2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 18:08:51 +00:00
the-guard-bot/handlers/commands/removeCommand.js
Thomas Rory Gummerson 37974a3d92 Updates
2023-03-08 14:08:57 +01:00

46 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');
const { isMaster } = require('../../utils/config');
/** @param { import('../../typings/context').ExtendedContext } ctx */
const removeCommandHandler = async (ctx) => {
const { text } = ctx.message;
if (ctx.chat.type !== 'private') return null;
if (ctx.from.status !== 'admin') {
return ctx.replyWithHTML(
' <b>Sorry, only admins access this command.</b>'
);
}
const [, commandName] = text.split(' ');
if (!commandName) {
return ctx.replyWithHTML(
'<b>Send a valid command.</b>\n\nExample:\n' +
'<code>/removecommand rules</code>'
);
}
const command = await getCommand({ name: commandName.toLowerCase() });
if (!command) {
return ctx.replyWithHTML(" <b>Command couldn't be found.</b>");
}
const role = command.role.toLowerCase();
if (role === 'master' && !isMaster(ctx.from)) {
return ctx.replyWithHTML(
' <b>Sorry, only master can remove this command.</b>'
);
}
await removeCommand({ name: commandName.toLowerCase() });
return ctx.replyWithHTML(
`✅ <code>!${commandName}</code> ` +
'<b>has been removed successfully.</b>'
);
};
module.exports = removeCommandHandler;