Adds ICS
This commit is contained in:
parent
441715675c
commit
a79898b2e9
48 changed files with 2062 additions and 1503 deletions
|
|
@ -1,36 +1,28 @@
|
|||
import {DiscordClient} from "./DiscordClient";
|
||||
import {Logger} from "log4js";
|
||||
import {Routes, Snowflake} from "discord.js";
|
||||
import {REST, Routes, Snowflake} from "discord.js";
|
||||
import Commands from "./Commands/Commands";
|
||||
|
||||
export class CommandDeployer {
|
||||
constructor(
|
||||
private readonly client: DiscordClient,
|
||||
private readonly logger: Logger
|
||||
) {
|
||||
}
|
||||
|
||||
public async deployAvailableServers() {
|
||||
const commandInfos: object[] = [];
|
||||
this.client.Commands.allCommands.forEach((command) => {
|
||||
commandInfos.push(command.definition().toJSON())
|
||||
})
|
||||
|
||||
const guilds = await this.client.RESTClient.get(Routes.userGuilds());
|
||||
const deployments = guilds.map(guild => {
|
||||
return this.deployServer(commandInfos, guild.id)
|
||||
})
|
||||
|
||||
await Promise.all(deployments);
|
||||
}
|
||||
|
||||
private async deployServer(commandInfos: object[], serverId: Snowflake) {
|
||||
this.logger.log(`Started refreshing ${commandInfos.length} application (/) commands for ${serverId}.`);
|
||||
constructor(
|
||||
private readonly applicationId: string,
|
||||
private readonly restClient: REST,
|
||||
private readonly commands: Commands,
|
||||
private readonly logger: Logger
|
||||
) {
|
||||
}
|
||||
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
await this.client.RESTClient.put(
|
||||
Routes.applicationGuildCommands(this.client.ApplicationId, serverId),
|
||||
{ body: commandInfos },
|
||||
);
|
||||
this.logger.log(`Successfully reloaded ${commandInfos.length} application (/) commands for ${serverId}.`);
|
||||
}
|
||||
public async deployServer(serverId: Snowflake) {
|
||||
const commandInfos = this.commands.getJsonDefinitions();
|
||||
|
||||
this.logger.debug(`Started refreshing ${commandInfos.length} application (/) commands for ${serverId}.`);
|
||||
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
await this.restClient.put(
|
||||
Routes.applicationGuildCommands(this.applicationId, serverId),
|
||||
{body: commandInfos},
|
||||
);
|
||||
|
||||
this.logger.debug(`Successfully reloaded ${commandInfos.length} application (/) commands for ${serverId}.`);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue