import { REST } from '@discordjs/rest' ; import { Routes } from 'discord-api-types/v9' ; import { Options } from 'discord.js' ; import { Bot } from './bot' ; import { Button } from './buttons' ; import { Command , DevCommand , HelpCommand , InfoCommand , LinkCommand , TestCommand , TranslateCommand , } from './commands' ; import { ButtonHandler , CommandHandler , GuildJoinHandler , GuildLeaveHandler , MessageHandler , ReactionHandler , TriggerHandler , } from './events' ; import { CustomClient } from './extensions' ; import { Job } from './jobs' ; import { Reaction } from './reactions' ; import { JobService , Logger } from './services' ; import { Trigger } from './triggers' ; let Config = require ( '../config/config.json' ) ; let Logs = require ( '../lang/logs.json' ) ; async function start ( ) { let client = new CustomClient ( { intents : Config . client . intents , partials : Config . client . partials , makeCache : Options . cacheWithLimits ( { ... Options . defaultMakeCacheSettings , ... Config . client . caches , } ) , } ) ; let commands = [ new DevCommand ( ) , new HelpCommand ( ) , new InfoCommand ( ) , new LinkCommand ( ) , new TestCommand ( ) , new TranslateCommand ( ) , ] . sort ( ( a , b ) => ( a . metadata . name > b . metadata . name ? 1 : - 1 ) ) ; let buttons = [ ] ; let reactions = [ ] ; let triggers = [ ] ; let guildJoinHandler = new GuildJoinHandler ( ) ; let guildLeaveHandler = new GuildLeaveHandler ( ) ; let commandHandler = new CommandHandler ( commands ) ; let buttonHandler = new ButtonHandler ( buttons ) ; let triggerHandler = new TriggerHandler ( triggers ) ; let messageHandler = new MessageHandler ( triggerHandler ) ; let reactionHandler = new ReactionHandler ( reactions ) ; let jobs = [ ] ; let bot = new Bot ( Config . client . token , client , guildJoinHandler , guildLeaveHandler , messageHandler , commandHandler , buttonHandler , reactionHandler , new JobService ( jobs ) ) ; if ( process . argv [ 2 ] === '--register' ) { await registerCommands ( commands ) ; process . exit ( ) ; } await bot . start ( ) ; } async function registerCommands ( commands ) { let cmdDatas = commands . map ( cmd => cmd . metadata ) ; let cmdNames = cmdDatas . map ( cmdData => cmdData . name ) ; Logger . info ( Logs . info . commandsRegistering . replaceAll ( '{COMMAND_NAMES}' , cmdNames . map ( cmdName => `'${ cmdName }'` ) . join ( ', ' ) ) ) ; try { let rest = new REST ( { version : '9' } ) . setToken ( Config . client . token ) ; await rest . put ( Routes . applicationCommands ( Config . client . id ) , { body : [ ] } ) ; await rest . put ( Routes . applicationCommands ( Config . client . id ) , { body : cmdDatas } ) ; } catch ( error ) { Logger . error ( Logs . error . commandsRegistering , error ) ; return ; } Logger . info ( Logs . info . commandsRegistered ) ; } process . on ( 'unhandledRejection' , ( reason , _promise ) => { Logger . error ( Logs . error . unhandledRejection , reason ) ; } ) ; start ( ) . catch ( error => { Logger . error ( Logs . error . unspecified , error ) ; } ) ;