diff options
| author | Fuwn <[email protected]> | 2025-09-28 00:03:12 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-28 00:03:12 -0700 |
| commit | 999ba817c68e3dd2b578b27f5f0f527d04be87c7 (patch) | |
| tree | d84ebf1830fb7b35c04129995512ebda4aed4e74 /packages/gateway/src/commands | |
| parent | feat(listeners:roleMentionCooldown): Remove expected behaviour logs (diff) | |
| download | umabotdiscord-999ba817c68e3dd2b578b27f5f0f527d04be87c7.tar.xz umabotdiscord-999ba817c68e3dd2b578b27f5f0f527d04be87c7.zip | |
refactor(gateway): Consolidate event handlers
Diffstat (limited to 'packages/gateway/src/commands')
| -rw-r--r-- | packages/gateway/src/commands/commandHandler.ts | 18 | ||||
| -rw-r--r-- | packages/gateway/src/commands/crp.ts | 8 | ||||
| -rw-r--r-- | packages/gateway/src/commands/index.ts | 10 | ||||
| -rw-r--r-- | packages/gateway/src/commands/react.ts | 6 | ||||
| -rw-r--r-- | packages/gateway/src/commands/say.ts | 12 | ||||
| -rw-r--r-- | packages/gateway/src/commands/start.ts | 12 |
6 files changed, 35 insertions, 31 deletions
diff --git a/packages/gateway/src/commands/commandHandler.ts b/packages/gateway/src/commands/commandHandler.ts new file mode 100644 index 0000000..5d8b77a --- /dev/null +++ b/packages/gateway/src/commands/commandHandler.ts @@ -0,0 +1,18 @@ +import { Client, Events, Message } from "discord.js"; +import { handleSayCommand } from "./say"; +import { handleStartCommand } from "./start"; +import { handleCrpCommand } from "./crp"; +import { handleReactCommand } from "./react"; + +export const handleCommandHandler = (client: Client) => { + client.on(Events.MessageCreate, async (message: Message) => { + if (message.author.bot) return; + + await Promise.allSettled([ + handleSayCommand(message), + handleStartCommand(message), + handleCrpCommand(message), + handleReactCommand(message), + ]); + }); +}; diff --git a/packages/gateway/src/commands/crp.ts b/packages/gateway/src/commands/crp.ts index 9f7c509..8503cb3 100644 --- a/packages/gateway/src/commands/crp.ts +++ b/packages/gateway/src/commands/crp.ts @@ -1,11 +1,10 @@ -import { Client, Events, Message, Role } from "discord.js"; +import { Message, Role } from "discord.js"; -export const handleCrpCommand = (client: Client) => { - client.on(Events.MessageCreate, async (message: Message) => { +export const handleCrpCommand = async (message: Message) => { if (message.author.bot) return; if (message.content.toLowerCase().startsWith("uma!crp")) { - const application = await client.application?.fetch(); + const application = await message.client.application?.fetch(); const ownerId = application?.owner?.id; if (message.author.id !== ownerId) { @@ -95,5 +94,4 @@ export const handleCrpCommand = (client: Client) => { ); } } - }); }; diff --git a/packages/gateway/src/commands/index.ts b/packages/gateway/src/commands/index.ts index b3dd2a2..87b37f9 100644 --- a/packages/gateway/src/commands/index.ts +++ b/packages/gateway/src/commands/index.ts @@ -1,12 +1,6 @@ import { Client } from "discord.js"; -import { handleSayCommand } from "./say"; -import { handleStartCommand } from "./start"; -import { handleCrpCommand } from "./crp"; -import { handleReactCommand } from "./react"; +import { handleCommandHandler } from "./commandHandler"; export const handleCommands = (client: Client) => { - handleSayCommand(client); - handleStartCommand(client); - handleCrpCommand(client); - handleReactCommand(client); + handleCommandHandler(client); }; diff --git a/packages/gateway/src/commands/react.ts b/packages/gateway/src/commands/react.ts index ef18d8f..639dec6 100644 --- a/packages/gateway/src/commands/react.ts +++ b/packages/gateway/src/commands/react.ts @@ -1,7 +1,6 @@ -import { Client, Events, Message } from "discord.js"; +import { Message } from "discord.js"; -export const handleReactCommand = (client: Client) => { - client.on(Events.MessageCreate, async (message: Message) => { +export const handleReactCommand = async (message: Message) => { if (message.author.bot) return; if (!message.content.startsWith("uma!react")) return; @@ -35,5 +34,4 @@ export const handleReactCommand = (client: Client) => { await message.reply("Failed to react to the message."); } - }); }; diff --git a/packages/gateway/src/commands/say.ts b/packages/gateway/src/commands/say.ts index 4696574..31afb04 100644 --- a/packages/gateway/src/commands/say.ts +++ b/packages/gateway/src/commands/say.ts @@ -1,12 +1,11 @@ -import { Client, Events, Message } from "discord.js"; +import { Message } from "discord.js"; import { GUILD_ID } from "../constants"; -export const handleSayCommand = (client: Client) => { - client.on(Events.MessageCreate, async (message: Message) => { +export const handleSayCommand = async (message: Message) => { if (message.author.bot) return; if (message.content.toLowerCase().startsWith("uma!say")) { - const application = await client.application?.fetch(); + const application = await message.client.application?.fetch(); const ownerId = application?.owner?.id; if (message.author.id !== ownerId) return; @@ -29,7 +28,7 @@ export const handleSayCommand = (client: Client) => { if (messageIdMatch) { try { - const guild = client.guilds.cache.get(GUILD_ID); + const guild = message.client.guilds.cache.get(GUILD_ID); if (!guild) { await message.reply("❌ Guild not found."); @@ -79,7 +78,7 @@ export const handleSayCommand = (client: Client) => { const channelId = channelMatch[1]; - targetChannel = client.channels.cache.get(channelId); + targetChannel = message.client.channels.cache.get(channelId); if (!targetChannel || !targetChannel.isTextBased()) { await message.reply("❌ Channel not found or is not a text channel."); @@ -123,5 +122,4 @@ export const handleSayCommand = (client: Client) => { } } } - }); }; diff --git a/packages/gateway/src/commands/start.ts b/packages/gateway/src/commands/start.ts index 4a771ed..b6c9300 100644 --- a/packages/gateway/src/commands/start.ts +++ b/packages/gateway/src/commands/start.ts @@ -1,12 +1,11 @@ -import { Client, Events, Message } from "discord.js"; +import { Message } from "discord.js"; import { sendProgressUpdate, executeBulkRoleAssignment } from "./utilities"; -export const handleStartCommand = (client: Client) => { - client.on(Events.MessageCreate, async (message: Message) => { +export const handleStartCommand = async (message: Message) => { if (message.author.bot) return; if (message.content.toLowerCase().startsWith("uma!start")) { - const application = await client.application?.fetch(); + const application = await message.client.application?.fetch(); const ownerId = application?.owner?.id; if (message.author.id !== ownerId) return; @@ -65,7 +64,7 @@ export const handleStartCommand = (client: Client) => { ); executeBulkRoleAssignment( - client, + message.client, roleId, updateChannelId, channelId, @@ -73,11 +72,10 @@ export const handleStartCommand = (client: Client) => { ).catch((error) => { console.error("Bulk role assignment failed:", error); sendProgressUpdate( - client, + message.client, "❌ Bulk role assignment failed due to an error", updateChannelId, ); }); } - }); }; |