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.2 KiB
JavaScript
Raw Normal View History

2017-10-04 20:55:50 +03:30
'use strict';
// DB
const { getCommand, removeCommand } = require('../../stores/command');
2020-05-13 22:38:59 +02:00
const { isMaster } = require('../../utils/config');
2017-10-04 20:55:50 +03:30
2020-03-10 22:10:48 +01:00
/** @param { import('../../typings/context').ExtendedContext } ctx */
2021-05-07 22:46:11 +02:00
const removeCommandHandler = async (ctx) => {
const { text } = ctx.message;
if (ctx.chat.type !== 'private') return null;
2021-05-07 22:46:11 +02:00
if (ctx.from.status !== 'admin') {
return ctx.replyWithHTML(
2023-03-08 14:08:57 +01:00
' <b>Sorry, only admins access this command.</b>'
);
2017-10-04 20:55:50 +03:30
}
2023-03-08 14:08:57 +01:00
const [, commandName] = text.split(' ');
2017-10-04 20:55:50 +03:30
if (!commandName) {
2021-05-07 22:46:11 +02:00
return ctx.replyWithHTML(
'<b>Send a valid command.</b>\n\nExample:\n' +
2023-03-08 14:08:57 +01:00
'<code>/removecommand rules</code>'
);
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) {
2023-03-08 14:08:57 +01:00
return ctx.replyWithHTML(" <b>Command couldn't be found.</b>");
2017-10-04 20:55:50 +03:30
}
const role = command.role.toLowerCase();
2021-05-07 22:46:11 +02:00
if (role === 'master' && !isMaster(ctx.from)) {
return ctx.replyWithHTML(
2023-03-08 14:08:57 +01:00
' <b>Sorry, only master can remove this command.</b>'
);
2017-10-04 20:55:50 +03:30
}
2017-11-20 13:29:33 +03:30
await removeCommand({ name: commandName.toLowerCase() });
2021-05-07 22:46:11 +02:00
return ctx.replyWithHTML(
2017-10-10 21:42:39 +03:30
`✅ <code>!${commandName}</code> ` +
2023-03-08 14:08:57 +01:00
'<b>has been removed successfully.</b>'
);
2017-10-04 20:55:50 +03:30
};
module.exports = removeCommandHandler;