pnp-scheduler/source/deploy.ts

46 lines
No EOL
1.8 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";
const { REST, Routes } = require('discord.js');
const container = Container.getInstance();
Services.setup(container, ServiceHint.Deploy)
const commands = new Commands().allCommands;
const environment = container.get<Environment>(Environment.name);
const logger = container.get<Logger>("logger");
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(environment.discord.token);
// 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 rest.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);