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

55 lines
1.3 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');
2020-03-10 22:10:48 +01:00
/** @param { import('../../typings/context').ExtendedContext } ctx */
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) {
return reply(
' <b>Sorry, only admins access this command.</b>',
replyOptions
);
2017-10-04 20:55:50 +03:30
}
const [ , commandName ] = text.split(' ');
if (!commandName) {
return reply(
'<b>Send a valid command.</b>\n\nExample:\n' +
'<code>/removecommand rules</code>',
replyOptions
);
2017-10-04 20:55:50 +03:30
}
2017-11-20 13:29:33 +03:30
const command = await getCommand({ name: commandName.toLowerCase() });
2017-10-04 20:55:50 +03:30
if (!command) {
return reply(
' <b>Command couldn\'t be found.</b>',
replyOptions
);
2017-10-04 20:55:50 +03:30
}
const role = command.role.toLowerCase();
if (role === 'master' && !isMaster) {
return reply(
' <b>Sorry, only master can remove this command.</b>',
replyOptions
);
2017-10-04 20:55:50 +03:30
}
2017-11-20 13:29:33 +03:30
await removeCommand({ name: commandName.toLowerCase() });
2017-10-04 20:55:50 +03:30
return reply(
2017-10-10 21:42:39 +03:30
`✅ <code>!${commandName}</code> ` +
2017-10-04 20:55:50 +03:30
'<b>has been removed successfully.</b>',
replyOptions
);
2017-10-04 20:55:50 +03:30
};
module.exports = removeCommandHandler;