-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.ts
124 lines (108 loc) · 3.36 KB
/
start.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/rest/v9';
import { Options } from 'discord.js';
import { Bot } from './bot';
import {
Command,
DevCommand,
HandleCheckCommand,
HelpCommand,
InfoCommand,
LeaderboardCommand,
LinkCommand,
TranslateCommand,
VerifyCommand,
} from './commands';
import {
CommandHandler,
GuildJoinHandler,
GuildLeaveHandler,
MessageHandler,
ReactionHandler,
TriggerHandler,
} from './events';
import { CustomClient } from './extensions';
import { Reaction } from './reactions';
import { Env, JobService, Logger } from './services';
import { Trigger } from './triggers';
let Config = require('../config/config.json');
let Logs = require('../lang/logs.json');
async function start(): Promise<void> {
let client = new CustomClient({
intents: Config.client.intents,
partials: Config.client.partials,
makeCache: Options.cacheWithLimits({
// Keep default caching behavior
...Options.defaultMakeCacheSettings,
// Override specific options from config
...Config.client.caches,
}),
});
// Commands
let commands: Command[] = [
new DevCommand(),
new HelpCommand(),
new InfoCommand(),
new LinkCommand(),
new TranslateCommand(),
new VerifyCommand(),
new LeaderboardCommand(),
new HandleCheckCommand(),
// TODO: Add new commands here
].sort((a, b) => (a.metadata.name > b.metadata.name ? 1 : -1));
// Reactions
let reactions: Reaction[] = [
// TODO: Add new reactions here
];
// Triggers
let triggers: Trigger[] = [
// TODO: Add new triggers here
];
// Event handlers
let guildJoinHandler = new GuildJoinHandler();
let guildLeaveHandler = new GuildLeaveHandler();
let commandHandler = new CommandHandler(commands);
let triggerHandler = new TriggerHandler(triggers);
let messageHandler = new MessageHandler(triggerHandler);
let reactionHandler = new ReactionHandler(reactions);
let bot = new Bot(
Env.token,
client,
guildJoinHandler,
guildLeaveHandler,
messageHandler,
commandHandler,
reactionHandler,
new JobService([])
);
if (process.argv[2] === '--register') {
await registerCommands(commands);
process.exit();
}
await bot.start();
}
async function registerCommands(commands: Command[]): Promise<void> {
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(Env.token);
await rest.put(Routes.applicationCommands(Env.appId), { body: [] });
await rest.put(Routes.applicationCommands(Env.appId), { 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);
});