65 lines
No EOL
2.2 KiB
TypeScript
65 lines
No EOL
2.2 KiB
TypeScript
import Commands from "./Discord/Commands/Commands";
|
|
import {Environment} from "./Environment";
|
|
import {DatabaseConnection} from "./Database/DatabaseConnection";
|
|
import {DatabaseUpdater} from "./Database/DatabaseUpdater";
|
|
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";
|
|
|
|
const container = Container.getInstance();
|
|
Services.setup(container, ServiceHint.Deploy)
|
|
|
|
|
|
const environment = container.get<Environment>(Environment.name);
|
|
const logger = container.get<Logger>("logger");
|
|
// Construct and prepare an instance of the REST module
|
|
|
|
const client = container.get<DiscordClient>(DiscordClient.name);
|
|
client.connectRESTClient(environment.discord.token)
|
|
|
|
const commands = client.Commands.allCommands;
|
|
|
|
// and deploy your commands!
|
|
(async () => {
|
|
try {
|
|
const commandInfos = [];
|
|
commands.forEach((command) => {
|
|
commandInfos.push(command.definition().toJSON())
|
|
})
|
|
|
|
logger.log(`Started refreshing ${commandInfos.length} application (/) commands.`);
|
|
|
|
// 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));
|
|
updater.ensureAvaliablity(Definitions);
|
|
|
|
logger.log("Ensuring icons...");
|
|
(async () => {
|
|
const iconCache = container.get<IconCache>(IconCache.name);
|
|
await iconCache.populate();
|
|
|
|
const deployer = new IconDeployer(
|
|
iconCache
|
|
);
|
|
|
|
deployer.ensureExistance()
|
|
})() |