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

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-10-04 20:55:50 +03:30
'use strict';
// Utils
const { loadJSON } = require('../../utils/json');
// Config
const { masterID } = loadJSON('config.json');
// DB
const { isAdmin } = require('../../stores/user');
const { getCommand, removeCommand } = require('../../stores/command');
// Bot
const { replyOptions } = require('../../bot/options');
const removeCommandHandler = async ({ chat, message, reply }) => {
const user = message.from;
const { text } = message;
if (chat.type !== 'private') {
return null;
}
if (!await isAdmin(user)) {
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' && user.id !== masterID) {
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;