2021-12-10 21:39:54 +05:00
require ( "./helpers/extenders" ) ;
const Sentry = require ( "@sentry/node" ) ,
util = require ( "util" ) ,
fs = require ( "fs" ) ,
readdir = util . promisify ( fs . readdir ) ,
mongoose = require ( "mongoose" ) ,
2022-01-03 23:20:33 +05:00
chalk = require ( "chalk" ) ,
{ Intents } = require ( "discord.js" ) ;
2021-12-10 21:39:54 +05:00
const config = require ( "./config" ) ;
if ( config . apiKeys . sentryDSN ) {
try {
2021-12-26 19:29:37 +05:00
Sentry . init ( {
dsn : config . apiKeys . sentryDSN
} ) ;
2021-12-10 21:39:54 +05:00
} catch ( e ) {
console . log ( e ) ;
console . log ( chalk . yellow ( "Looks like your Sentry DSN key is invalid. If you do not intend to use Sentry, please remove the key from the configuration file." ) ) ;
} ;
} ;
2021-12-22 16:50:28 +05:00
// Load JaBa class
2022-01-03 23:20:33 +05:00
const JaBa = require ( "./base/JaBa" ) ;
const client = new JaBa ( {
2022-01-04 21:16:52 +05:00
intents : [
Intents . FLAGS . GUILDS ,
Intents . FLAGS . GUILD _MEMBERS ,
Intents . FLAGS . GUILD _BANS ,
Intents . FLAGS . GUILD _EMOJIS _AND _STICKERS ,
Intents . FLAGS . GUILD _INVITES ,
Intents . FLAGS . GUILD _VOICE _STATES ,
Intents . FLAGS . GUILD _PRESENCES ,
Intents . FLAGS . GUILD _MESSAGES ,
Intents . FLAGS . GUILD _MESSAGE _REACTIONS ,
Intents . FLAGS . GUILD _MESSAGE _TYPING ,
Intents . FLAGS . DIRECT _MESSAGES ,
] ,
2022-01-03 23:20:33 +05:00
partials : [ "CHANNEL" ]
} ) ;
2021-12-10 21:39:54 +05:00
const init = async ( ) => {
// Search for all commands
const directories = await readdir ( "./commands/" ) ;
2021-12-31 14:06:23 +05:00
client . logger . log ( ` Loading a total of ${ directories . length } categories. ` , "log" ) ;
2021-12-10 21:39:54 +05:00
directories . forEach ( async ( dir ) => {
const commands = await readdir ( ` ./commands/ ${ dir } / ` ) ;
commands . filter ( ( cmd ) => cmd . split ( "." ) . pop ( ) === "js" ) . forEach ( ( cmd ) => {
const response = client . loadCommand ( ` ./commands/ ${ dir } ` , cmd ) ;
if ( response ) {
client . logger . log ( response , "error" ) ;
} ;
} ) ;
} ) ;
// Then we load events, which will include our message and ready event.
const evtFiles = await readdir ( "./events/" ) ;
2022-01-01 23:50:33 +05:00
client . logger . log ( ` Loading a total of ${ evtFiles . length } events. ` , "log" ) ;
2021-12-10 21:39:54 +05:00
evtFiles . forEach ( ( file ) => {
const eventName = file . split ( "." ) [ 0 ] ;
client . logger . log ( ` Loading Event: ${ eventName } ` ) ;
2021-12-26 19:29:37 +05:00
const event = new ( require ( ` ./events/ ${ file } ` ) ) ( client ) ;
2021-12-10 21:39:54 +05:00
client . on ( eventName , ( ... args ) => event . run ( ... args ) ) ;
delete require . cache [ require . resolve ( ` ./events/ ${ file } ` ) ] ;
} ) ;
client . login ( client . config . token ) ; // Log in to the discord api
// connect to mongoose database
2021-12-26 19:29:37 +05:00
mongoose . connect ( client . config . mongoDB , {
useNewUrlParser : true ,
useUnifiedTopology : true
} ) . then ( ( ) => {
2021-12-10 21:39:54 +05:00
client . logger . log ( "Connected to the Mongodb database." , "log" ) ;
} ) . catch ( ( err ) => {
2021-12-24 20:52:27 +05:00
client . logger . log ( ` Unable to connect to the Mongodb database. Error: ${ err } ` , "error" ) ;
2021-12-10 21:39:54 +05:00
} ) ;
const languages = require ( "./helpers/languages" ) ;
client . translations = await languages ( ) ;
const autoUpdateDocs = require ( "./helpers/autoUpdateDocs.js" ) ;
autoUpdateDocs . update ( client ) ;
} ;
init ( ) ;
// if there are errors, log them
client . on ( "disconnect" , ( ) => client . logger . log ( "Bot is disconnecting..." , "warn" ) )
. on ( "reconnecting" , ( ) => client . logger . log ( "Bot reconnecting..." , "log" ) )
. on ( "error" , ( e ) => client . logger . log ( e , "error" ) )
. on ( "warn" , ( info ) => client . logger . log ( info , "warn" ) ) ;
// if there is an unhandledRejection, log them
process . on ( "unhandledRejection" , ( err ) => console . error ( err ) ) ;