Moved deployment code to class

This commit is contained in:
Michel Fedde 2025-06-17 19:43:33 +02:00
parent aef26b1cc3
commit 83209f642c
6 changed files with 61 additions and 39 deletions

View file

@ -6,11 +6,10 @@ import Definitions from "./Database/definitions";
import {Container} from "./Container/Container";
import {ServiceHint, Services} from "./Container/Services";
import {Logger} from "log4js";
import {REST, Routes} from 'discord.js';
import {IconDeployer} from "./Icons/IconDeployer";
import {DiscordClient} from "./Discord/DiscordClient";
import {IconCache} from "./Icons/IconCache";
import {CommandDeployer} from "./Discord/CommandDeployer";
const container = Container.getInstance();
Services.setup(container, ServiceHint.Deploy)
@ -23,30 +22,13 @@ const logger = container.get<Logger>("logger");
const client = container.get<DiscordClient>(DiscordClient.name);
client.connectRESTClient(environment.discord.token)
const commands = client.Commands.allCommands;
logger.log("Deploying Commands...")
// and deploy your commands!
const deployer = new CommandDeployer(client, logger);
(async () => {
try {
const commandInfos = [];
commands.forEach((command) => {
commandInfos.push(command.definition().toJSON())
})
logger.log(`Started refreshing ${commandInfos.length} application (/) commands.`);
await deployer.deployAvailableServers()
})()
// The put method is used to fully refresh all commands in the guild with the current set
const data = await client.RESTClient.put(
Routes.applicationGuildCommands(environment.discord.clientId, environment.discord.guildId),
{ body: commandInfos },
);
logger.log(`Successfully reloaded ${commandInfos.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
logger.error(error);
}
})();
logger.log("Ensuring Database...");
const updater = new DatabaseUpdater(container.get<DatabaseConnection>(DatabaseConnection.name));