2019-11-26 21:22:24 +00:00
module . exports = async ( client , message ) => {
if ( message . author . bot ) return ;
const settings = message . settings = client . getSettings ( message . guild ) ;
const prefixMention = new RegExp ( ` ^<@!? ${ client . user . id } >( |) $ ` ) ;
if ( message . content . match ( prefixMention ) ) {
2019-12-24 01:07:48 +00:00
return message . reply ( ` my prefix for this guild is \` ${ settings . prefix } \` ` ) ;
2019-11-26 21:22:24 +00:00
}
if ( message . content . indexOf ( settings . prefix ) !== 0 ) return ;
const args = message . content . slice ( settings . prefix . length ) . trim ( ) . split ( / +/g ) ;
const command = args . shift ( ) . toLowerCase ( ) ;
if ( message . guild && ! message . member ) await message . guild . fetchMember ( message . author ) ;
const level = client . permlevel ( message ) ;
const cmd = client . commands . get ( command ) || client . commands . get ( client . aliases . get ( command ) ) ;
if ( ! cmd ) return ;
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." ) ;
if ( level < client . levelCache [ cmd . conf . permLevel ] ) {
if ( settings . systemNotice === "true" ) {
2019-12-24 03:40:11 +00:00
message . delete ( ) ;
return message . channel . send ( ` ${ message . author } , you do not have the right permissions to use this command. \n Your current permission level is ** ${ level } ** ( ${ client . config . permLevels . find ( l => l . level === level ) . name } ), and this command requires permission level ** ${ client . levelCache [ cmd . conf . permLevel ] } ** ( ${ cmd . conf . permLevel } ) ` ) ;
2019-11-26 21:22:24 +00:00
} else {
return ;
}
}
message . author . permLevel = level ;
message . flags = [ ] ;
while ( args [ 0 ] && args [ 0 ] [ 0 ] === "-" ) {
message . flags . push ( args . shift ( ) . slice ( 1 ) ) ;
}
2019-12-24 01:23:06 +00:00
2019-11-26 21:22:24 +00:00
client . logger . cmd ( ` [CMD] ${ client . config . permLevels . find ( l => l . level === level ) . name } ${ message . author . username } ( ${ message . author . id } ) ran command ${ cmd . help . name } ` ) ;
cmd . run ( client , message , args , level ) ;
} ;