2020-01-03 16:27:32 +00:00
const {
Collection ,
MessageEmbed
} = require ( 'discord.js' ) ;
const {
table
} = require ( 'quick.db' ) ;
2019-11-10 08:42:09 +00:00
const Servers = new table ( 'servers' ) ;
const Users = new table ( 'users' ) ;
const Backend = new table ( 'backend' ) ;
2019-11-10 20:50:18 +00:00
const Trello = require ( 'trello' ) ;
const config = require ( '../config' ) ;
2020-01-05 18:11:13 +00:00
const vars = require ( '../vars' ) ;
2020-01-03 16:27:32 +00:00
const {
db ,
topic
} = require ( '../utils' )
2019-11-10 20:50:18 +00:00
const trello = new Trello ( config . trello . key , config . trello . token ) ;
2019-10-09 16:19:30 +00:00
module . exports = {
2019-11-10 08:42:09 +00:00
name : 'message' ,
run : async ( client , msg ) => {
if ( msg . author . bot ) return ;
2020-01-03 16:27:32 +00:00
//if (msg.author.id !== '318044130796109825') return;
//console.log(msg.author.tag)
let UserFromDB = await db . blacklist ( msg . author . id , 's' )
if ( UserFromDB . state ) return ;
2019-11-10 08:42:09 +00:00
const DefaultPrefix = client . config . prefixes ;
const CustomPrefix = Servers . get ( msg . guild . id ) ;
if ( ! CustomPrefix ) {
2020-01-03 16:27:32 +00:00
PrefixArray = [ DefaultPrefix /* , CustomPrefix */ ] . flat ( Infinity ) ;
2019-11-10 08:42:09 +00:00
} else {
2020-01-03 16:27:32 +00:00
PrefixArray = [ DefaultPrefix , CustomPrefix . prefix ] . flat ( Infinity ) ;
2019-11-10 08:42:09 +00:00
}
let PREFIX ;
let EXISTS ;
for ( p in PrefixArray ) {
if ( msg . content . startsWith ( PrefixArray [ p ] ) ) {
EXISTS = true ;
PREFIX = p ;
}
}
if ( ! EXISTS ) return ;
2020-01-03 16:27:32 +00:00
//console.log(topic.includesSetting('thaldrin.no-cmds', msg.channel.topic))
if ( topic . includesSetting ( 'thaldrin.no-cmd' , msg . channel . topic ) ) return ;
2019-11-10 08:42:09 +00:00
const args = msg . content . slice ( PrefixArray [ PREFIX ] . length ) . trim ( ) . split ( / +/g ) ;
const command = args . shift ( ) . toLowerCase ( ) ;
const cmd = client . commands . find ( ( c ) => c . name == command || ( c . aliases && c . aliases . includes ( command ) ) ) ;
2019-10-09 16:19:30 +00:00
2020-01-03 16:27:32 +00:00
2019-11-10 08:42:09 +00:00
const ctx = {
send : msg . channel . send . bind ( msg . channel ) ,
client ,
msg ,
args ,
command : cmd ,
me : msg . guild . me ,
guild : msg . guild ,
channel : msg . channel ,
author : msg . author ,
member : msg . member ,
2019-11-10 20:50:18 +00:00
trello ,
2020-01-03 16:27:32 +00:00
db : {
users : Users ,
servers : Servers ,
backend : Backend
} ,
2019-11-10 08:42:09 +00:00
utils : require ( '../utils' ) ,
config : require ( '../config' ) ,
2019-12-17 10:07:37 +00:00
vars : require ( '../vars' ) ,
2020-01-05 18:11:13 +00:00
isDeveloper : vars . developers . find ( ( dev ) => msg . author . id == dev . id )
2019-11-10 08:42:09 +00:00
} ;
if ( ! cmd ) return ;
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
if ( ! client . cooldowns . has ( cmd . name ) ) {
client . cooldowns . set ( cmd . name , new Collection ( ) ) ;
}
2019-10-09 16:19:30 +00:00
2019-11-13 21:12:14 +00:00
if ( ctx . isDeveloper ) {
cmd . AuthorPermissions = 'NONE' ;
}
2019-11-10 08:42:09 +00:00
if ( cmd . guildOnly && ! msg . guild ) return ;
if ( cmd . nsfw && ! ctx . channel . nsfw )
2019-11-21 21:41:53 +00:00
return ctx . send ( 'This channel is not set to NSFW, please mark it as such and rerun this command.' ) ;
2020-01-05 18:11:13 +00:00
if ( cmd . developerOnly && ! vars . developers . find ( ( dev ) => msg . author . id == dev . id ) ) return ;
2019-11-11 17:08:27 +00:00
if ( cmd . AuthorPermissions !== 'NONE' && ! ctx . member . permissions . has ( cmd . AuthorPermissions ) ) {
2019-11-13 21:12:14 +00:00
return ctx . send ( ` You need the \` ${ cmd . AuthorPermissions } \` Permission(s) to run this Command ` ) ;
2019-11-11 17:08:27 +00:00
}
2019-11-10 08:42:09 +00:00
const now = Date . now ( ) ;
const timestamps = client . cooldowns . get ( cmd . name ) ;
const cooldownAmount = ( cmd . cooldown || 1 ) * 1000 ;
2019-10-09 16:19:30 +00:00
2019-11-10 08:42:09 +00:00
if ( timestamps . has ( msg . author . id ) ) {
const expirationTime = timestamps . get ( msg . author . id ) + cooldownAmount ;
2019-10-09 16:19:30 +00:00
2019-11-10 08:42:09 +00:00
if ( now < expirationTime ) {
2019-11-11 17:08:27 +00:00
let CooldownEmb = new MessageEmbed ( ) ;
2019-11-10 08:42:09 +00:00
const timeLeft = ( expirationTime - now ) / 1000 ;
2019-11-11 17:08:27 +00:00
CooldownEmb . setTitle ( ` ${ cmd . name } is on cooldown ` ) . setDescription (
2019-11-10 08:42:09 +00:00
` \` ${ cmd . name } \` has a cooldown of \` ${ cmd . cooldown } second ${ cmd . cooldown > 1
? 's'
2019-11-11 17:08:27 +00:00
: '' } \ ` \n Wait \` ${ ` ${ Math . round ( timeLeft ) } second ${ Math . round ( timeLeft ) > 1
2019-11-10 08:42:09 +00:00
? 's'
: '' } ` .replace('0 second', 'just a second longer')} \` before trying to use it again. `
) ;
2019-11-11 17:08:27 +00:00
return ctx . send ( CooldownEmb ) ;
2019-11-10 08:42:09 +00:00
}
} else {
timestamps . set ( msg . author . id , now ) ;
setTimeout ( ( ) => timestamps . delete ( msg . author . id ) , cooldownAmount ) ;
2019-10-09 16:19:30 +00:00
2020-01-14 20:24:14 +00:00
cmd . command ( ctx ) . then ( async ( ) => {
2020-01-19 23:35:54 +00:00
if ( ! ctx . config . type . beta ) ctx . client . channels . find ( c => c . id === vars . logs . usage ) . send ( ` ${ ctx . utils . format . bold ( ctx . author . tag ) } ( ${ ctx . utils . format . code ( ctx . author . id ) } ) used ${ ctx . utils . format . code ( cmd . name ) } in ${ ctx . utils . format . bold ( ctx . guild . name ) } ( ${ ctx . utils . format . code ( ctx . guild . id ) } ) ` ) . catch ( e => console . log ( e ) )
2020-01-14 20:24:14 +00:00
await ctx . db . backend . add ( ` usage. ${ cmd . name } ` , 1 )
2020-01-06 13:55:04 +00:00
} ) . catch ( ( err ) => {
2020-01-19 23:35:54 +00:00
if ( ! cmd . name === 'e926' || ! cmd . name === 'e621' ) {
2019-11-21 21:41:53 +00:00
trello
. addCard (
cmd . name + ' | ' + err . message ,
` Full Error:
2019-11-10 20:50:18 +00:00
$ { err }
2019-11-13 21:12:14 +00:00
Content : $ { ctx . msg . content }
2019-11-10 20:50:18 +00:00
Author : $ { msg . author . tag } ( $ { msg . author . id } )
Server : $ { msg . guild . name } ( $ { msg . guild . id } ) ` ,
2019-11-21 21:41:53 +00:00
config . trello . boards . errors
)
. then ( ( r ) => {
trello
. addLabelToCard ( r . id , config . trello . labels . errors )
. catch ( ( error ) => console . log ( error ) ) ;
} )
. catch ( ( err ) => console . log ( err ) ) ;
}
//console.warn(err.message);
let ErrorEmb = new MessageEmbed ( ) ;
ErrorEmb . setTitle ( ` ${ cmd . name } encountered an Error ` )
. setDescription ( ` \` ${ err . message } \` \n \n \` ${ err } \` ` )
. setColor ( 'RED' ) ;
return ctx . send ( ErrorEmb ) ;
2019-11-10 20:50:18 +00:00
} ) ;
2019-11-10 08:42:09 +00:00
}
}
2020-01-03 16:27:32 +00:00
} ;