2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-26 11:57:09 +00:00
the-guard-bot/handlers/commands/removeCommand.js
2017-11-20 13:29:33 +03:30

54 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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;