2018-09-18 21:33:52 +02:00
const { CommandoClient } = require ( 'discord.js-commando' ) ;
2018-09-26 13:35:43 +02:00
const Discord = require ( 'discord.js' ) ;
2018-09-24 17:10:49 +02:00
const path = require ( 'path' ) ;
2018-09-20 14:50:05 +02:00
const { token , prefix , botID , statsChannel , ownerID , supportServer } = require ( './config.json' ) ;
2018-09-20 17:50:47 +02:00
const responseObject = require ( "./json/reply.json" ) ;
const reactObject = require ( "./json/react.json" ) ;
2018-09-21 19:12:11 +02:00
const imgResponseObject = require ( "./json/imgreply.json" ) ;
2018-09-07 00:24:03 +02:00
2018-09-07 21:28:42 +02:00
// Prefix and ownerID and invite to support server
2018-09-07 00:24:03 +02:00
const client = new CommandoClient ( {
2018-09-18 13:52:20 +02:00
commandPrefix : prefix ,
owner : ownerID ,
invite : supportServer ,
2018-09-10 18:52:19 +02:00
unknownCommandResponse : false ,
2018-09-17 21:17:37 +02:00
disableEveryone : true ,
2018-09-07 00:24:03 +02:00
} ) ;
2018-09-07 21:28:42 +02:00
// Command groups
2018-09-07 00:24:03 +02:00
client . registry
2018-09-07 19:07:10 +02:00
. registerDefaultTypes ( )
. registerGroups ( [
2018-09-18 02:18:54 +02:00
[ 'fun' , 'Fun' ] ,
[ 'utility' , 'Utility' ] ,
[ 'admin' , 'Admins' ] ,
[ 'owner' , 'Owner' ] ,
2018-09-07 19:07:10 +02:00
] )
. registerDefaultGroups ( )
. registerDefaultCommands ( )
. registerCommandsIn ( path . join ( _ _dirname , 'commands' ) ) ;
2018-09-18 21:33:52 +02:00
// Ready messages
2018-09-19 16:43:51 +02:00
client . on ( 'ready' , async ( ) => {
2018-09-18 21:33:52 +02:00
// Send stats to the console
console . log ( ` Logged in as ${ client . user . tag } ! ( ${ client . user . id } ) ` ) ;
console . log ( ` Ready to serve in ${ client . channels . size } channels on ${ client . guilds . size } servers, for a total of ${ client . users . size } users. ${ client . readyAt } ` ) ;
// Send stats to the "stats" channel in the support server if its not the test bot
2018-09-23 23:12:32 +02:00
if ( client . user . id === botID ) {
2018-09-18 21:33:52 +02:00
const channel = client . channels . get ( statsChannel ) ;
channel . send ( ` Ready to serve in ${ client . channels . size } channels on ${ client . guilds . size } servers, for a total of ${ client . users . size } users. ${ client . readyAt } ` ) ;
client . user . setActivity ( '"haha help" or "@me help" for help' ) ;
2018-09-23 23:12:32 +02:00
}
2018-09-18 21:33:52 +02:00
} ) ;
// When bot join a guild send embeds with details about it.
2018-09-19 16:43:51 +02:00
client . on ( "guildCreate" , async guild => {
2018-09-23 23:04:13 +02:00
console . log ( ` ${ guild . name } \n ${ guild . memberCount } users \n Owner: ${ guild . owner . user . username } \n Owner ID: ${ guild . owner } ` ) ;
2018-09-18 21:33:52 +02:00
const channel = client . channels . get ( statsChannel ) ;
2018-09-26 13:35:43 +02:00
const addEmbed = new Discord . RichEmbed ( )
2018-09-27 15:19:24 +02:00
. setColor ( "#52e80d" )
2018-09-26 13:35:43 +02:00
. setTitle ( 'Someone added me ! YAY :D' )
2018-09-27 15:36:24 +02:00
. setThumbnail ( guild . iconURL )
2018-09-26 13:35:43 +02:00
. setDescription ( ` ${ guild . name } \n ${ guild . memberCount } users \n Owner: ${ guild . owner . user . username } \n Owner ID: ${ guild . owner } ` )
. setTimestamp ( )
2018-09-18 21:33:52 +02:00
channel . send ( { embed : addEmbed } ) ;
} )
// When bot get kicked from a guild send embeds with details about it.
2018-09-19 16:43:51 +02:00
client . on ( "guildDelete" , async guild => {
2018-09-23 23:04:13 +02:00
console . log ( ` ***BOT KICKED*** \n ${ guild . name } \n ${ guild . memberCount } users \n Owner: ${ guild . owner . user . username } \n Owner ID: ${ guild . owner } \n ***BOT KICKED*** ` ) ;
2018-09-18 21:33:52 +02:00
const channel = client . channels . get ( statsChannel ) ;
2018-09-26 13:35:43 +02:00
const kickEmbed = new Discord . RichEmbed ( )
. setColor ( "#FF0000" )
. setTitle ( 'They kicked me out :(' )
2018-09-27 15:36:24 +02:00
. setThumbnail ( guild . iconURL )
2018-09-26 13:35:43 +02:00
. setDescription ( ` ${ guild . name } \n ${ guild . memberCount } users \n Owner: ${ guild . owner . user . username } \n Owner ID: ${ guild . owner } ` )
. setTimestamp ( )
2018-09-18 21:33:52 +02:00
channel . send ( { embed : kickEmbed } ) ;
} )
2018-09-08 23:34:08 +02:00
2018-09-19 16:43:51 +02:00
client . on ( "message" , async ( message ) => {
2018-09-18 21:33:52 +02:00
let message _content = message . content . toLowerCase ( ) ;
2018-09-20 14:50:05 +02:00
// React to the message and send an auto response with it
2018-09-21 15:31:34 +02:00
if ( message . author . bot ) return ; {
2018-09-21 19:12:11 +02:00
// Reply with images as attachement
if ( imgResponseObject [ message _content ] ) {
message . channel . send ( { files : [ imgResponseObject [ message _content ] ] } ) ;
}
else if ( responseObject [ message _content ] && reactObject [ message _content ] ) {
2018-09-20 18:48:19 +02:00
message . channel . send ( responseObject [ message _content ] ) ;
2018-09-20 14:09:55 +02:00
message . react ( reactObject [ message _content ] ) ;
2018-09-20 14:50:05 +02:00
// React only to the messages
2018-09-20 14:09:55 +02:00
}
else if ( reactObject [ message _content ] ) {
message . react ( reactObject [ message _content ] ) ;
2018-09-18 21:33:52 +02:00
}
2018-09-20 14:50:05 +02:00
// auto respond to messages
2018-09-20 14:09:55 +02:00
else if ( responseObject [ message _content ] ) {
2018-09-20 18:48:19 +02:00
message . channel . send ( responseObject [ message _content ] ) ;
2018-09-20 14:09:55 +02:00
}
2018-09-21 15:31:34 +02:00
} } ) ;
2018-09-08 01:37:16 +02:00
2018-09-07 19:07:10 +02:00
client . on ( 'error' , console . error ) ;
2018-09-20 17:46:08 +02:00
process . on ( 'unhandledRejection' , error => console . error ( 'Uncaught Promise Rejection' , error ) ) ;
2018-09-07 00:24:03 +02:00
2018-09-07 19:07:10 +02:00
client . login ( token ) ;