From ba031ea4c942e4f20d506f28a6475e8b64f1df92 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:01:07 +0000 Subject: [PATCH 01/26] Add EnableCommand to enable voice commands --- .../voice_commands/commands/EnableCommand.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src_modules/voice_commands/commands/EnableCommand.ts diff --git a/src_modules/voice_commands/commands/EnableCommand.ts b/src_modules/voice_commands/commands/EnableCommand.ts new file mode 100644 index 0000000..a40dcdb --- /dev/null +++ b/src_modules/voice_commands/commands/EnableCommand.ts @@ -0,0 +1,33 @@ +import { Command, IExecutionContext } from "extcord"; +import VoiceCommandsModule from ".."; +import { voiceCommandsEnabledErrorPhrase, voiceCommandsEnabledPhrase } from "../phrases"; + +export class EnableCommand extends Command<[]> { + private voiceCommandsModule: VoiceCommandsModule; + + public constructor(voiceCommandsModule: VoiceCommandsModule) { + super( + { + allowedPrivileges: ["everyone"], + author: "extcord", + description: "Enable voice commands", + globalAliases: ["enable"], + name: "enable", + }, + [], + ); + + this.voiceCommandsModule = voiceCommandsModule; + } + + public async execute(context: IExecutionContext<[]>) { + const guild = context.guild.guild; + + if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { + return context.respond(voiceCommandsEnabledErrorPhrase, {}); + } + + await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, true); + return context.respond(voiceCommandsEnabledPhrase, {}); + } +} From f4b7f2d98fdc3d176688d0b1d8ef2849319f1d94 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:01:29 +0000 Subject: [PATCH 02/26] Add DisableCommand to disable voice commands --- .../voice_commands/commands/DisableCommand.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src_modules/voice_commands/commands/DisableCommand.ts diff --git a/src_modules/voice_commands/commands/DisableCommand.ts b/src_modules/voice_commands/commands/DisableCommand.ts new file mode 100644 index 0000000..2e50765 --- /dev/null +++ b/src_modules/voice_commands/commands/DisableCommand.ts @@ -0,0 +1,33 @@ +import { Command, IExecutionContext } from "../../../.."; +import VoiceCommandsModule from ".."; +import { voiceCommandsDisabledPhrase, voiceCommandsAlreadyDisabledPhrase } from "../phrases"; + +export class DisableCommand extends Command<[]> { + private voiceCommandsModule: VoiceCommandsModule; + + public constructor(voiceCommandsModule: VoiceCommandsModule) { + super( + { + allowedPrivileges: ["everyone"], + author: "extcord", + description: "Disable voice commands", + globalAliases: ["disable"], + name: "disable", + }, + [], + ); + + this.voiceCommandsModule = voiceCommandsModule; + } + + public async execute(context: IExecutionContext<[]>) { + const guild = context.guild.guild; + + if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { + await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, false); + return context.respond(voiceCommandsDisabledPhrase, {}); + } else { + return context.respond(voiceCommandsAlreadyDisabledPhrase, {}); + } + } +} From 1994d1ccbe1e76b5a5724a9e2eb7fc9f0ad674ea Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:01:49 +0000 Subject: [PATCH 03/26] Added EnableAutoJoinCommand to enable automatic jo --- .../commands/EnableAutoJoinCommand.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src_modules/voice_commands/commands/EnableAutoJoinCommand.ts diff --git a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts new file mode 100644 index 0000000..432c0a1 --- /dev/null +++ b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts @@ -0,0 +1,33 @@ +import { Command, IExecutionContext } from "../../../framework"; +import VoiceCommandsModule from ".."; +import { autoJoinEnabledPhrase, autoJoinAlreadyEnabledPhrase } from "../phrases"; + +export class EnableAutoJoinCommand extends Command<[]> { + private voiceCommandsModule: VoiceCommandsModule; + + public constructor(voiceCommandsModule: VoiceCommandsModule) { + super( + { + allowedPrivileges: ["everyone"], + author: "extcord", + description: "Enable automatic joining", + globalAliases: ["enableautojoin"], + name: "enableautojoin", + }, + [], + ); + + this.voiceCommandsModule = voiceCommandsModule; + } + + public async execute(context: IExecutionContext<[]>) { + const guild = context.guild.guild; + + if (await this.voiceCommandsModule.autoJoinConfigEntry.guildGet(guild)) { + return context.respond(autoJoinAlreadyEnabledPhrase, {}); + } + + await this.voiceCommandsModule.autoJoinConfigEntry.guildSet(guild, true); + return context.respond(autoJoinEnabledPhrase, {}); + } +} From a55ff7a0d71323c5bc2d6414908660c4de7b9ee0 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:02:08 +0000 Subject: [PATCH 04/26] Add DisableAutoJoinCommand to disable automatic jo --- .../commands/DisableAutoJoinCommand.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src_modules/voice_commands/commands/DisableAutoJoinCommand.ts diff --git a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts new file mode 100644 index 0000000..2862c1e --- /dev/null +++ b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts @@ -0,0 +1,33 @@ +import { Command, IExecutionContext } from "../../../framework"; +import VoiceCommandsModule from ".."; +import { autoJoinDisabledPhrase, autoJoinAlreadyDisabledPhrase } from "../phrases"; + +export class DisableAutoJoinCommand extends Command<[]> { + private voiceCommandsModule: VoiceCommandsModule; + + public constructor(voiceCommandsModule: VoiceCommandsModule) { + super( + { + allowedPrivileges: ["everyone"], + author: "extcord", + description: "Disable automatic joining", + globalAliases: ["disableautojoin"], + name: "disableautojoin", + }, + [], + ); + + this.voiceCommandsModule = voiceCommandsModule; + } + + public async execute(context: IExecutionContext<[]>) { + const guild = context.guild.guild; + + if (await this.voiceCommandsModule.autoJoinConfigEntry.guildGet(guild)) { + await this.voiceCommandsModule.autoJoinConfigEntry.guildSet(guild, false); + return context.respond(autoJoinDisabledPhrase, {}); + } else { + return context.respond(autoJoinAlreadyDisabledPhrase, {}); + } + } +} From f7168b3744eea458e99f4dcc9baf5f7245e3bf20 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:02:36 +0000 Subject: [PATCH 05/26] Updated src_modules/voice_commands/index.ts --- src_modules/voice_commands/index.ts | 64 +++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index fa8cd72..9c96c06 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -43,9 +43,29 @@ export default class VoiceCommandsModule extends Module { }); this.keywordPhrase = new SimplePhrase({ - name: "keyword", - }, "bot"); - this.registerPhrase(this.keywordPhrase); + name: "keyword", + }, "bot"); + this.registerPhrase(this.keywordPhrase); + + this.voiceCommandsEnabledPhrase = new SimplePhrase({ + name: "voiceCommandsEnabled", + }, "Voice commands enabled."); + this.registerPhrase(this.voiceCommandsEnabledPhrase); + + this.voiceCommandsDisabledPhrase = new SimplePhrase({ + name: "voiceCommandsDisabled", + }, "Voice commands disabled."); + this.registerPhrase(this.voiceCommandsDisabledPhrase); + + this.autoJoinEnabledPhrase = new SimplePhrase({ + name: "autoJoinEnabled", + }, "Automatic joining enabled."); + this.registerPhrase(this.autoJoinEnabledPhrase); + + this.autoJoinDisabledPhrase = new SimplePhrase({ + name: "autoJoinDisabled", + }, "Automatic joining disabled."); + this.registerPhrase(this.autoJoinDisabledPhrase); this.backendLanguageIdPhrase = new SimplePhrase({ name: "backendLanguageId", @@ -93,17 +113,32 @@ export default class VoiceCommandsModule extends Module { this.registerConfigEntry(this.tokenConfigEntry); this.voiceCommandsEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "voiceCommandsEnabled", - }, bot.database, true); - this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); + name: "voiceCommandsEnabled", + }, bot.database, true); + this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); + + this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ + name: "autoJoinEnabled", + }, bot.database, false); + this.registerConfigEntry(this.autoJoinEnabledConfigEntry); bot.intents.push(GatewayIntentBits.GuildVoiceStates); this.client = new VoiceBackendClient(this); this.voiceCommands = new VoiceCommands(this, bot); - this.phoneticCache = new PhoneticCache(this, bot); - this.speechCache = new SpeechCache(this, bot); + this.phoneticCache = new PhoneticCache(this, bot); + this.speechCache = new SpeechCache(this, bot); + + this.registerCommandGroup({ + name: "voice-commands", + description: "Commands for managing voice commands and automatic joining", + }); + + this.registerCommand("voice-commands", new EnableCommand(this)); + this.registerCommand("voice-commands", new DisableCommand(this)); + this.registerCommand("voice-commands", new EnableAutoJoinCommand(this)); + this.registerCommand("voice-commands", new DisableAutoJoinCommand(this)); } public async getListener(guild: Guild): Promise { @@ -141,7 +176,18 @@ export default class VoiceCommandsModule extends Module { private async onVoiceStateUpdate(oldState: VoiceState, newState: VoiceState) { if (oldState.channel === null && newState.channel !== null && newState.channel instanceof VoiceChannel && !newState.member?.user.bot) { - const channel = newState.channel; + const channel = newState.channel; + + const extendedGuild = { + entity: guildEntity, + guild: guild, + }; + + const autoJoinEnabled = await this.autoJoinEnabledConfigEntry.guildGet(extendedGuild); + + if (!autoJoinEnabled) { + return; + } // Someone joined a voice channel const nonBotUsers = channel.members.filter(member => !member.user.bot); From 836f2993976b0c6adc88c7ff37b3c11487996933 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:11:06 +0000 Subject: [PATCH 06/26] Moved voice command phrases to separate file --- src_modules/voice_commands/phrases.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src_modules/voice_commands/phrases.ts diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts new file mode 100644 index 0000000..9d10616 --- /dev/null +++ b/src_modules/voice_commands/phrases.ts @@ -0,0 +1,17 @@ +import { SimplePhrase } from "extcord"; + +export const voiceCommandsEnabledPhrase = new SimplePhrase({ + name: "voiceCommandsEnabled", +}, "Voice commands enabled."); + +export const voiceCommandsDisabledPhrase = new SimplePhrase({ + name: "voiceCommandsDisabled", +}, "Voice commands disabled."); + +export const autoJoinEnabledPhrase = new SimplePhrase({ + name: "autoJoinEnabled", +}, "Automatic joining enabled."); + +export const autoJoinDisabledPhrase = new SimplePhrase({ + name: "autoJoinDisabled", +}, "Automatic joining disabled."); From ea791a9ff8694547c18e74bd49947b536dea9adb Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:11:26 +0000 Subject: [PATCH 07/26] Updated src_modules/voice_commands/index.ts --- src_modules/voice_commands/index.ts | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index 9c96c06..7199fe5 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -5,6 +5,7 @@ import { GatewayIntentBits, Guild, VoiceState, VoiceChannel } from "discord.js"; import { VoiceConnection } from "@discordjs/voice"; import { BooleanGuildConfigEntry, Bot, Logger, Module, SimplePhrase, StringConfigEntry, NumberConfigEntry } from "../.."; +import { keywordPhrase, voiceCommandsEnabledPhrase, voiceCommandsDisabledPhrase, autoJoinEnabledPhrase, autoJoinDisabledPhrase } from "./phrases"; import { GuildListener } from "./GuildListener"; import { VoiceBackendClient } from "./VoiceBackendClient"; @@ -42,30 +43,7 @@ export default class VoiceCommandsModule extends Module { options.selfDeaf = false; }); - this.keywordPhrase = new SimplePhrase({ - name: "keyword", - }, "bot"); - this.registerPhrase(this.keywordPhrase); - - this.voiceCommandsEnabledPhrase = new SimplePhrase({ - name: "voiceCommandsEnabled", - }, "Voice commands enabled."); - this.registerPhrase(this.voiceCommandsEnabledPhrase); - - this.voiceCommandsDisabledPhrase = new SimplePhrase({ - name: "voiceCommandsDisabled", - }, "Voice commands disabled."); - this.registerPhrase(this.voiceCommandsDisabledPhrase); - - this.autoJoinEnabledPhrase = new SimplePhrase({ - name: "autoJoinEnabled", - }, "Automatic joining enabled."); - this.registerPhrase(this.autoJoinEnabledPhrase); - - this.autoJoinDisabledPhrase = new SimplePhrase({ - name: "autoJoinDisabled", - }, "Automatic joining disabled."); - this.registerPhrase(this.autoJoinDisabledPhrase); + // Removed phrases this.backendLanguageIdPhrase = new SimplePhrase({ name: "backendLanguageId", From 543bdf8344773191cc0d3d910a17d56d101e95ed Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:19:35 +0000 Subject: [PATCH 08/26] Updated src_modules/voice_commands/phrases.ts --- src_modules/voice_commands/phrases.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts index 9d10616..67fc026 100644 --- a/src_modules/voice_commands/phrases.ts +++ b/src_modules/voice_commands/phrases.ts @@ -1,17 +1,17 @@ -import { SimplePhrase } from "extcord"; +import { MessagePhrase } from "extcord"; -export const voiceCommandsEnabledPhrase = new SimplePhrase({ +export const voiceCommandsEnabledPhrase = new MessagePhrase({ name: "voiceCommandsEnabled", }, "Voice commands enabled."); -export const voiceCommandsDisabledPhrase = new SimplePhrase({ +export const voiceCommandsDisabledPhrase = new MessagePhrase({ name: "voiceCommandsDisabled", }, "Voice commands disabled."); -export const autoJoinEnabledPhrase = new SimplePhrase({ +export const autoJoinEnabledPhrase = new MessagePhrase({ name: "autoJoinEnabled", }, "Automatic joining enabled."); -export const autoJoinDisabledPhrase = new SimplePhrase({ +export const autoJoinDisabledPhrase = new MessagePhrase({ name: "autoJoinDisabled", }, "Automatic joining disabled."); From e14c2edc379aa72758368de4aceebdfea71b0fec Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:21:20 +0000 Subject: [PATCH 09/26] Updated src_modules/voice_commands/phrases.ts --- src_modules/voice_commands/phrases.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts index 67fc026..0fc6f67 100644 --- a/src_modules/voice_commands/phrases.ts +++ b/src_modules/voice_commands/phrases.ts @@ -2,16 +2,20 @@ import { MessagePhrase } from "extcord"; export const voiceCommandsEnabledPhrase = new MessagePhrase({ name: "voiceCommandsEnabled", -}, "Voice commands enabled."); + message: "Voice commands enabled.", +}); export const voiceCommandsDisabledPhrase = new MessagePhrase({ name: "voiceCommandsDisabled", -}, "Voice commands disabled."); + message: "Voice commands disabled.", +}); export const autoJoinEnabledPhrase = new MessagePhrase({ name: "autoJoinEnabled", -}, "Automatic joining enabled."); + message: "Automatic joining enabled.", +}); export const autoJoinDisabledPhrase = new MessagePhrase({ name: "autoJoinDisabled", -}, "Automatic joining disabled."); + message: "Automatic joining disabled.", +}); From 936ec0b1a7d183f0fd09597bc65660a972bcdb25 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:26:23 +0000 Subject: [PATCH 10/26] Updated src_modules/voice_commands/commands/Disabl --- src_modules/voice_commands/commands/DisableAutoJoinCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts index 2862c1e..d2432fa 100644 --- a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts +++ b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts @@ -1,4 +1,4 @@ -import { Command, IExecutionContext } from "../../../framework"; +import { Command, IExecutionContext } from "../../.."; import VoiceCommandsModule from ".."; import { autoJoinDisabledPhrase, autoJoinAlreadyDisabledPhrase } from "../phrases"; From 551e87e64f152a6bed77f43d29fcef9aae1c8ded Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:26:28 +0000 Subject: [PATCH 11/26] Updated src_modules/voice_commands/commands/Disabl --- src_modules/voice_commands/commands/DisableCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_modules/voice_commands/commands/DisableCommand.ts b/src_modules/voice_commands/commands/DisableCommand.ts index 2e50765..02c3895 100644 --- a/src_modules/voice_commands/commands/DisableCommand.ts +++ b/src_modules/voice_commands/commands/DisableCommand.ts @@ -1,4 +1,4 @@ -import { Command, IExecutionContext } from "../../../.."; +import { Command, IExecutionContext } from "../../.."; import VoiceCommandsModule from ".."; import { voiceCommandsDisabledPhrase, voiceCommandsAlreadyDisabledPhrase } from "../phrases"; From b73a4924b3ba89f99cafe63a048f55d8b6ebd7e1 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:26:32 +0000 Subject: [PATCH 12/26] Updated src_modules/voice_commands/commands/Enable --- src_modules/voice_commands/commands/EnableAutoJoinCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts index 432c0a1..cd680db 100644 --- a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts +++ b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts @@ -1,4 +1,4 @@ -import { Command, IExecutionContext } from "../../../framework"; +import { Command, IExecutionContext } from "../../.."; import VoiceCommandsModule from ".."; import { autoJoinEnabledPhrase, autoJoinAlreadyEnabledPhrase } from "../phrases"; From f1fd0ede9cbb569186bd435fd872d64a2aebc67e Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:26:38 +0000 Subject: [PATCH 13/26] Updated src_modules/voice_commands/commands/Enable --- src_modules/voice_commands/commands/EnableCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_modules/voice_commands/commands/EnableCommand.ts b/src_modules/voice_commands/commands/EnableCommand.ts index a40dcdb..ee82655 100644 --- a/src_modules/voice_commands/commands/EnableCommand.ts +++ b/src_modules/voice_commands/commands/EnableCommand.ts @@ -1,4 +1,4 @@ -import { Command, IExecutionContext } from "extcord"; +import { Command, IExecutionContext } from "../../.."; import VoiceCommandsModule from ".."; import { voiceCommandsEnabledErrorPhrase, voiceCommandsEnabledPhrase } from "../phrases"; From 8a86de51d26cff525fbffda2c9fc3f4e0d222c13 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:26:42 +0000 Subject: [PATCH 14/26] Updated src_modules/voice_commands/phrases.ts --- src_modules/voice_commands/phrases.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts index 0fc6f67..edb6b25 100644 --- a/src_modules/voice_commands/phrases.ts +++ b/src_modules/voice_commands/phrases.ts @@ -1,4 +1,4 @@ -import { MessagePhrase } from "extcord"; +import { MessagePhrase } from "../.."; export const voiceCommandsEnabledPhrase = new MessagePhrase({ name: "voiceCommandsEnabled", From f12376a139795438d91b3371ebbeace78b9e057b Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:41:46 +0000 Subject: [PATCH 15/26] Updated src_modules/voice_commands/phrases.ts --- src_modules/voice_commands/phrases.ts | 64 ++++++++++++++++++++------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts index edb6b25..d889870 100644 --- a/src_modules/voice_commands/phrases.ts +++ b/src_modules/voice_commands/phrases.ts @@ -1,21 +1,53 @@ import { MessagePhrase } from "../.."; -export const voiceCommandsEnabledPhrase = new MessagePhrase({ - name: "voiceCommandsEnabled", - message: "Voice commands enabled.", -}); +export const voiceCommandsEnabledPhrase = new MessagePhrase( + { + description: "Shown when voice commands are enabled", + name: "voiceCommandsEnabled", + }, + "Voice commands enabled.", + { + timestamp: false, + title: "Voice commands enabled." + }, + {}, +); -export const voiceCommandsDisabledPhrase = new MessagePhrase({ - name: "voiceCommandsDisabled", - message: "Voice commands disabled.", -}); +export const voiceCommandsDisabledPhrase = new MessagePhrase( + { + description: "Shown when voice commands are disabled", + name: "voiceCommandsDisabled", + }, + "Voice commands disabled.", + { + timestamp: false, + title: "Voice commands disabled." + }, + {}, +); -export const autoJoinEnabledPhrase = new MessagePhrase({ - name: "autoJoinEnabled", - message: "Automatic joining enabled.", -}); +export const autoJoinEnabledPhrase = new MessagePhrase( + { + description: "Shown when automatic joining is enabled", + name: "autoJoinEnabled", + }, + "Automatic joining enabled.", + { + timestamp: false, + title: "Automatic joining enabled." + }, + {}, +); -export const autoJoinDisabledPhrase = new MessagePhrase({ - name: "autoJoinDisabled", - message: "Automatic joining disabled.", -}); +export const autoJoinDisabledPhrase = new MessagePhrase( + { + description: "Shown when automatic joining is disabled", + name: "autoJoinDisabled", + }, + "Automatic joining disabled.", + { + timestamp: false, + title: "Automatic joining disabled." + }, + {}, +); From ab11a50c2990853da1d030cacc0f6abd78415be1 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 13:59:05 +0000 Subject: [PATCH 16/26] Updated src_modules/voice_commands/index.ts --- src_modules/voice_commands/index.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index 7199fe5..5f09e45 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -108,15 +108,21 @@ export default class VoiceCommandsModule extends Module { this.phoneticCache = new PhoneticCache(this, bot); this.speechCache = new SpeechCache(this, bot); - this.registerCommandGroup({ - name: "voice-commands", - description: "Commands for managing voice commands and automatic joining", - }); - - this.registerCommand("voice-commands", new EnableCommand(this)); - this.registerCommand("voice-commands", new DisableCommand(this)); - this.registerCommand("voice-commands", new EnableAutoJoinCommand(this)); - this.registerCommand("voice-commands", new DisableAutoJoinCommand(this)); + this.voiceCommandsGroup = new CommandGroup( + { + allowedPrivileges: ["everyone"], + author: "extcord", + description: "Commands for managing voice commands and automatic joining", + name: "voice-commands", + }, + ); + this.voiceCommandsGroup.addSubcommands( + new EnableCommand(this), + new DisableCommand(this), + new EnableAutoJoinCommand(this), + new DisableAutoJoinCommand(this), + ); + this.registerCommand(this.voiceCommandsGroup); } public async getListener(guild: Guild): Promise { From 26b528a90ad5f593acca1e461f7c7410fa8af1d6 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:02:51 +0000 Subject: [PATCH 17/26] Updated src_modules/voice_commands/index.ts --- src_modules/voice_commands/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index 5f09e45..14c56a0 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -4,7 +4,7 @@ import { GatewayIntentBits, Guild, VoiceState, VoiceChannel } from "discord.js"; import { VoiceConnection } from "@discordjs/voice"; -import { BooleanGuildConfigEntry, Bot, Logger, Module, SimplePhrase, StringConfigEntry, NumberConfigEntry } from "../.."; +import { BooleanGuildConfigEntry, Bot, CommandGroup, Logger, Module, SimplePhrase, StringConfigEntry, NumberConfigEntry } from "../.."; import { keywordPhrase, voiceCommandsEnabledPhrase, voiceCommandsDisabledPhrase, autoJoinEnabledPhrase, autoJoinDisabledPhrase } from "./phrases"; import { GuildListener } from "./GuildListener"; @@ -28,6 +28,7 @@ export default class VoiceCommandsModule extends Module { public voiceCommandsEnabledConfigEntry: BooleanGuildConfigEntry; public client: VoiceBackendClient; public voiceCommands: VoiceCommands; + public voiceCommandsGroup: CommandGroup; public phoneticCache: PhoneticCache; public speechCache: SpeechCache; @@ -122,6 +123,12 @@ export default class VoiceCommandsModule extends Module { new EnableAutoJoinCommand(this), new DisableAutoJoinCommand(this), ); + this.voiceCommandsGroup.addPhrases( + voiceCommandsEnabledPhrase, + voiceCommandsDisabledPhrase, + autoJoinEnabledPhrase, + autoJoinDisabledPhrase + ); this.registerCommand(this.voiceCommandsGroup); } From 86317d6fd6b96edbd49a55607291cf3a208fe117 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:09:28 +0000 Subject: [PATCH 18/26] Updated src_modules/voice_commands/phrases.ts --- src_modules/voice_commands/phrases.ts | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts index d889870..9ac28af 100644 --- a/src_modules/voice_commands/phrases.ts +++ b/src_modules/voice_commands/phrases.ts @@ -51,3 +51,55 @@ export const autoJoinDisabledPhrase = new MessagePhrase( }, {}, ); + +export const autoJoinAlreadyDisabledPhrase = new MessagePhrase( + { + description: "Shown when automatic joining is already disabled", + name: "autoJoinAlreadyDisabled", + }, + "Automatic joining is already disabled.", + { + timestamp: false, + title: "Automatic joining already disabled." + }, + {}, +); + +export const voiceCommandsAlreadyDisabledPhrase = new MessagePhrase( + { + description: "Shown when voice commands are already disabled", + name: "voiceCommandsAlreadyDisabled", + }, + "Voice commands are already disabled.", + { + timestamp: false, + title: "Voice commands already disabled." + }, + {}, +); + +export const autoJoinAlreadyEnabledPhrase = new MessagePhrase( + { + description: "Shown when automatic joining is already enabled", + name: "autoJoinAlreadyEnabled", + }, + "Automatic joining is already enabled.", + { + timestamp: false, + title: "Automatic joining already enabled." + }, + {}, +); + +export const voiceCommandsAlreadyEnabledPhrase = new MessagePhrase( + { + description: "Shown when voice commands are already enabled", + name: "voiceCommandsAlreadyEnabled", + }, + "Voice commands are already enabled.", + { + timestamp: false, + title: "Voice commands already enabled." + }, + {}, +); From bd3722ac98abb79641189a8341caefe6806b1aa5 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:09:34 +0000 Subject: [PATCH 19/26] Updated src_modules/voice_commands/commands/Enable --- src_modules/voice_commands/commands/EnableCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_modules/voice_commands/commands/EnableCommand.ts b/src_modules/voice_commands/commands/EnableCommand.ts index ee82655..98b80f2 100644 --- a/src_modules/voice_commands/commands/EnableCommand.ts +++ b/src_modules/voice_commands/commands/EnableCommand.ts @@ -24,7 +24,7 @@ export class EnableCommand extends Command<[]> { const guild = context.guild.guild; if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { - return context.respond(voiceCommandsEnabledErrorPhrase, {}); + return context.respond(voiceCommandsAlreadyEnabledPhrase, {}); } await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, true); From 7bea65eb49fe05a7f930d1121fb7668cc15371e7 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:09:46 +0000 Subject: [PATCH 20/26] Updated src_modules/voice_commands/index.ts --- src_modules/voice_commands/index.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index 14c56a0..a75fac2 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -92,14 +92,19 @@ export default class VoiceCommandsModule extends Module { this.registerConfigEntry(this.tokenConfigEntry); this.voiceCommandsEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "voiceCommandsEnabled", - }, bot.database, true); - this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); + name: "voiceCommandsEnabled", + }, bot.database, true); + this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); + + this.autoJoinConfigEntry = new BooleanGuildConfigEntry({ + name: "autoJoin", + }, bot.database, false); + this.registerConfigEntry(this.autoJoinConfigEntry); - this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "autoJoinEnabled", - }, bot.database, false); - this.registerConfigEntry(this.autoJoinEnabledConfigEntry); + this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ + name: "autoJoinEnabled", + }, bot.database, false); + this.registerConfigEntry(this.autoJoinEnabledConfigEntry); bot.intents.push(GatewayIntentBits.GuildVoiceStates); From 38427e3803502b021c66ecd4c7c76db1ab93aac2 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:16:58 +0000 Subject: [PATCH 21/26] Updated src_modules/voice_commands/index.ts --- src_modules/voice_commands/index.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index a75fac2..d815ecd 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -26,6 +26,7 @@ export default class VoiceCommandsModule extends Module { public maxQueuedAsrCountConfigEntry: NumberConfigEntry; public tokenConfigEntry: StringConfigEntry; public voiceCommandsEnabledConfigEntry: BooleanGuildConfigEntry; + public autoJoinEnabledConfigEntry: BooleanGuildConfigEntry; public client: VoiceBackendClient; public voiceCommands: VoiceCommands; public voiceCommandsGroup: CommandGroup; @@ -92,19 +93,14 @@ export default class VoiceCommandsModule extends Module { this.registerConfigEntry(this.tokenConfigEntry); this.voiceCommandsEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "voiceCommandsEnabled", - }, bot.database, true); - this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); + name: "voiceCommandsEnabled", + }, bot.database, true); + this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); - this.autoJoinConfigEntry = new BooleanGuildConfigEntry({ - name: "autoJoin", - }, bot.database, false); - this.registerConfigEntry(this.autoJoinConfigEntry); - - this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "autoJoinEnabled", - }, bot.database, false); - this.registerConfigEntry(this.autoJoinEnabledConfigEntry); + this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ + name: "autoJoinEnabled", + }, bot.database, false); + this.registerConfigEntry(this.autoJoinEnabledConfigEntry); bot.intents.push(GatewayIntentBits.GuildVoiceStates); From 96cdc096f35a9305d931c8e40916b5c19c920b18 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:26:11 +0000 Subject: [PATCH 22/26] Updated src_modules/voice_commands/commands/Disabl --- src_modules/voice_commands/commands/DisableAutoJoinCommand.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts index d2432fa..a966811 100644 --- a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts +++ b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts @@ -21,8 +21,8 @@ export class DisableAutoJoinCommand extends Command<[]> { } public async execute(context: IExecutionContext<[]>) { - const guild = context.guild.guild; - + const guild = context.guild; + if (await this.voiceCommandsModule.autoJoinConfigEntry.guildGet(guild)) { await this.voiceCommandsModule.autoJoinConfigEntry.guildSet(guild, false); return context.respond(autoJoinDisabledPhrase, {}); From 127ed6b6338c7f869650ae25be12058beb6792a8 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:26:23 +0000 Subject: [PATCH 23/26] Updated src_modules/voice_commands/commands/Disabl --- src_modules/voice_commands/commands/DisableCommand.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src_modules/voice_commands/commands/DisableCommand.ts b/src_modules/voice_commands/commands/DisableCommand.ts index 02c3895..f25cf62 100644 --- a/src_modules/voice_commands/commands/DisableCommand.ts +++ b/src_modules/voice_commands/commands/DisableCommand.ts @@ -21,8 +21,8 @@ export class DisableCommand extends Command<[]> { } public async execute(context: IExecutionContext<[]>) { - const guild = context.guild.guild; - + const guild = context.guild; + if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, false); return context.respond(voiceCommandsDisabledPhrase, {}); From 8ce929444898ac50fda0bd81b0edf43df286861f Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:26:36 +0000 Subject: [PATCH 24/26] Updated src_modules/voice_commands/commands/Enable --- .../voice_commands/commands/EnableAutoJoinCommand.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts index cd680db..8c6af03 100644 --- a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts +++ b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts @@ -21,12 +21,12 @@ export class EnableAutoJoinCommand extends Command<[]> { } public async execute(context: IExecutionContext<[]>) { - const guild = context.guild.guild; - + const guild = context.guild; + if (await this.voiceCommandsModule.autoJoinConfigEntry.guildGet(guild)) { return context.respond(autoJoinAlreadyEnabledPhrase, {}); } - + await this.voiceCommandsModule.autoJoinConfigEntry.guildSet(guild, true); return context.respond(autoJoinEnabledPhrase, {}); } From 1d1fd3d5c817812d41679a30ceee780ffe90952a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:26:49 +0000 Subject: [PATCH 25/26] Updated src_modules/voice_commands/commands/Enable --- src_modules/voice_commands/commands/EnableCommand.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src_modules/voice_commands/commands/EnableCommand.ts b/src_modules/voice_commands/commands/EnableCommand.ts index 98b80f2..edd6964 100644 --- a/src_modules/voice_commands/commands/EnableCommand.ts +++ b/src_modules/voice_commands/commands/EnableCommand.ts @@ -21,12 +21,12 @@ export class EnableCommand extends Command<[]> { } public async execute(context: IExecutionContext<[]>) { - const guild = context.guild.guild; - + const guild = context.guild; + if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { return context.respond(voiceCommandsAlreadyEnabledPhrase, {}); } - + await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, true); return context.respond(voiceCommandsEnabledPhrase, {}); } From 2f197687ff6a723823994936dfa6dfa3c208e755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lassi=20S=C3=A4ike?= Date: Sat, 2 Sep 2023 18:04:49 +0300 Subject: [PATCH 26/26] Fix implementation --- .../commands/DisableAutoJoinCommand.ts | 8 +- .../voice_commands/commands/DisableCommand.ts | 6 +- .../commands/EnableAutoJoinCommand.ts | 10 +-- .../voice_commands/commands/EnableCommand.ts | 16 ++-- src_modules/voice_commands/index.ts | 84 +++++++++++-------- src_modules/voice_commands/phrases.ts | 13 +++ 6 files changed, 84 insertions(+), 53 deletions(-) diff --git a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts index a966811..7fa0088 100644 --- a/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts +++ b/src_modules/voice_commands/commands/DisableAutoJoinCommand.ts @@ -8,7 +8,7 @@ export class DisableAutoJoinCommand extends Command<[]> { public constructor(voiceCommandsModule: VoiceCommandsModule) { super( { - allowedPrivileges: ["everyone"], + allowedPrivileges: ["admin"], author: "extcord", description: "Disable automatic joining", globalAliases: ["disableautojoin"], @@ -22,9 +22,9 @@ export class DisableAutoJoinCommand extends Command<[]> { public async execute(context: IExecutionContext<[]>) { const guild = context.guild; - - if (await this.voiceCommandsModule.autoJoinConfigEntry.guildGet(guild)) { - await this.voiceCommandsModule.autoJoinConfigEntry.guildSet(guild, false); + + if (await this.voiceCommandsModule.autoJoinEnabledConfigEntry.guildGet(guild)) { + await this.voiceCommandsModule.autoJoinEnabledConfigEntry.guildSet(guild, false); return context.respond(autoJoinDisabledPhrase, {}); } else { return context.respond(autoJoinAlreadyDisabledPhrase, {}); diff --git a/src_modules/voice_commands/commands/DisableCommand.ts b/src_modules/voice_commands/commands/DisableCommand.ts index f25cf62..e6f9f30 100644 --- a/src_modules/voice_commands/commands/DisableCommand.ts +++ b/src_modules/voice_commands/commands/DisableCommand.ts @@ -8,10 +8,10 @@ export class DisableCommand extends Command<[]> { public constructor(voiceCommandsModule: VoiceCommandsModule) { super( { - allowedPrivileges: ["everyone"], + allowedPrivileges: ["admin"], author: "extcord", description: "Disable voice commands", - globalAliases: ["disable"], + globalAliases: [], name: "disable", }, [], @@ -22,7 +22,7 @@ export class DisableCommand extends Command<[]> { public async execute(context: IExecutionContext<[]>) { const guild = context.guild; - + if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, false); return context.respond(voiceCommandsDisabledPhrase, {}); diff --git a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts index 8c6af03..2c9125f 100644 --- a/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts +++ b/src_modules/voice_commands/commands/EnableAutoJoinCommand.ts @@ -8,7 +8,7 @@ export class EnableAutoJoinCommand extends Command<[]> { public constructor(voiceCommandsModule: VoiceCommandsModule) { super( { - allowedPrivileges: ["everyone"], + allowedPrivileges: ["admin"], author: "extcord", description: "Enable automatic joining", globalAliases: ["enableautojoin"], @@ -22,12 +22,12 @@ export class EnableAutoJoinCommand extends Command<[]> { public async execute(context: IExecutionContext<[]>) { const guild = context.guild; - - if (await this.voiceCommandsModule.autoJoinConfigEntry.guildGet(guild)) { + + if (await this.voiceCommandsModule.autoJoinEnabledConfigEntry.guildGet(guild)) { return context.respond(autoJoinAlreadyEnabledPhrase, {}); } - - await this.voiceCommandsModule.autoJoinConfigEntry.guildSet(guild, true); + + await this.voiceCommandsModule.autoJoinEnabledConfigEntry.guildSet(guild, true); return context.respond(autoJoinEnabledPhrase, {}); } } diff --git a/src_modules/voice_commands/commands/EnableCommand.ts b/src_modules/voice_commands/commands/EnableCommand.ts index edd6964..906dbde 100644 --- a/src_modules/voice_commands/commands/EnableCommand.ts +++ b/src_modules/voice_commands/commands/EnableCommand.ts @@ -1,6 +1,6 @@ import { Command, IExecutionContext } from "../../.."; import VoiceCommandsModule from ".."; -import { voiceCommandsEnabledErrorPhrase, voiceCommandsEnabledPhrase } from "../phrases"; +import { voiceCommandsAlreadyEnabledPhrase, voiceCommandsEnabledPhrase, voiceCommandsNotSupportedPhrase } from "../phrases"; export class EnableCommand extends Command<[]> { private voiceCommandsModule: VoiceCommandsModule; @@ -8,10 +8,10 @@ export class EnableCommand extends Command<[]> { public constructor(voiceCommandsModule: VoiceCommandsModule) { super( { - allowedPrivileges: ["everyone"], + allowedPrivileges: ["admin"], author: "extcord", description: "Enable voice commands", - globalAliases: ["enable"], + globalAliases: [], name: "enable", }, [], @@ -22,11 +22,17 @@ export class EnableCommand extends Command<[]> { public async execute(context: IExecutionContext<[]>) { const guild = context.guild; - + if (await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildGet(guild)) { return context.respond(voiceCommandsAlreadyEnabledPhrase, {}); } - + + const backendLanguage = this.voiceCommandsModule.backendLanguageIdPhrase.get(context.language); + + if (backendLanguage === undefined || backendLanguage === "") { + return context.respond(voiceCommandsNotSupportedPhrase, {});; + } + await this.voiceCommandsModule.voiceCommandsEnabledConfigEntry.guildSet(guild, true); return context.respond(voiceCommandsEnabledPhrase, {}); } diff --git a/src_modules/voice_commands/index.ts b/src_modules/voice_commands/index.ts index d815ecd..3126a8e 100644 --- a/src_modules/voice_commands/index.ts +++ b/src_modules/voice_commands/index.ts @@ -5,13 +5,17 @@ import { GatewayIntentBits, Guild, VoiceState, VoiceChannel } from "discord.js"; import { VoiceConnection } from "@discordjs/voice"; import { BooleanGuildConfigEntry, Bot, CommandGroup, Logger, Module, SimplePhrase, StringConfigEntry, NumberConfigEntry } from "../.."; -import { keywordPhrase, voiceCommandsEnabledPhrase, voiceCommandsDisabledPhrase, autoJoinEnabledPhrase, autoJoinDisabledPhrase } from "./phrases"; +import { voiceCommandsEnabledPhrase, voiceCommandsDisabledPhrase, autoJoinEnabledPhrase, autoJoinDisabledPhrase, voiceCommandsAlreadyDisabledPhrase, voiceCommandsAlreadyEnabledPhrase, autoJoinAlreadyDisabledPhrase, autoJoinAlreadyEnabledPhrase, voiceCommandsNotSupportedPhrase } from "./phrases"; import { GuildListener } from "./GuildListener"; import { VoiceBackendClient } from "./VoiceBackendClient"; import { PhoneticCache } from "./PhoneticCache"; import { SpeechCache } from "./SpeechCache"; import { VoiceCommands } from "./VoiceCommands"; +import { DisableCommand } from "./commands/DisableCommand"; +import { EnableCommand } from "./commands/EnableCommand"; +import { EnableAutoJoinCommand } from "./commands/EnableAutoJoinCommand"; +import { DisableAutoJoinCommand } from "./commands/DisableAutoJoinCommand"; export default class VoiceCommandsModule extends Module { private listeners: Map; @@ -45,7 +49,10 @@ export default class VoiceCommandsModule extends Module { options.selfDeaf = false; }); - // Removed phrases + this.keywordPhrase = new SimplePhrase({ + name: "keyword", + }, "bot"); + this.registerPhrase(this.keywordPhrase); this.backendLanguageIdPhrase = new SimplePhrase({ name: "backendLanguageId", @@ -93,23 +100,22 @@ export default class VoiceCommandsModule extends Module { this.registerConfigEntry(this.tokenConfigEntry); this.voiceCommandsEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "voiceCommandsEnabled", - }, bot.database, true); - this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); - - this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ - name: "autoJoinEnabled", - }, bot.database, false); - this.registerConfigEntry(this.autoJoinEnabledConfigEntry); + name: "voiceCommandsEnabled", + }, bot.database, true); + this.registerConfigEntry(this.voiceCommandsEnabledConfigEntry); + this.autoJoinEnabledConfigEntry = new BooleanGuildConfigEntry({ + name: "autoJoinEnabled", + }, bot.database, false); + this.registerConfigEntry(this.autoJoinEnabledConfigEntry); bot.intents.push(GatewayIntentBits.GuildVoiceStates); this.client = new VoiceBackendClient(this); this.voiceCommands = new VoiceCommands(this, bot); - this.phoneticCache = new PhoneticCache(this, bot); - this.speechCache = new SpeechCache(this, bot); - + this.phoneticCache = new PhoneticCache(this, bot); + this.speechCache = new SpeechCache(this, bot); + this.voiceCommandsGroup = new CommandGroup( { allowedPrivileges: ["everyone"], @@ -128,7 +134,12 @@ export default class VoiceCommandsModule extends Module { voiceCommandsEnabledPhrase, voiceCommandsDisabledPhrase, autoJoinEnabledPhrase, - autoJoinDisabledPhrase + autoJoinDisabledPhrase, + voiceCommandsAlreadyDisabledPhrase, + voiceCommandsAlreadyEnabledPhrase, + autoJoinAlreadyDisabledPhrase, + autoJoinAlreadyEnabledPhrase, + voiceCommandsNotSupportedPhrase, ); this.registerCommand(this.voiceCommandsGroup); } @@ -168,28 +179,29 @@ export default class VoiceCommandsModule extends Module { private async onVoiceStateUpdate(oldState: VoiceState, newState: VoiceState) { if (oldState.channel === null && newState.channel !== null && newState.channel instanceof VoiceChannel && !newState.member?.user.bot) { - const channel = newState.channel; - - const extendedGuild = { - entity: guildEntity, - guild: guild, - }; - - const autoJoinEnabled = await this.autoJoinEnabledConfigEntry.guildGet(extendedGuild); - - if (!autoJoinEnabled) { - return; - } - - // Someone joined a voice channel - const nonBotUsers = channel.members.filter(member => !member.user.bot); - if (nonBotUsers.size > 0 && this.bot.voice.getConnection(channel.guild) === undefined) { - setTimeout(async () => { - const nonBotUsers = channel.members.filter(member => !member.user.bot); - if (nonBotUsers.size > 0 && this.bot.voice.getConnection(channel.guild) === undefined) { - await this.getConnection(this.bot, channel); - } - }, 5000); + const channel = newState.channel; + + this.bot.database.ensureConnection(); + + const guildEntity = await this.bot.database.repos.guild.getEntity(newState.guild); + + const extendedGuild = { + entity: guildEntity, + guild: newState.guild, + }; + + const autoJoinEnabled = await this.autoJoinEnabledConfigEntry.guildGet(extendedGuild); + + if (autoJoinEnabled) { + const nonBotUsers = channel.members.filter(member => !member.user.bot); + if (nonBotUsers.size > 0 && this.bot.voice.getConnection(channel.guild) === undefined) { + setTimeout(async () => { + const nonBotUsers = channel.members.filter(member => !member.user.bot); + if (nonBotUsers.size > 0 && this.bot.voice.getConnection(channel.guild) === undefined) { + await this.getConnection(this.bot, channel); + } + }, 5000); + } } } diff --git a/src_modules/voice_commands/phrases.ts b/src_modules/voice_commands/phrases.ts index 9ac28af..fa1bd4d 100644 --- a/src_modules/voice_commands/phrases.ts +++ b/src_modules/voice_commands/phrases.ts @@ -103,3 +103,16 @@ export const voiceCommandsAlreadyEnabledPhrase = new MessagePhrase( }, {}, ); + +export const voiceCommandsNotSupportedPhrase = new MessagePhrase( + { + description: "Shown when voice commands are not supported with the language", + name: "voiceCommandsNotSupported", + }, + "Voice commands are not supported with this language.", + { + timestamp: false, + title: "Voice commands are not supported with this language." + }, + {}, +);