diff --git a/src/cmd/registry/limbo.ts b/src/cmd/registry/limbo.ts new file mode 100644 index 0000000..354b691 --- /dev/null +++ b/src/cmd/registry/limbo.ts @@ -0,0 +1,39 @@ +import { ChannelType, type Message } from "discord.js"; +import type { Command } from "../../models"; +import RoleService from "../../services/role"; +import DataService from "../../services/data"; + +const LIMBO_CHANNEL_NAME = "limbo"; + +export default { + name: "limbo", + description: "Toggles on/off limbo mode. When limbo mode is on, new members will be placed in #limbo. When off, new members will be placed in #chat-and-shitpost.", + usage: ".limbo [on|off]", + execute: async (message: Message) => { + const ogState = RoleService.limboMode; + + if (message.content.includes("on")) + RoleService.limboMode = true; + else if (message.content.includes("off")) + RoleService.limboMode = false; + else + RoleService.limboMode = !RoleService.limboMode; + + // update system channel + if (RoleService.limboMode) { + if (!ogState) + DataService.data = { ...DataService.data, prevSystemChannelId: message.guild?.systemChannel?.id }; + const limboChannel = message.guild?.channels.cache.find((ch) => ch.name.toLowerCase() === LIMBO_CHANNEL_NAME); + if (limboChannel && limboChannel.type === ChannelType.GuildText) + await message.guild?.setSystemChannel(limboChannel); + } + else { + const prevSystemChannel = message.guild?.channels.cache.find((ch) => ch.id === DataService.data.prevSystemChannelId); + if (prevSystemChannel && prevSystemChannel.type === ChannelType.GuildText) + await message.guild?.setSystemChannel(prevSystemChannel); + } + + + await message.reply(`*${ogState}* -> **${RoleService.limboMode}**`); + } +} satisfies Command; diff --git a/src/cmd/registry/limbomode.ts b/src/cmd/registry/limbomode.ts deleted file mode 100644 index 65d0d62..0000000 --- a/src/cmd/registry/limbomode.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { Message } from "discord.js"; -import type { Command } from "../../models"; -import RoleService from "../../services/role"; - -export default { - name: "limbomode", - description: "Toggles on/off limbo mode. When limbo mode is on, new members will be placed in #limbo. When off, new members will be placed in #chat-and-shitpost.", - usage: ".limbomode [on|off]", - execute: async (message: Message) => { - const ogState = RoleService.limboMode; - - if (message.content.includes("on")) - RoleService.limboMode = true; - else if (message.content.includes("off")) - RoleService.limboMode = false; - else - RoleService.limboMode = !RoleService.limboMode; - - await message.reply(`*${ogState}* -> **${RoleService.limboMode}**`); - } -} satisfies Command; diff --git a/src/index.ts b/src/index.ts index 4b486de..eac1d06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ client.on("messageCreate", async (message) => { try { const command = CommandService.parse(message); - if (command) command.execute(message); + if (command) await command.execute(message); } catch (err) { console.error(err); diff --git a/src/services/data.ts b/src/services/data.ts index 18844da..2c63f0c 100644 --- a/src/services/data.ts +++ b/src/services/data.ts @@ -1,5 +1,6 @@ interface Data { - limboMode: boolean + limboMode: boolean, + prevSystemChannelId?: string } export default class DataService { @@ -7,7 +8,8 @@ export default class DataService { private static file: Bun.BunFile | undefined; private static _data: Data = { // default values (will be overwritten) - limboMode: false + limboMode: false, + prevSystemChannelId: undefined }; static async init() {