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 */
|
2020-05-13 22:38:59 +02:00
|
|
|
|
const removeCommandHandler = async ({ from, chat, message, replyWithHTML }) => {
|
2017-10-04 20:55:50 +03:30
|
|
|
|
const { text } = message;
|
2017-10-06 16:40:49 +03:30
|
|
|
|
if (chat.type !== 'private') return null;
|
|
|
|
|
|
2020-05-13 22:38:59 +02:00
|
|
|
|
if (from.status !== 'admin') {
|
|
|
|
|
return replyWithHTML(
|
2017-10-31 23:08:22 +01:00
|
|
|
|
'ℹ️ <b>Sorry, only admins access this command.</b>',
|
|
|
|
|
);
|
2017-10-04 20:55:50 +03:30
|
|
|
|
}
|
|
|
|
|
const [ , commandName ] = text.split(' ');
|
|
|
|
|
if (!commandName) {
|
2020-05-13 22:38:59 +02:00
|
|
|
|
return replyWithHTML(
|
2017-11-20 14:32:34 +03:30
|
|
|
|
'<b>Send a valid command.</b>\n\nExample:\n' +
|
|
|
|
|
'<code>/removecommand rules</code>',
|
2017-10-31 23:08:22 +01:00
|
|
|
|
);
|
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) {
|
2020-05-13 22:38:59 +02:00
|
|
|
|
return replyWithHTML(
|
2017-10-31 23:08:22 +01:00
|
|
|
|
'ℹ️ <b>Command couldn\'t be found.</b>',
|
|
|
|
|
);
|
2017-10-04 20:55:50 +03:30
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 21:54:59 +03:30
|
|
|
|
const role = command.role.toLowerCase();
|
2020-05-13 22:38:59 +02:00
|
|
|
|
if (role === 'master' && !isMaster(from)) {
|
|
|
|
|
return replyWithHTML(
|
2017-10-31 23:08:22 +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() });
|
2020-05-13 22:38:59 +02:00
|
|
|
|
return replyWithHTML(
|
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>',
|
2017-10-31 23:08:22 +01:00
|
|
|
|
);
|
2017-10-04 20:55:50 +03:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = removeCommandHandler;
|