Moved deployment code to class
This commit is contained in:
parent
aef26b1cc3
commit
83209f642c
6 changed files with 61 additions and 39 deletions
37
source/Discord/CommandDeployer.ts
Normal file
37
source/Discord/CommandDeployer.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import {DiscordClient} from "./DiscordClient";
|
||||
import {Logger} from "log4js";
|
||||
import {Routes, Snowflake} from "discord.js";
|
||||
|
||||
export class CommandDeployer {
|
||||
constructor(
|
||||
private readonly client: DiscordClient,
|
||||
private readonly logger: Logger
|
||||
) {
|
||||
}
|
||||
|
||||
public async deployAvailableServers() {
|
||||
const commandInfos = [];
|
||||
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}.`);
|
||||
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
const data = await this.client.RESTClient.put(
|
||||
Routes.applicationGuildCommands(this.client.ApplicationId, serverId),
|
||||
{ body: commandInfos },
|
||||
);
|
||||
|
||||
this.logger.log(`Successfully reloaded ${commandInfos.length} application (/) commands for ${serverId}.`);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,16 @@
|
|||
import {
|
||||
SlashCommandBuilder,
|
||||
Interaction,
|
||||
CommandInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
MessageFlags,
|
||||
GuildMemberRoleManager,
|
||||
InteractionReplyOptions,
|
||||
GuildMember,
|
||||
EmbedBuilder,
|
||||
AutocompleteInteraction,
|
||||
formatEmoji, roleMention, time, userMention
|
||||
roleMention, time, userMention
|
||||
} from "discord.js";
|
||||
import {AutocompleteCommand, ChatInteractionCommand, Command} from "./Command";
|
||||
import {GroupModel} from "../../Models/GroupModel";
|
||||
import {GroupRepository} from "../../Repositories/GroupRepository";
|
||||
import {DatabaseConnection} from "../../Database/DatabaseConnection";
|
||||
import {Container} from "../../Container/Container";
|
||||
import {GroupSelection} from "../CommandPartials/GroupSelection";
|
||||
import {UserError} from "../UserError";
|
||||
|
|
@ -25,9 +21,6 @@ import {GroupConfigurationTransformers} from "../../Groups/GroupConfigurationTra
|
|||
import {GroupConfigurationRepository} from "../../Repositories/GroupConfigurationRepository";
|
||||
import {IconCache} from "../../Icons/IconCache";
|
||||
import {PlaydateRepository} from "../../Repositories/PlaydateRepository";
|
||||
import playdate from "../../Database/tables/Playdate";
|
||||
import Commands from "./Commands";
|
||||
import Groups from "../../Database/tables/Groups";
|
||||
|
||||
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
|
||||
private static GOODBYE_MESSAGES: string[] = [
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ export class DiscordClient {
|
|||
});
|
||||
})
|
||||
|
||||
this.client.on(Events.GuildAvailable, () => {
|
||||
Container.get<Logger>("logger").info("Joined Guild?")
|
||||
})
|
||||
|
||||
this.client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
||||
const method = this.findCommandMethod(interaction);
|
||||
if (!method) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue