mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-26 11:57:09 +00:00
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'use strict';
|
||
|
||
// DB
|
||
const { getCommand, removeCommand } = require('../../stores/command');
|
||
|
||
// Bot
|
||
const { replyOptions } = require('../../bot/options');
|
||
|
||
const removeCommandHandler = async ({ chat, message, reply, state }) => {
|
||
const { isAdmin, isMaster } = state;
|
||
const { text } = message;
|
||
if (chat.type !== 'private') return null;
|
||
|
||
if (!isAdmin) {
|
||
return reply(
|
||
'ℹ️ <b>Sorry, only admins access this command.</b>',
|
||
replyOptions
|
||
);
|
||
}
|
||
const [ , commandName ] = text.split(' ');
|
||
if (!commandName) {
|
||
return reply(
|
||
'Enter a command name to remove.\n\n' +
|
||
'For example:\n/removecommand <b>rules</b>',
|
||
replyOptions
|
||
);
|
||
}
|
||
|
||
const command = await getCommand({ name: commandName.toLowerCase() });
|
||
if (!command) {
|
||
return reply(
|
||
'ℹ️ <b>Command couldn\'t be found.</b>',
|
||
replyOptions
|
||
);
|
||
}
|
||
|
||
const role = command.role.toLowerCase();
|
||
if (role === 'master' && !isMaster) {
|
||
return reply(
|
||
'ℹ️ <b>Sorry, only master can remove this command.</b>',
|
||
replyOptions
|
||
);
|
||
}
|
||
|
||
await removeCommand({ name: commandName.toLowerCase() });
|
||
return reply(
|
||
`✅ <code>!${commandName}</code> ` +
|
||
'<b>has been removed successfully.</b>',
|
||
replyOptions
|
||
);
|
||
};
|
||
|
||
module.exports = removeCommandHandler;
|