2022-12-11 02:40:15 +00:00
module . exports = class {
constructor ( wsEvent ) {
this . wsEvent = wsEvent ;
2022-12-09 13:14:31 +00:00
}
2022-12-11 02:40:15 +00:00
async run ( client , interaction ) {
if ( ! interaction . isChatInputCommand ( ) ) return ;
2022-12-09 13:14:31 +00:00
// Request all the data we need from the database
const data = { } ;
2022-12-11 02:40:15 +00:00
data . user = await client . db . getUser ( interaction . user . id ) ;
data . guild = await client . db . getGuild ( interaction . guild . id ) ;
data . member = await client . db . getMember ( interaction . guild . id , interaction . user . id ) ;
2022-12-09 13:14:31 +00:00
2022-12-11 02:40:15 +00:00
const command = client . commands . get ( interaction . commandName ) ;
2022-12-09 13:14:31 +00:00
// Return if the command is disabled globally
2022-12-11 02:40:15 +00:00
if ( command . enabled === false ) interaction . reply (
client . config . emojis . permError + ' This command has been disabled by my developers.'
2022-12-09 13:14:31 +00:00
) ;
2022-12-11 02:40:15 +00:00
2022-12-09 13:14:31 +00:00
// Return if the command is restricted to developers (and the user is not a developer)
2022-12-11 02:40:15 +00:00
if ( command . devOnly === true && client . config . devIds . includes ( interaction . user . id ) !== true ) {
return interaction . reply (
` ${ client . config . emojis . permError } ${ interaction . user . username } is not in the sudoers file. This incident will be reported. `
2022-12-09 13:14:31 +00:00
) ;
2022-12-11 02:40:15 +00:00
}
2022-12-09 13:14:31 +00:00
// Cooldown
2022-12-11 02:40:15 +00:00
if ( client . cooldowns . get ( command . name ) . has ( interaction . user . id ) ) {
const timestamp = client . cooldowns . get ( command . name ) . get ( interaction . user . id ) ;
2022-12-09 13:14:31 +00:00
const currentTime = Date . now ( ) ;
const cooldown = command . cooldown / 1000 ;
const timePassed = Math . floor ( ( currentTime - timestamp ) / 1000 ) ;
2022-12-11 02:40:15 +00:00
return interaction . reply (
2022-12-11 06:22:57 +00:00
` ${ client . config . emojis . wait } <@ ${ interaction . user . id } >, you need to wait ${ cooldown - timePassed } seconds before using this command again. `
2022-12-09 13:14:31 +00:00
) ;
} else {
2022-12-11 02:40:15 +00:00
client . cooldowns . get ( command . name ) . set ( interaction . user . id , new Date ( ) ) ;
2022-12-09 13:14:31 +00:00
setTimeout ( ( ) => {
2022-12-11 02:40:15 +00:00
client . cooldowns . get ( command . name ) . delete ( interaction . user . id ) ;
} , client . commands . get ( command . name ) . cooldown ) ;
}
2022-12-09 13:14:31 +00:00
2022-12-11 06:22:57 +00:00
// Try to execute the command, if it fails return error stack and inform the user
2022-12-09 13:14:31 +00:00
try {
2022-12-11 02:40:15 +00:00
command . run ( client , interaction , data ) ;
client . logger . command ( ` Ran ${ command . name } ` ) ;
2022-12-09 13:14:31 +00:00
} catch ( error ) {
2022-12-11 02:40:15 +00:00
client . logger . error ( 'COMMAND_EXECUTION_ERROR' , ` ${ command . name } : ${ error . stack } ` ) ;
interaction . reply ( ` ${ client . config . emojis . botError } An error occurred when I was trying to run this command. I've sent through the details of the error to my developers. ` ) ;
2022-12-09 13:14:31 +00:00
}
}
2022-12-11 02:40:15 +00:00
} ;