'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( 'ℹ️ Sorry, only admins access this command.', ); } const [ , commandName ] = text.split(' '); if (!commandName) { return ctx.replyWithHTML( 'Send a valid command.\n\nExample:\n' + '/removecommand rules', ); } const command = await getCommand({ name: commandName.toLowerCase() }); if (!command) { return ctx.replyWithHTML( 'ℹ️ Command couldn\'t be found.', ); } const role = command.role.toLowerCase(); if (role === 'master' && !isMaster(ctx.from)) { return ctx.replyWithHTML( 'ℹ️ Sorry, only master can remove this command.', ); } await removeCommand({ name: commandName.toLowerCase() }); return ctx.replyWithHTML( `✅ !${commandName} ` + 'has been removed successfully.', ); }; module.exports = removeCommandHandler;