-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export async function before(m) { | ||
if (!m.text || !global.prefix.test(m.text)) { | ||
return; | ||
} | ||
|
||
const usedPrefix = global.prefix.exec(m.text)[0]; | ||
const command = m.text.slice(usedPrefix.length).trim().split(' ')[0].toLowerCase(); | ||
|
||
const validCommand = (command, plugins) => { | ||
for (let plugin of Object.values(plugins)) { | ||
if (plugin.command && (Array.isArray(plugin.command) ? plugin.command : [plugin.command]).includes(command)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
if (validCommand(command, global.plugins)) { | ||
let chat = global.db.data.chats[m.chat]; | ||
let user = global.db.data.users[m.sender]; | ||
if (chat.isBanned) return; | ||
if (!user.commands) { | ||
user.commands = 0; | ||
} | ||
user.commands += 1; | ||
await conn.sendPresenceUpdate('composing', m.chat); | ||
} else { | ||
const comando = m.text.trim().split(' ')[0]; | ||
await m.reply(`El comando "${comando}" no existe.\nUsa */menu* para ver la lista de los comandos.`); | ||
} | ||
} |