aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/Util.ts77
-rw-r--r--src/lib/models/Ban.ts3
-rw-r--r--src/lib/models/Guild.ts3
-rw-r--r--src/lib/models/Modlog.ts3
4 files changed, 80 insertions, 6 deletions
diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts
index 661392f..0aadc89 100644
--- a/src/lib/extensions/Util.ts
+++ b/src/lib/extensions/Util.ts
@@ -4,6 +4,16 @@ import { promisify } from 'util';
import { exec } from 'child_process';
import got from 'got';
import { MessageEmbed, GuildMember, User } from 'discord.js';
+import { CommandInteractionOption } from 'discord.js';
+import {
+ ApplicationCommandOptionType,
+ APIInteractionDataResolvedGuildMember,
+ APIInteractionDataResolvedChannel,
+ APIRole
+} from 'discord-api-types';
+import { GuildChannel } from 'discord.js';
+import { Role } from 'discord.js';
+import chalk from 'chalk';
interface hastebinRes {
key: string;
@@ -32,6 +42,17 @@ export interface uuidRes {
created_at: string;
}
+export interface SlashCommandOption<T> {
+ name: string;
+ type: ApplicationCommandOptionType;
+ value?: T;
+ options?: CommandInteractionOption[];
+ user?: User;
+ member?: GuildMember | APIInteractionDataResolvedGuildMember;
+ channel?: GuildChannel | APIInteractionDataResolvedChannel;
+ role?: Role | APIRole;
+}
+
export class Util extends ClientUtil {
/**
* The client of this ClientUtil
@@ -88,9 +109,7 @@ export class Util extends ClientUtil {
* @param command The shell command to run
* @returns The stdout and stderr of the shell command
*/
- public async shell(
- command: string
- ): Promise<{
+ public async shell(command: string): Promise<{
stdout: string;
stderr: string;
}> {
@@ -225,6 +244,58 @@ export class Util extends ClientUtil {
return apiRes.uuid;
}
+ public async syncSlashCommands(force = false): Promise<void> {
+ try {
+ const registered = await this.client.application.commands.fetch();
+ for (const [, registeredCommand] of registered) {
+ if (
+ !this.client.commandHandler.modules.find(
+ (cmd) => cmd.id == registeredCommand.name
+ ) ||
+ force
+ ) {
+ await this.client.application.commands.delete(registeredCommand.id);
+ this.client.logger.verbose(
+ chalk`{red Deleted slash command ${registeredCommand.name}}`
+ );
+ }
+ }
+
+ for (const [, botCommand] of this.client.commandHandler.modules) {
+ if (botCommand.execSlash) {
+ const found = registered.find((i) => i.name == botCommand.id);
+
+ const slashdata = {
+ name: botCommand.id,
+ description: botCommand.description.content,
+ options: botCommand.options.slashCommandOptions
+ };
+
+ if (found?.id && !force) {
+ if (slashdata.description !== found.description) {
+ await this.client.application.commands.edit(found.id, slashdata);
+ this.client.logger.verbose(
+ chalk`{yellow Edited slash command ${botCommand.id}}`
+ );
+ }
+ } else {
+ await this.client.application.commands.create(slashdata);
+ this.client.logger.verbose(
+ chalk`{green Created slash command ${botCommand.id}}`
+ );
+ }
+ }
+ }
+
+ return this.client.logger.log(chalk.green('Slash commands registered'));
+ } catch (e) {
+ console.log(chalk.red(e.stack));
+ return this.client.logger.error(
+ chalk`{red Slash commands not registered, see above error.}`
+ );
+ }
+ }
+
public moulberryBushRoleMap = [
{ name: '*', id: '792453550768390194' },
{ name: 'Admin Perms', id: '746541309853958186' },
diff --git a/src/lib/models/Ban.ts b/src/lib/models/Ban.ts
index c30c4c5..3ce9c06 100644
--- a/src/lib/models/Ban.ts
+++ b/src/lib/models/Ban.ts
@@ -22,7 +22,8 @@ export interface BanModelCreationAttributes {
export class Ban
extends BaseModel<BanModel, BanModelCreationAttributes>
- implements BanModel {
+ implements BanModel
+{
/**
* The ID of this ban (no real use just for a primary key)
*/
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index e4e317f..1cb3abb 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -10,7 +10,8 @@ export type GuildModelCreationAttributes = Optional<GuildModel, 'prefix'>;
export class Guild
extends BaseModel<GuildModel, GuildModelCreationAttributes>
- implements GuildModel {
+ implements GuildModel
+{
id: string;
prefix: string;
static initModel(seqeulize: Sequelize, client: BotClient): void {
diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts
index 6dd5e26..7efeeed 100644
--- a/src/lib/models/Modlog.ts
+++ b/src/lib/models/Modlog.ts
@@ -34,7 +34,8 @@ export interface ModlogModelCreationAttributes {
export class Modlog
extends BaseModel<ModlogModel, ModlogModelCreationAttributes>
- implements ModlogModel {
+ implements ModlogModel
+{
id: string;
type: ModlogType;
user: string;