diff options
| author | Fuwn <[email protected]> | 2025-10-03 03:16:06 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-03 03:16:20 -0700 |
| commit | 3549aef7914dd69aea26e96dd2d22a851e43cb61 (patch) | |
| tree | 8a72b7288a39a5235055e9056fc2bc2dd1ec0d61 /packages | |
| parent | feat(gateway:listeners): Disable moderation agent (diff) | |
| download | umabotdiscord-3549aef7914dd69aea26e96dd2d22a851e43cb61.tar.xz umabotdiscord-3549aef7914dd69aea26e96dd2d22a851e43cb61.zip | |
refactor(gateway:clientReady): Organise clientReady submodules
Diffstat (limited to 'packages')
7 files changed, 159 insertions, 152 deletions
diff --git a/packages/gateway/src/listeners/clientReady/activity.ts b/packages/gateway/src/listeners/clientReady/activity.ts new file mode 100644 index 0000000..8abd50b --- /dev/null +++ b/packages/gateway/src/listeners/clientReady/activity.ts @@ -0,0 +1,5 @@ +import { Client } from "discord.js"; + +export const handleActivity = (client: Client) => { + client.user?.setActivity("r/okbuddyumamusume", { type: 3 }); +}; diff --git a/packages/gateway/src/listeners/clientReady/clientReady.ts b/packages/gateway/src/listeners/clientReady/clientReady.ts deleted file mode 100644 index 0a6ad26..0000000 --- a/packages/gateway/src/listeners/clientReady/clientReady.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { Client, Events } from "discord.js"; -import { ROLEPLAY_UMAGRAM_CHANNEL_ID } from "../constants"; - -export const handleClientReady = (client: Client) => { - client.once(Events.ClientReady, async (readyClient) => { - await readyClient.user.setActivity("r/okbuddyumamusume", { type: 3 }); - - try { - const channel = client.channels.cache.get(ROLEPLAY_UMAGRAM_CHANNEL_ID); - - if (channel && channel.isTextBased()) { - const processChannelMessages = async ( - targetChannel: any, - channelName: string, - ) => { - let lastMessageId: string | undefined; - let messageCount = 0; - let heartCount = 0; - - while (true) { - const messages = await targetChannel.messages.fetch({ - limit: 100, - before: lastMessageId, - }); - - if (messages.size === 0) break; - - for (const message of messages.values()) { - messageCount += 1; - - const existingReaction = message.reactions.cache.get("❤️"); - - if ( - existingReaction && - existingReaction.users.cache.has(client.user!.id) - ) - continue; - - try { - await message.react("❤️"); - - heartCount += 1; - - await new Promise((resolve) => setTimeout(resolve, 100)); - } catch (error) { - console.error( - `Failed to heart message ${message.id} in ${channelName}:`, - error, - ); - } - } - - lastMessageId = messages.last()?.id; - - await new Promise((resolve) => setTimeout(resolve, 500)); - } - - return { messageCount, heartCount }; - }; - - await processChannelMessages(channel, "Main Channel"); - - try { - const activeThreads = await (channel as any).threads?.fetchActive(); - const archivedThreads = await ( - channel as any - ).threads?.fetchArchived(); - const allThreads = [ - ...activeThreads.threads.values(), - ...archivedThreads.threads.values(), - ]; - - for (const thread of allThreads) { - try { - await processChannelMessages(thread, `Thread: ${thread.name}`); - } catch (error) { - console.error(`Error processing thread ${thread.name}:`, error); - } - } - } catch (error) { - console.error("Error fetching threads:", error); - } - } - } catch (error) { - console.error("Error adding hearts to existing messages:", error); - } - }); -}; diff --git a/packages/gateway/src/listeners/clientReady/index.ts b/packages/gateway/src/listeners/clientReady/index.ts new file mode 100644 index 0000000..8e7f81a --- /dev/null +++ b/packages/gateway/src/listeners/clientReady/index.ts @@ -0,0 +1,12 @@ +import { Client, Events } from "discord.js"; +import { handleVoiceConnection } from "./voiceConnection"; +import { handleActivity } from "./activity"; +import { handleUmagramCatchup } from "./umagramCatchup"; + +export const handleClientReady = (client: Client) => { + client.once(Events.ClientReady, async (readyClient) => { + handleVoiceConnection(readyClient); + handleActivity(readyClient); + await handleUmagramCatchup(readyClient); + }); +}; diff --git a/packages/gateway/src/listeners/clientReady/umagramCatchup.ts b/packages/gateway/src/listeners/clientReady/umagramCatchup.ts new file mode 100644 index 0000000..07ea08b --- /dev/null +++ b/packages/gateway/src/listeners/clientReady/umagramCatchup.ts @@ -0,0 +1,82 @@ +import { Client } from "discord.js"; +import { ROLEPLAY_UMAGRAM_CHANNEL_ID } from "../constants"; + +export const handleUmagramCatchup = async (client: Client) => { + try { + const channel = client.channels.cache.get(ROLEPLAY_UMAGRAM_CHANNEL_ID); + + if (channel && channel.isTextBased()) { + const processChannelMessages = async ( + targetChannel: any, + channelName: string, + ) => { + let lastMessageId: string | undefined; + let messageCount = 0; + let heartCount = 0; + + while (true) { + const messages = await targetChannel.messages.fetch({ + limit: 100, + before: lastMessageId, + }); + + if (messages.size === 0) break; + + for (const message of messages.values()) { + messageCount += 1; + + const existingReaction = message.reactions.cache.get("❤️"); + + if ( + existingReaction && + existingReaction.users.cache.has(client.user!.id) + ) + continue; + + try { + await message.react("❤️"); + + heartCount += 1; + + await new Promise((resolve) => setTimeout(resolve, 100)); + } catch (error) { + console.error( + `Failed to heart message ${message.id} in ${channelName}:`, + error, + ); + } + } + + lastMessageId = messages.last()?.id; + + await new Promise((resolve) => setTimeout(resolve, 500)); + } + + return { messageCount, heartCount }; + }; + + await processChannelMessages(channel, "Main Channel"); + + try { + const activeThreads = await (channel as any).threads?.fetchActive(); + const archivedThreads = await (channel as any).threads?.fetchArchived(); + const allThreads = [ + ...activeThreads.threads.values(), + ...archivedThreads.threads.values(), + ]; + + for (const thread of allThreads) { + try { + await processChannelMessages(thread, `Thread: ${thread.name}`); + } catch (error) { + console.error(`Error processing thread ${thread.name}:`, error); + } + } + } catch (error) { + console.error("Error fetching threads:", error); + } + } + } catch (error) { + console.error("Error adding hearts to existing messages:", error); + } +}; diff --git a/packages/gateway/src/listeners/clientReady/voiceConnection.ts b/packages/gateway/src/listeners/clientReady/voiceConnection.ts index 2de1f90..bdee625 100644 --- a/packages/gateway/src/listeners/clientReady/voiceConnection.ts +++ b/packages/gateway/src/listeners/clientReady/voiceConnection.ts @@ -1,4 +1,4 @@ -import { Client, Events } from "discord.js"; +import { Client } from "discord.js"; import { joinVoiceChannel, VoiceConnectionStatus, @@ -8,72 +8,70 @@ import { const VOICE_CHANNEL_ID = "1422049438863589487"; export const handleVoiceConnection = (client: Client) => { - client.once(Events.ClientReady, async () => { - const voiceChannel = client.channels.cache.get(VOICE_CHANNEL_ID); + const voiceChannel = client.channels.cache.get(VOICE_CHANNEL_ID); - if (!voiceChannel || !voiceChannel.isVoiceBased()) { - console.error( - `Voice channel ${VOICE_CHANNEL_ID} not found or is not a voice channel`, - ); + if (!voiceChannel || !voiceChannel.isVoiceBased()) { + console.error( + `Voice channel ${VOICE_CHANNEL_ID} not found or is not a voice channel`, + ); - return; - } + return; + } - try { - const connection = joinVoiceChannel({ - channelId: voiceChannel.id, - guildId: voiceChannel.guildId!, - adapterCreator: voiceChannel.guild.voiceAdapterCreator, - }); - const player = createAudioPlayer(); + try { + const connection = joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: voiceChannel.guildId!, + adapterCreator: voiceChannel.guild.voiceAdapterCreator, + }); + const player = createAudioPlayer(); - connection.subscribe(player); - connection.on("error", (error) => { - console.error("Voice connection error:", error); - setTimeout(() => { - handleVoiceConnection(client); - }, 15000); - }); - connection.on(VoiceConnectionStatus.Disconnected, () => { - setTimeout(() => { - try { - const newConnection = joinVoiceChannel({ - channelId: voiceChannel.id, - guildId: voiceChannel.guildId!, - adapterCreator: voiceChannel.guild.voiceAdapterCreator, - }); - const newPlayer = createAudioPlayer(); + connection.subscribe(player); + connection.on("error", (error) => { + console.error("Voice connection error:", error); + setTimeout(() => { + handleVoiceConnection(client); + }, 15000); + }); + connection.on(VoiceConnectionStatus.Disconnected, () => { + setTimeout(() => { + try { + const newConnection = joinVoiceChannel({ + channelId: voiceChannel.id, + guildId: voiceChannel.guildId!, + adapterCreator: voiceChannel.guild.voiceAdapterCreator, + }); + const newPlayer = createAudioPlayer(); - newConnection.subscribe(newPlayer); - newConnection.on("error", (error) => { - console.error("Voice reconnection error:", error); - setTimeout(() => { - handleVoiceConnection(client); - }, 15000); - }); - newConnection.on(VoiceConnectionStatus.Disconnected, () => { - setTimeout(() => { - handleVoiceConnection(client); - }, 5000); - }); - } catch (error) { - console.error("Failed to reconnect to voice channel:", error); + newConnection.subscribe(newPlayer); + newConnection.on("error", (error) => { + console.error("Voice reconnection error:", error); + setTimeout(() => { + handleVoiceConnection(client); + }, 15000); + }); + newConnection.on(VoiceConnectionStatus.Disconnected, () => { setTimeout(() => { handleVoiceConnection(client); - }, 10000); - } - }, 5000); - }); - connection.on(VoiceConnectionStatus.Destroyed, () => { - setTimeout(() => { - handleVoiceConnection(client); - }, 5000); - }); - } catch (error) { - console.error("Failed to connect to voice channel:", error); + }, 5000); + }); + } catch (error) { + console.error("Failed to reconnect to voice channel:", error); + setTimeout(() => { + handleVoiceConnection(client); + }, 10000); + } + }, 5000); + }); + connection.on(VoiceConnectionStatus.Destroyed, () => { setTimeout(() => { handleVoiceConnection(client); - }, 10000); - } - }); + }, 5000); + }); + } catch (error) { + console.error("Failed to connect to voice channel:", error); + setTimeout(() => { + handleVoiceConnection(client); + }, 10000); + } }; diff --git a/packages/gateway/src/listeners/index.ts b/packages/gateway/src/listeners/index.ts index b0ca723..6171402 100644 --- a/packages/gateway/src/listeners/index.ts +++ b/packages/gateway/src/listeners/index.ts @@ -4,12 +4,10 @@ import { handleRoleProtection } from "./roleProtection"; import { handleChannelDeletion } from "./channelDeletion"; import { handleMessageDeletion } from "./messageDeletion"; import { handleMessageEdit } from "./messageEdit"; -import { handleClientReady } from "./clientReady/clientReady"; -import { handleVoiceConnection } from "./clientReady/voiceConnection"; +import { handleClientReady } from "./clientReady"; import { handleMediaModeration } from "./mediaModeration"; export const handleListeners = (client: Client) => { - handleVoiceConnection(client); handleClientReady(client); handleMessageCreate(client); handleRoleProtection(client); diff --git a/packages/gateway/src/listeners/messageCreate/index.ts b/packages/gateway/src/listeners/messageCreate/index.ts index 1b484b5..8e30fc1 100644 --- a/packages/gateway/src/listeners/messageCreate/index.ts +++ b/packages/gateway/src/listeners/messageCreate/index.ts @@ -2,7 +2,7 @@ import { Client, Events, Message } from "discord.js"; import { handleIqdbModeration } from "./iqdbModeration"; import { handleRoleplayUmagram } from "./roleplayUmagram"; // import { handleArtMediaModeration } from "./artMediaModeration"; -import { handleAIModeration } from "./moderationAgent"; +// import { handleAIModeration } from "./moderationAgent"; import { handleAnnouncementReaction } from "./announcementReaction"; import { handleRoleMentionCooldown } from "./roleMentionCooldown"; import { handleAICommand } from "./aiCommandHandler"; |