File size: 21,286 Bytes
7226ab4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
const ConfigManager = require('./ConfigManager');
const fs = require('fs');
const path = require('path');
/**
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* COMMAND HANDLER - AKIRA BOT V21
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* โ
Sistema completo de comandos com permissรตes por tier
* โ
Rate limiting inteligente por usuรกrio
* โ
Menus profissionais e formatados
* โ
Funcionalidades enterprise-grade
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*/
// Sistema de rate limiting por usuรกrio (premium features)
const premiumFeatureUsage = new Map(); // { userId: { lastUse: timestamp, count: number, resetDate: Date } }
class CommandHandler {
constructor(botCore) {
this.bot = botCore;
this.config = ConfigManager.getInstance();
}
/**
* Verifica se usuรกrio tem acesso a feature premium (1x a cada 3 meses)
*/
canUsePremiumFeature(userId) {
const now = new Date();
const usage = premiumFeatureUsage.get(userId) || { lastUse: 0, count: 0, resetDate: now };
// Reset a cada 3 meses (90 dias)
const threeMonthsAgo = new Date(now.getTime() - (90 * 24 * 60 * 60 * 1000));
if (usage.resetDate < threeMonthsAgo) {
usage.count = 0;
usage.resetDate = now;
}
const canUse = usage.count === 0;
if (canUse) {
usage.count = 1;
usage.lastUse = now.getTime();
}
premiumFeatureUsage.set(userId, usage);
return canUse;
}
/**
* Formata linha divisรณria para menus
*/
getDivider() {
return 'โ'.repeat(54);
}
/**
* Formata cabeรงalho de menu
*/
getMenuHeader(emoji, title) {
return `โ${'โ'.repeat(52)}โ
โ ${emoji} ${title.padEnd(48)} โ
โ${'โ'.repeat(52)}โ`;
}
/**
* Formata seรงรฃo de menu
*/
getMenuSection(emoji, section) {
return `\n${this.getDivider()}
${emoji} ${section}
${this.getDivider()}`;
}
async handle(m, meta) {
// meta: { nome, numeroReal, texto, replyInfo, ehGrupo }
try {
const { nome, numeroReal, texto, replyInfo, ehGrupo } = meta;
const mp = this.bot.messageProcessor;
const parsed = mp.parseCommand(texto);
if (!parsed) return false;
const senderId = numeroReal;
const sock = this.bot.sock;
// common helpers
const isOwner = () => {
try { return this.config.isDono(senderId, nome); } catch { return false; }
};
const cmd = parsed.comando;
const args = parsed.args;
const full = parsed.textoCompleto;
// Rate-limit via messageProcessor
if (!mp.checkRateLimit(senderId)) {
await sock.sendMessage(m.key.remoteJid, { text: 'โฐ Vocรช estรก usando comandos muito rรกpido. Aguarde.' }, { quoted: m });
return true;
}
// Permission check wrapper for owner-only actions
const ownerOnly = async (fn) => {
if (!isOwner()) {
await sock.sendMessage(m.key.remoteJid, { text: '๐ซ Comando restrito ao dono.' }, { quoted: m });
return true;
}
return await fn();
};
switch (cmd) {
case 'ping':
await sock.sendMessage(m.key.remoteJid, { text: `๐ Pong! Uptime: ${Math.floor(process.uptime())}s` }, { quoted: m });
return true;
case 'perfil':
case 'profile':
case 'info':
try {
const uid = m.key.participant || m.key.remoteJid;
const nomeReg = this.bot.apiClient.getRegisterName ? this.bot.apiClient.getRegisterName(uid) : 'Nรฃo registrado';
const level = this.bot.levelSystem.getGroupRecord(m.key.remoteJid, uid, true).level || 0;
const xp = this.bot.levelSystem.getGroupRecord(m.key.remoteJid, uid, true).xp || 0;
const txt = `๐ค *Perfil:* ${nomeReg}\n๐ฎ Nรญvel: ${level}\nโญ XP: ${xp}`;
await sock.sendMessage(m.key.remoteJid, { text: txt }, { quoted: m });
} catch (e) { }
return true;
case 'registrar':
case 'register':
case 'reg':
try {
// local simple registry using database/datauser/registered.json
const dbFolder = path.join(this.config.DATABASE_FOLDER, 'datauser');
if (!fs.existsSync(dbFolder)) fs.mkdirSync(dbFolder, { recursive: true });
const regPath = path.join(dbFolder, 'registered.json');
if (!fs.existsSync(regPath)) fs.writeFileSync(regPath, JSON.stringify([], null, 2));
if (!full.includes('|')) {
await sock.sendMessage(m.key.remoteJid, { text: 'Uso: #registrar Nome|Idade' }, { quoted: m });
return true;
}
const [nomeUser, idadeStr] = full.split('|').map(s => s.trim());
const idade = parseInt(idadeStr,10);
if (!nomeUser || isNaN(idade)) { await sock.sendMessage(m.key.remoteJid, { text: 'Formato invรกlido.' }, { quoted: m }); return true; }
const registered = JSON.parse(fs.readFileSync(regPath, 'utf8') || '[]');
const senderJid = m.key.participant || m.key.remoteJid;
if (registered.find(u=>u.id===senderJid)) { await sock.sendMessage(m.key.remoteJid, { text: 'โ
Vocรช jรก estรก registrado!' }, { quoted: m }); return true; }
const serial = (Date.now().toString(36) + Math.random().toString(36).slice(2,10)).toUpperCase();
const time = new Date().toISOString();
registered.push({ id: senderJid, name: nomeUser, age: idade, time, serial, registeredAt: Date.now() });
fs.writeFileSync(regPath, JSON.stringify(registered, null, 2));
// ensure leveling record
this.bot.levelSystem.getGroupRecord(m.key.remoteJid, senderJid, true);
await sock.sendMessage(m.key.remoteJid, { text: 'โ
Registrado com sucesso!' }, { quoted: m });
} catch (e) { this.bot.logger && this.bot.logger.error('registrar error', e); }
return true;
case 'level':
case 'nivel':
case 'rank':
try {
const gid = m.key.remoteJid;
if (!String(gid).endsWith('@g.us')) { await sock.sendMessage(gid, { text: '๐ต Level funciona apenas em grupos.' }, { quoted: m }); return true; }
const sub = (args[0]||'').toLowerCase();
if (['on','off','status'].includes(sub)) {
return await ownerOnly(async () => {
const settingsPath = this.config.JSON_PATHS?.leveling || null;
if (settingsPath) {
const toggles = this.bot.apiClient.loadJSON ? this.bot.apiClient.loadJSON(settingsPath) : {};
if (sub === 'on') { toggles[gid]=true; this.bot.apiClient.saveJSON && this.bot.apiClient.saveJSON(settingsPath, toggles); await sock.sendMessage(gid,{text:'โ
Level ativado'},{quoted:m}); }
else if (sub === 'off') { delete toggles[gid]; this.bot.apiClient.saveJSON && this.bot.apiClient.saveJSON(settingsPath, toggles); await sock.sendMessage(gid,{text:'๐ซ Level desativado'},{quoted:m}); }
else { await sock.sendMessage(gid,{text:`โน๏ธ Status: ${toggles[gid] ? 'Ativo' : 'Inativo'}`},{quoted:m}); }
} else {
await sock.sendMessage(gid,{text:'โ ๏ธ Configuraรงรฃo de leveling nรฃo encontrada'},{quoted:m});
}
return true;
});
}
// Mostrar level do usuรกrio
const uid = m.key.participant || m.key.remoteJid;
const rec = this.bot.levelSystem.getGroupRecord(gid, uid, true);
const req = this.bot.levelSystem.requiredXp(rec.level);
const pct = req === Infinity ? 100 : Math.min(100, Math.floor((rec.xp/req)*100));
const msg = `๐ LEVEL\n๐ค @${uid.split('@')[0]}\n๐ Nรญvel: ${rec.level}\nโญ XP: ${rec.xp}/${req}\nProgresso: ${pct}%`;
await sock.sendMessage(gid, { text: msg, contextInfo: { mentionedJid: [uid] } }, { quoted: m });
} catch (e) { }
return true;
case 'antilink':
try {
return await ownerOnly(async () => {
const sub2 = (args[0]||'').toLowerCase();
const gid = m.key.remoteJid;
if (sub2 === 'on') { this.bot.moderationSystem.toggleAntiLink(gid, true); await sock.sendMessage(gid,{text:'๐ ANTI-LINK ATIVADO'},{quoted:m}); }
else if (sub2 === 'off') { this.bot.moderationSystem.toggleAntiLink(gid, false); await sock.sendMessage(gid,{text:'๐ ANTI-LINK DESATIVADO'},{quoted:m}); }
else { await sock.sendMessage(gid,{text:`Status: ${this.bot.moderationSystem.isAntiLinkActive(gid) ? 'Ativo' : 'Inativo'}`},{quoted:m}); }
return true;
});
} catch (e) {}
return true;
case 'mute':
try {
return await ownerOnly(async () => {
const target = (m.message?.extendedTextMessage?.contextInfo?.mentionedJid||[])[0] || replyInfo?.participantJidCitado;
if (!target) { await sock.sendMessage(m.key.remoteJid,{text:'Marque ou responda o usuรกrio'},{quoted:m}); return true; }
const res = this.bot.moderationSystem.muteUser(m.key.remoteJid, target, 5);
await sock.sendMessage(m.key.remoteJid,{text:`๐ Mutado por ${res.minutes} minutos`},{quoted:m});
return true;
});
} catch (e) {}
return true;
case 'desmute':
try { return await ownerOnly(async ()=>{ const target = (m.message?.extendedTextMessage?.contextInfo?.mentionedJid||[])[0] || replyInfo?.participantJidCitado; if (!target) { await sock.sendMessage(m.key.remoteJid,{text:'Marque ou responda o usuรกrio'},{quoted:m}); return true;} this.bot.moderationSystem.unmuteUser(m.key.remoteJid,target); await sock.sendMessage(m.key.remoteJid,{text:'๐ Usuรกrio desmutado'},{quoted:m}); return true; }); } catch(e){}
return true;
case 'sticker':
case 's':
case 'fig':
try {
// delegate to mediaProcessor
const quoted = m.message?.extendedTextMessage?.contextInfo?.quotedMessage;
const imageMsg = m.message?.imageMessage || quoted?.imageMessage;
const stickerMsg = quoted?.stickerMessage;
if (stickerMsg) {
const stickerBuf = await this.bot.mediaProcessor.downloadMedia(stickerMsg, 'sticker');
if (stickerBuf) {
await sock.sendMessage(m.key.remoteJid, { sticker: stickerBuf }, { quoted: m });
} else {
await sock.sendMessage(m.key.remoteJid, { text: 'โ Erro ao baixar sticker.' }, { quoted: m });
}
return true;
}
if (imageMsg) {
const buf = await this.bot.mediaProcessor.downloadMedia(imageMsg, 'image');
const res = await this.bot.mediaProcessor.createStickerFromImage(buf, { packName: this.config.STICKER_PACK || 'Akira Pack', author: nome });
if (res && res.sucesso && res.buffer) {
await sock.sendMessage(m.key.remoteJid, { sticker: res.buffer }, { quoted: m });
} else {
await sock.sendMessage(m.key.remoteJid, { text: 'โ Erro ao criar sticker' }, { quoted: m });
}
return true;
}
await sock.sendMessage(m.key.remoteJid, { text: 'Envie/Responda uma imagem ou sticker' }, { quoted: m });
} catch (e) { }
return true;
case 'play':
try {
if (!full) { await sock.sendMessage(m.key.remoteJid, { text: 'Uso: #play <link ou termo>' }, { quoted: m }); return true; }
await sock.sendMessage(m.key.remoteJid, { text: 'โณ Processando mรบsica...' }, { quoted: m });
const res = await this.bot.mediaProcessor.downloadYouTubeAudio(full);
if (res.error) { await sock.sendMessage(m.key.remoteJid, { text: `โ ${res.error}` }, { quoted: m }); return true; }
await sock.sendMessage(m.key.remoteJid, { audio: res.buffer, mimetype: 'audio/mpeg', ptt: false, fileName: `${res.title || 'music'}.mp3` }, { quoted: m });
} catch (e) {}
return true;
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// COMANDO: MENU / HELP / COMANDOS
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
case 'help':
case 'menu':
case 'comandos':
case 'ajuda':
try {
const menuText = `โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ค AKIRA BOT V21 - MENU COMPLETO ๐ค โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฑ *PREFIXO:* \`${this.config.PREFIXO}\`
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐จ MรDIA & CRIATIVIDADE (Todos)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\`#sticker\` - Criar sticker de imagem
\`#s\` ou \`#fig\` - Aliases para #sticker
\`#play <nome/link>\` - Baixar mรบsica do YouTube
\`#ping\` - Testar latรชncia do bot
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ค รUDIO INTELIGENTE (Novo)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โข Respondo รกudio automaticamente em PV
โข Em grupos: mencione "Akira" ou responda ao รกudio
โข Transcriรงรฃo interna (NUNCA mostra no chat)
โข Resposto em รกudio automรกtico
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ MODERAรรO (Apenas Isaac Quarenta)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\`#antilink on\` - Ativar anti-link
\`#antilink off\` - Desativar anti-link
\`#antilink status\` - Ver status
\`#mute @usuรกrio\` - Mutar por 5 min (ou reply)
\`#desmute @usuรกrio\` - Desmutar (ou reply)
\`#level on\` - Ativar sistema de nรญveis
\`#level off\` - Desativar sistema de nรญveis
\`#level status\` - Ver status do level
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฎ UTILIDADES (Todos)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\`#perfil\` ou \`#info\` - Ver seu perfil
\`#registrar Nome|Idade\` - Registrar no bot
\`#level\` - Ver seu nรญvel e XP
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฌ CONVERSA NORMAL
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Mencione "Akira" em grupos
โ
Ou responda minhas mensagens para conversar
โ
IA sempre disponรญvel em PV
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๏ธ INFORMAรรES IMPORTANTES
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Comandos de grupo: Apenas Isaac Quarenta
๐ Sistema de XP automรกtico ao enviar mensagens
๐ Suba de nรญvel conversando (automaticamente)
๐ก๏ธ Anti-spam e proteรงรฃo contra abuso
๐ค STT: Deepgram (200h/mรชs gratuito)
๐ TTS: Google Text-to-Speech
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฐ *Quer apoiar o projeto?*
Digite: \`#donate\` ou \`#doar\`
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*Desenvolvido com โค๏ธ por Isaac Quarenta*`;
await sock.sendMessage(m.key.remoteJid, { text: menuText }, { quoted: m });
} catch (e) {
this.bot.logger?.error('Erro no comando menu:', e);
}
return true;
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// COMANDO: DONATE / APOIO
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
case 'donate':
case 'doar':
case 'apoia':
case 'doacao':
try {
const donateText = `โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โค๏ธ APOIE O PROJETO AKIRA BOT โค๏ธ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ *Vocรช gosta do Akira?*
Seu apoio nos ajuda a manter:
โ
Bot online 24/7
โ
Novas funcionalidades
โ
Sem publicidades
โ
Gratuito para todos
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฐ FORMAS DE APOIAR
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ *PIX (IMEDIATO):*
E-mail: akira.bot.dev@gmail.com
Chave: akira.bot.dev@gmail.com
โ *COMPRE UM CAFร (Ko-fi):*
https://ko-fi.com/isaacquarenta
๐ณ *PAYPAL:*
https://paypal.me/isaacquarenta
๐ *QUALQUER VALOR AJUDA!*
Desde R$ 5 atรฉ quanto vocรช quiser contribuir
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ AGRADECIMENTOS ESPECIAIS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Todos que contribuem receberรฃo:
โจ Meu sincero agradecimento
โจ Suporte prioritรกrio
โจ Novas features primeiro
โจ Reconhecimento especial
โจ Status VIP no bot
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ IMPACTO DA SUA DOAรรO
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
R$ 5 = Mantรฉm o bot 1 dia online
R$ 20 = Semana completa
R$ 50 = Mรชs inteiro
R$ 100+ = Mรชs + desenvolvimento de features
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*Desenvolvido com โค๏ธ por Isaac Quarenta*
_Obrigado por apoiar um projeto feito com paixรฃo!_ ๐`;
await sock.sendMessage(m.key.remoteJid, { text: donateText }, { quoted: m });
} catch (e) {
this.bot.logger?.error('Erro no comando donate:', e);
}
return true;
default:
return false;
}
} catch (err) {
try { await this.bot.sock.sendMessage(m.key.remoteJid, { text: 'โ Erro no comando.' }, { quoted: m }); } catch {}
return true;
}
}
}
module.exports = CommandHandler;
|