mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: cleanup code (which probably does nothing but I am hopeful anyway)
This commit is contained in:
1 parent
57cc67c8be
commit
91260aed2a
5 files changed
+49
-2
No files matched your search
Vendored
+1
@@ -6,6 +6,7 @@
|
|||||||
"SKLLD",
|
"SKLLD",
|
||||||
"Smri",
|
"Smri",
|
||||||
"tankopedia",
|
"tankopedia",
|
||||||
|
"Unregistering",
|
||||||
"wargaming",
|
"wargaming",
|
||||||
"winrate"
|
"winrate"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { Client, Routes } from 'discord.js';
|
||||||
|
import { exit } from 'process';
|
||||||
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
|
import getClientId from '../utilities/getClientId.js';
|
||||||
|
import { rest } from './interactionCreate.js';
|
||||||
|
|
||||||
|
export const EXIT_EVENT_NAMES = [
|
||||||
|
'exit',
|
||||||
|
'SIGINT',
|
||||||
|
'SIGUSR1',
|
||||||
|
'SIGUSR2',
|
||||||
|
'uncaughtException',
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function cleanup(client: Client) {
|
||||||
|
console.log('Cleaning up...');
|
||||||
|
|
||||||
|
console.log('Unregistering public commands...');
|
||||||
|
rest.put(Routes.applicationCommands(getClientId()), { body: [] });
|
||||||
|
|
||||||
|
console.log('Unregistering guild commands...');
|
||||||
|
rest.put(Routes.applicationGuildCommands(getClientId(), discord.guild_id), {
|
||||||
|
body: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Destroying client...');
|
||||||
|
try {
|
||||||
|
client.destroy();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to destroy client');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Removing all exit event listeners...');
|
||||||
|
EXIT_EVENT_NAMES.forEach((exitEventName) =>
|
||||||
|
process.off(exitEventName, () => cleanup(client)),
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Exiting...');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ export interface CommandRegistry {
|
|||||||
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
|
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
|
export const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
|
||||||
const commandFolders = readdirSync('src/commands/');
|
const commandFolders = readdirSync('src/commands/');
|
||||||
const commandCollection = new Collection<string, CommandRegistry>();
|
const commandCollection = new Collection<string, CommandRegistry>();
|
||||||
const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
|
const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const DEFAULT_THRESHOLD = 7;
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inDevelopment: false,
|
inDevelopment: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Client, GatewayIntentBits } from 'discord.js';
|
import { Client, GatewayIntentBits } from 'discord.js';
|
||||||
|
import cleanup, { EXIT_EVENT_NAMES } from './behaviors/cleanup.js';
|
||||||
import guildMemberAdd from './behaviors/guildMemberAdd.js';
|
import guildMemberAdd from './behaviors/guildMemberAdd.js';
|
||||||
import interactionCreate from './behaviors/interactionCreate.js';
|
import interactionCreate from './behaviors/interactionCreate.js';
|
||||||
import ready from './behaviors/ready.js';
|
import ready from './behaviors/ready.js';
|
||||||
@@ -15,3 +16,7 @@ client.on('ready', ready);
|
|||||||
client.on('guildMemberAdd', guildMemberAdd);
|
client.on('guildMemberAdd', guildMemberAdd);
|
||||||
client.on('interactionCreate', interactionCreate);
|
client.on('interactionCreate', interactionCreate);
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
||||||
|
|
||||||
|
EXIT_EVENT_NAMES.forEach((exitEventName) =>
|
||||||
|
process.on(exitEventName, () => cleanup(client)),
|
||||||
|
);
|
||||||
Reference in new issue
Block a user