'use strict'; // DB const { getCommand, removeCommand } = require('../../stores/command'); // Bot const { replyOptions } = require('../../bot/options'); const removeCommandHandler = async ({ chat, message, reply, state }) => { const { isAdmin, isMaster } = state; const { text } = message; if (chat.type !== 'private') return null; if (!isAdmin) { return reply( 'ℹ️ Sorry, only admins access this command.', replyOptions ); } const [ , commandName ] = text.split(' '); if (!commandName) { return reply( 'Enter a command name to remove.\n\n' + 'For example:\n/removecommand rules', replyOptions ); } const command = await getCommand({ name: commandName.toLowerCase() }); if (!command) { return reply( 'ℹ️ Command couldn\'t be found.', replyOptions ); } const role = command.role.toLowerCase(); if (role === 'master' && !isMaster) { return reply( 'ℹ️ Sorry, only master can remove this command.', replyOptions ); } await removeCommand({ name: commandName.toLowerCase() }); return reply( `✅ !${commandName} ` + 'has been removed successfully.', replyOptions ); }; module.exports = removeCommandHandler;