2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-23 02:17:47 +00:00
the-guard-bot/handlers/commands/removeCommand.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-10-04 20:55:50 +03:30
'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;
2017-10-04 20:55:50 +03:30
const { text } = message;
if (chat.type !== 'private') {
return null;
}
if (!isAdmin) {
2017-10-04 20:55:50 +03:30
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 });
if (!command) {
return reply(' <b>Command couldn\'t be found.</b>',
replyOptions);
}
if (command.role === 'Master' && !isMaster) {
2017-10-04 20:55:50 +03:30
return reply(' <b>Sorry, only master can remove this command.</b>',
replyOptions);
}
await removeCommand({ name: commandName });
return reply(
`✅ <code>/${commandName}</code> ` +
'<b>has been removed successfully.</b>',
replyOptions);
};
module.exports = removeCommandHandler;