2020-03-31 07:59:09 +00:00
module . exports = async ( client , message ) => {
if ( message . author . bot ) return
2020-04-06 05:54:45 +00:00
const data = { }
data . userData = await client . findOrCreateUser ( message . author )
if ( message . guild ) {
if ( ! message . channel . permissionsFor ( client . user ) . has ( 'SEND_MESSAGES' ) ) {
try {
return message . author . send ( ` I don't have permission to speak in **# ${ message . channel . name } **, Please ask a moderator to give me the send messages permission! ` )
} catch ( err ) { }
2020-04-04 06:59:22 +00:00
}
2020-04-06 05:54:45 +00:00
data . guildData = await client . findOrCreateGuild ( message . guild )
2020-04-04 06:59:22 +00:00
}
2020-04-06 05:54:45 +00:00
const prefixes = [ data . userData . prefix , data . guildData . prefix ]
2020-04-04 06:59:22 +00:00
2020-04-06 05:54:45 +00:00
let prefix
2020-03-31 07:59:09 +00:00
2020-04-06 05:54:45 +00:00
const prefixMention = new RegExp ( ` ^<@!? ${ client . user . id } > ` )
if ( message . content . match ( prefixMention ) ? message . content . match ( prefixMention ) [ 0 ] : '!' ) {
prefix = message . content . match ( prefixMention ) ? message . content . match ( prefixMention ) [ 0 ] : '!'
}
2020-03-31 07:59:09 +00:00
2020-04-06 05:54:45 +00:00
for ( const thisPrefix of prefixes ) {
if ( message . content . startsWith ( thisPrefix ) ) prefix = thisPrefix
}
2020-03-31 07:59:09 +00:00
if ( message . content . indexOf ( prefix ) !== 0 ) return
const args = message . content . slice ( prefix . length ) . trim ( ) . split ( / +/g )
const command = args . shift ( ) . toLowerCase ( )
if ( message . guild && ! message . member ) await message . guild . fetchMember ( message . author )
2020-04-06 05:54:45 +00:00
const level = client . permlevel ( message , data . guildSettings )
2020-03-31 07:59:09 +00:00
const cmd = client . commands . get ( command ) || client . commands . get ( client . aliases . get ( command ) )
if ( ! cmd ) return
2020-04-06 05:54:45 +00:00
if ( ! cmd . conf . enabled ) {
if ( data . guildData . systemNotice . enabled === true ) {
return message . channel . send ( 'This command has been disabled by my developers.' )
} else {
return
}
}
2020-03-31 07:59:09 +00:00
if ( cmd && ! message . guild && cmd . conf . guildOnly ) {
return message . channel . send ( 'This command is unavailable via private message. Please run this command in a guild.' )
}
2020-04-06 05:54:45 +00:00
if ( message . guild ) {
var missing = cmd . conf . requiredPerms . filter ( p => ! message . channel . permissionsFor ( client . user ) . has ( p ) )
if ( missing . length > 0 ) {
missing = '`' + ( missing . join ( '`, `' ) ) + '`'
return message . channel . send ( ` Missing permissions: ${ missing } ` )
}
}
2020-04-01 08:33:02 +00:00
// Dev perm level is separate so dev's don't get owner perms where they shouldn't have them
if ( cmd . conf . permLevel === 'Developer' ) {
2020-04-03 06:26:16 +00:00
if ( ! client . config . devs . includes ( message . author . id ) ) {
2020-04-06 05:54:45 +00:00
if ( data . guildData . systemNotice . enabled === true ) {
2020-04-04 06:59:22 +00:00
return message . channel . send ( 'You don\'t have permission to run this command!' )
} else {
return
}
2020-04-01 08:33:02 +00:00
}
}
2020-03-31 07:59:09 +00:00
if ( level < client . levelCache [ cmd . conf . permLevel ] ) {
2020-04-06 05:54:45 +00:00
if ( data . guildData . systemNotice . enabled === true ) {
2020-04-04 06:59:22 +00:00
return message . channel . send ( 'You don\'t have permission to run this command!' )
} else {
return
}
2020-03-31 07:59:09 +00:00
}
2020-03-31 15:45:45 +00:00
// Cooldown
if ( client . cooldown . get ( cmd . help . name ) . has ( message . author . id ) ) {
const init = client . cooldown . get ( command ) . get ( message . author . id )
const curr = new Date ( )
const diff = Math . round ( ( curr - init ) / 1000 )
const time = cmd . conf . cooldown / 1000
return message . reply ( ` this command is on cooldown! You'll be able to use it again in ${ time - diff } seconds. ` )
} else {
client . cooldown . get ( cmd . help . name ) . set ( message . author . id , new Date ( ) )
2020-03-31 08:24:51 +00:00
2020-03-31 15:45:45 +00:00
setTimeout ( ( ) => {
client . cooldown . get ( cmd . help . name ) . delete ( message . author . id )
} , client . commands . get ( cmd . help . name ) . conf . cooldown )
}
2020-03-31 08:24:51 +00:00
2020-03-31 07:59:09 +00:00
message . author . permLevel = level
2020-04-01 08:33:02 +00:00
// Might use this
2020-03-31 07:59:09 +00:00
message . flags = [ ]
while ( args [ 0 ] && args [ 0 ] [ 0 ] === '-' ) {
message . flags . push ( args . shift ( ) . slice ( 1 ) )
}
client . logger . log ( ` Command ran: ${ cmd . help . name } ` )
2020-04-06 05:54:45 +00:00
cmd . run ( client , message , args , level , data )
2020-03-31 07:59:09 +00:00
}