|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PermissionManager { |
|
|
constructor() { |
|
|
|
|
|
this.owners = [ |
|
|
{ |
|
|
numero: '244937035662', |
|
|
nome: 'Isaac Quarenta', |
|
|
descricao: 'Desenvolvedor Principal', |
|
|
nivel: 'ROOT' |
|
|
}, |
|
|
{ |
|
|
numero: '244978787009', |
|
|
nome: 'Isaac Quarenta', |
|
|
descricao: 'Segundo Proprietário', |
|
|
nivel: 'ROOT' |
|
|
} |
|
|
]; |
|
|
|
|
|
|
|
|
this.commandPermissions = { |
|
|
|
|
|
'help': { nivel: 'public', rateLimitMultiplier: 0.5 }, |
|
|
'menu': { nivel: 'public', rateLimitMultiplier: 0.5 }, |
|
|
'ping': { nivel: 'public', rateLimitMultiplier: 0.5 }, |
|
|
'info': { nivel: 'public', rateLimitMultiplier: 0.5 }, |
|
|
'donate': { nivel: 'public', rateLimitMultiplier: 0.5 }, |
|
|
'perfil': { nivel: 'public', rateLimitMultiplier: 1 }, |
|
|
'profile': { nivel: 'public', rateLimitMultiplier: 1 }, |
|
|
'registrar': { nivel: 'public', rateLimitMultiplier: 1 }, |
|
|
'level': { nivel: 'public', rateLimitMultiplier: 1 }, |
|
|
'sticker': { nivel: 'public', rateLimitMultiplier: 2 }, |
|
|
'gif': { nivel: 'public', rateLimitMultiplier: 2.5 }, |
|
|
'toimg': { nivel: 'public', rateLimitMultiplier: 1.5 }, |
|
|
'play': { nivel: 'public', rateLimitMultiplier: 2 }, |
|
|
'tts': { nivel: 'public', rateLimitMultiplier: 2 }, |
|
|
|
|
|
|
|
|
'add': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'remove': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'kick': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'ban': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'promote': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'demote': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'mute': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'desmute': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'antilink': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'warn': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
'clearwarn': { nivel: 'owner', rateLimitMultiplier: 1, grupo: true }, |
|
|
}; |
|
|
|
|
|
|
|
|
this.actionLimits = { |
|
|
|
|
|
'premium_feature': { |
|
|
maxUsos: 1, |
|
|
janelaDias: 90, |
|
|
message: 'Feature Premium - Acesso 1x a cada 90 dias' |
|
|
}, |
|
|
|
|
|
'normal_command': { |
|
|
janelaSec: 8, |
|
|
maxPorJanela: 6, |
|
|
message: 'Aguarde antes de usar outro comando' |
|
|
}, |
|
|
|
|
|
'admin_command': { |
|
|
janelaSec: 3, |
|
|
maxPorJanela: 10, |
|
|
message: 'Muitos comandos de admin muito rapido' |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
this.securityConfig = { |
|
|
|
|
|
maxMutesBeforeRemove: 5, |
|
|
|
|
|
|
|
|
muteProgressionMultiplier: 2, |
|
|
|
|
|
|
|
|
baseMuteDuration: 5, |
|
|
|
|
|
|
|
|
linkPatterns: [ |
|
|
'https://', |
|
|
'http://', |
|
|
'www.', |
|
|
'bit.ly/', |
|
|
't.me/', |
|
|
'wa.me/', |
|
|
'chat.whatsapp.com/', |
|
|
'whatsapp.com/' |
|
|
], |
|
|
|
|
|
|
|
|
abuseDetection: { |
|
|
enabled: true, |
|
|
deleteMessage: true, |
|
|
removeUser: true, |
|
|
logAction: true |
|
|
} |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isOwner(numero, nome) { |
|
|
try { |
|
|
const numeroLimpo = String(numero).trim(); |
|
|
const nomeLimpo = String(nome).trim(); |
|
|
|
|
|
return this.owners.some(owner => |
|
|
numeroLimpo === owner.numero && nomeLimpo === owner.nome |
|
|
); |
|
|
} catch (e) { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getOwnerInfo(numero) { |
|
|
const numeroLimpo = String(numero).trim(); |
|
|
return this.owners.find(owner => numeroLimpo === owner.numero); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hasPermissionForCommand(comando, numero, nome, ehGrupo = false) { |
|
|
const permConfig = this.commandPermissions[comando]; |
|
|
|
|
|
if (!permConfig) { |
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
|
if (permConfig.nivel === 'public') { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
if (permConfig.nivel === 'owner') { |
|
|
const isOwner = this.isOwner(numero, nome); |
|
|
if (!isOwner) return false; |
|
|
|
|
|
|
|
|
if (permConfig.grupo && !ehGrupo) { |
|
|
return false; |
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
|
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getCommandConfig(comando) { |
|
|
return this.commandPermissions[comando] || null; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getRateLimitMultiplier(comando) { |
|
|
const config = this.commandPermissions[comando]; |
|
|
return config?.rateLimitMultiplier || 1; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
containsLink(texto) { |
|
|
if (!texto) return false; |
|
|
const textLower = String(texto).toLowerCase(); |
|
|
return this.securityConfig.linkPatterns.some(pattern => |
|
|
textLower.includes(pattern.toLowerCase()) |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getActionLimitConfig(tipoAcao) { |
|
|
return this.actionLimits[tipoAcao]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getNextMuteDuration(muteCount) { |
|
|
const baseDuration = this.securityConfig.baseMuteDuration; |
|
|
const multiplier = this.securityConfig.muteProgressionMultiplier; |
|
|
|
|
|
|
|
|
return Math.min( |
|
|
baseDuration * Math.pow(multiplier, muteCount), |
|
|
1440 |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shouldRemoveAfterMute(muteCount) { |
|
|
return muteCount >= this.securityConfig.maxMutesBeforeRemove; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listOwners() { |
|
|
return this.owners.map(owner => ({ |
|
|
numero: owner.numero, |
|
|
nome: owner.nome, |
|
|
descricao: owner.descricao |
|
|
})); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validateStructure() { |
|
|
const errors = []; |
|
|
|
|
|
|
|
|
if (!Array.isArray(this.owners) || this.owners.length === 0) { |
|
|
errors.push('Nenhum proprietário definido'); |
|
|
} |
|
|
|
|
|
this.owners.forEach((owner, idx) => { |
|
|
if (!owner.numero || !owner.nome) { |
|
|
errors.push(`Proprietário ${idx} incompleto`); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
if (!this.commandPermissions || Object.keys(this.commandPermissions).length === 0) { |
|
|
errors.push('Nenhuma permissão de comando definida'); |
|
|
} |
|
|
|
|
|
return { |
|
|
isValid: errors.length === 0, |
|
|
errors |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
module.exports = PermissionManager; |
|
|
|