import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import { execSync } from "child_process" ; export class ReloadCommand extends Command { description = "Reloads a command." ; args = "<command:string>" ; allowdisable = false ; allowdms = true ; owner = true ; async run ( msg , _pargs , args ) { if ( process . env . NODE_ENV === "development" ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "owner.RELOAD_NODEMON" ) , "error" ) ; } execSync ( "tsc" ) ; if ( args . join ( " " ) . toLowerCase ( ) === "*" || args . join ( " " ) . toLowerCase ( ) === "all" ) args = this . bot . commands . map ( ( c ) => c . name ) ; const success = [ ] ; const fail = [ ] ; args . forEach ( ( arg ) => { let command ; const cmd = this . bot . commands . find ( ( c ) => c . name === arg . toLowerCase ( ) || c . aliases . includes ( arg . toLowerCase ( ) ) ) ; if ( ! cmd ) return fail . push ( { id : arg . toLowerCase ( ) , error : msg . string ( "owner.COMMAND_NOTFOUND" ) } ) ; const oldmodule = require ( `../${ cmd . category }/${ cmd . name }` ) ; delete require . cache [ require . resolve ( `../${ cmd . category }/${ cmd . name }` ) ] ; try { command = require ( `../${ cmd . category }/${ cmd . name }` ) ; } catch ( err ) { fail . push ( { id : cmd . name , error : err } ) ; this . bot . commands . push ( new oldmodule [ Object . keys ( oldmodule ) [ 0 ] ] ( this . bot , cmd . name , cmd . category ) ) ; } if ( command ) { const index = this . bot . commands . indexOf ( cmd ) ; if ( index !== - 1 ) this . bot . commands . splice ( index , 1 ) ; this . bot . commands . push ( new command [ Object . keys ( command ) [ 0 ] ] ( this . bot , cmd . name , cmd . category ) ) ; success . push ( cmd . name ) ; } } ) ; msg . createEmbed ( `🔄 ${ ( msg . string ( "owner.RELOAD_RELOADED" ) , { commands : success . length } ) }` , fail . length > 0 ? fail . map ( ( failedcmd ) => `**${ failedcmd . id }**: \`\`\`js\n${ failedcmd . error }\`\`\`` ) . join ( "\n" ) : null , fail . length > 0 ? "error" : "success" ) ; } }