import * as dotenv from 'dotenv' ; import * as path from 'path' ; import * as Knex from 'knex' ; import { Model } from 'objection' ; import { ChannelDeleteEvent } from './events/channel.delete.event' ; import { EmojiCreateEvent } from './events/emoji.create.event' ; import { EmojiDeleteEvent } from './events/emoji.delete.event' ; import { EmojiUpdateEvent } from './events/emoji.update.event' ; import { GuildCreateEvent } from './events/guild.create.event' ; import { GuildDeleteEvent } from './events/guild.delete.event' ; import { MessageDeleteEvent } from './events/message.delete.event' ; import { MessageDeleteBulkEvent } from './events/message.delete-bulk.event' ; import { MessageReactionAddEvent } from './events/message.reaction-add.event' ; import { MessageReactionRemoveEvent } from './events/message.reaction-remove.event' ; import { RoleDeleteEvent } from './events/role.delete.event' ; import { ReadyEvent } from './events/ready.event' ; import { Channel , Collection , GuildEmoji , Intents , Message , MessageReaction , Role , Snowflake , User } from 'discord.js' ; import { CommandoClient , CommandoGuild } from 'discord.js-commando' ; import { ClientManager } from './managers/client.manager' ; import { ConfigurationManager } from './managers/configuration.manager' ; const config = dotenv . config ( { path : '.env' } ) ; if ( config . error ) { console . error ( 'configuration could not be parsed\n' , config . error ) ; process . exit ( 1 ) ; } global [ 'BOT_COLOR' ] = 0xc4fcff ; global [ 'SUCCESS_COLOR' ] = 0x6dcf84 ; global [ 'LOCAL' ] = process . env . LOCAL === 'true' ; const knex = Knex ( { client : 'mysql' , connection : { driver : process . env . DB_DRIVER , host : process . env . DB_HOST , port : parseInt ( process . env . DB_PORT ) , user : process . env . DB_USER , password : process . env . DB_PASSWORD , database : process . env . DB_DATABASE , charset : process . env . DB_CHARSET , } , } ) ; Model . knex ( knex ) ; const intents = new Intents ( ) ; intents . add ( 'GUILDS' , 'GUILD_MEMBERS' , 'GUILD_EMOJIS' , 'GUILD_PRESENCES' , 'GUILD_MESSAGES' , 'GUILD_MESSAGE_REACTIONS' , 'DIRECT_MESSAGES' ) ; const client = new CommandoClient ( { commandPrefix : global . LOCAL ? process . env . BOT_PREFIX : ConfigurationManager . getDefaultValue ( 'prefix' ) , owner : process . env . BOT_OWNER . split ( ',' ) , commandEditableDuration : 0 , messageCacheMaxSize : parseInt ( process . env . BOT_MESSAGE_CACHE ) , partials : [ 'REACTION' , 'MESSAGE' , 'GUILD_MEMBER' , 'USER' ] , ws : { intents : intents } , disableMentions : 'everyone' , } ) ; client . registry . registerDefaultTypes ( ) . registerDefaultGroups ( ) . registerDefaultCommands ( { unknownCommand : false , commandState : false , prefix : false , eval : false , help : false , } ) . registerGroups ( [ [ 'general' , 'General' ] , [ 'manage' , 'Management' ] , [ 'roles' , 'Role Management' ] , [ 'emoji' , 'Emoji' ] , ] ) . registerCommandsIn ( { dirname : path . join ( __dirname , 'commands' ) , filter : /^[^.].*\.(ts|js)$/g , } ) ; client . login ( process . env . BOT_TOKEN ) . catch ( console . error ) ; ClientManager . get ( ) . init ( client ) ; ClientManager . get ( ) . load ( ) . then ( ( ) => console . log ( 'objects have been initialized' ) ) ; client . once ( 'ready' , ( ) => { const ready = new ReadyEvent ( client ) ; return ready . handle ( ) ; } ) ; client . on ( 'channelDelete' , ( channel ) => { const event = new ChannelDeleteEvent ( client , channel ) ; return event . handle ( ) ; } ) ; client . on ( 'emojiCreate' , ( emoji ) => { const event = new EmojiCreateEvent ( client , emoji ) ; return event . handle ( ) ; } ) ; client . on ( 'emojiDelete' , ( emoji ) => { const event = new EmojiDeleteEvent ( client , emoji ) ; return event . handle ( ) ; } ) ; client . on ( 'emojiUpdate' , ( oldEmoji , newEmoji ) => { const event = new EmojiUpdateEvent ( client , oldEmoji , newEmoji ) ; return event . handle ( ) ; } ) ; client . on ( 'guildCreate' , ( guild ) => { const event = new GuildCreateEvent ( client , guild ) ; return event . handle ( ) ; } ) ; client . on ( 'guildDelete' , ( guild ) => { const event = new GuildDeleteEvent ( client , guild ) ; return event . handle ( ) ; } ) ; client . on ( 'messageDelete' , ( message ) => { const event = new MessageDeleteEvent ( client , message ) ; return event . handle ( ) ; } ) ; client . on ( 'messageDeleteBulk' , ( messages ) => { const event = new MessageDeleteBulkEvent ( client , messages ) ; return event . handle ( ) ; } ) ; client . on ( 'messageReactionAdd' , ( messageReaction , user ) => { const event = new MessageReactionAddEvent ( client , messageReaction , user ) ; return event . handle ( ) ; } ) ; client . on ( 'messageReactionRemove' , ( messageReaction , user ) => { const event = new MessageReactionRemoveEvent ( client , messageReaction , user ) ; return event . handle ( ) ; } ) ; client . on ( 'roleDelete' , ( role ) => { const event = new RoleDeleteEvent ( client , role ) ; return event . handle ( ) ; } ) ; process . on ( 'SIGINT' , ( ) => { client . destroy ( ) ; process . exit ( 0 ) ; } ) ;