summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/gateway/src/commands/commandHandler.ts18
-rw-r--r--packages/gateway/src/commands/crp.ts8
-rw-r--r--packages/gateway/src/commands/index.ts10
-rw-r--r--packages/gateway/src/commands/react.ts6
-rw-r--r--packages/gateway/src/commands/say.ts12
-rw-r--r--packages/gateway/src/commands/start.ts12
-rw-r--r--packages/gateway/src/listeners/announcementReaction.ts8
-rw-r--r--packages/gateway/src/listeners/artMediaModeration.ts8
-rw-r--r--packages/gateway/src/listeners/index.ts14
-rw-r--r--packages/gateway/src/listeners/iqdbModeration.ts10
-rw-r--r--packages/gateway/src/listeners/messageCreate.ts20
-rw-r--r--packages/gateway/src/listeners/moderationAgent/index.ts8
-rw-r--r--packages/gateway/src/listeners/roleMentionCooldown.ts6
-rw-r--r--packages/gateway/src/listeners/roleplayUmagram.ts8
14 files changed, 75 insertions, 73 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,
);
});
}
- });
};
diff --git a/packages/gateway/src/listeners/announcementReaction.ts b/packages/gateway/src/listeners/announcementReaction.ts
index eba8f25..7a498b6 100644
--- a/packages/gateway/src/listeners/announcementReaction.ts
+++ b/packages/gateway/src/listeners/announcementReaction.ts
@@ -1,17 +1,15 @@
-import { Client, Events, Message } from "discord.js";
+import { Message } from "discord.js";
const ANNOUNCEMENT_CHANNEL_ID = "1406591215608270981";
-export const handleAnnouncementReaction = (client: Client) => {
- client.on(Events.MessageCreate, async (message: Message) => {
+export const handleAnnouncementReaction = async (message: Message) => {
if (message.channelId !== ANNOUNCEMENT_CHANNEL_ID) return;
- if (message.author.id === client.user?.id) return;
+ if (message.author.id === message.client.user?.id) return;
try {
await message.react("1406426721158303864");
} catch (error) {
console.error("Failed to add okbuddy reaction to announcement:", error);
}
- });
};
diff --git a/packages/gateway/src/listeners/artMediaModeration.ts b/packages/gateway/src/listeners/artMediaModeration.ts
index 21a820a..48fdc55 100644
--- a/packages/gateway/src/listeners/artMediaModeration.ts
+++ b/packages/gateway/src/listeners/artMediaModeration.ts
@@ -1,15 +1,14 @@
-import { Client, Events, Message } from "discord.js";
+import { Message } from "discord.js";
import {
ART_MEDIA_NSFW_CHANNEL_ID,
NSFW_DISCUSSION_CHANNEL_ID,
} from "./constants";
-export const handleArtMediaModeration = (client: Client) => {
- client.on(Events.MessageCreate, async (message: Message) => {
+export const handleArtMediaModeration = async (message: Message) => {
if (message.channelId !== ART_MEDIA_NSFW_CHANNEL_ID) return;
try {
- if (message.author.id === client.user?.id) return;
+ if (message.author.id === message.client.user?.id) return;
const hasMediaAttachments = message.attachments.some((attachment) => {
const contentType = attachment.contentType;
@@ -42,5 +41,4 @@ export const handleArtMediaModeration = (client: Client) => {
} catch (error) {
console.error("Error in art media moderation:", error);
}
- });
};
diff --git a/packages/gateway/src/listeners/index.ts b/packages/gateway/src/listeners/index.ts
index 846ac87..2637d2f 100644
--- a/packages/gateway/src/listeners/index.ts
+++ b/packages/gateway/src/listeners/index.ts
@@ -1,26 +1,16 @@
import { Client } from "discord.js";
-import { handleIqdbModeration } from "./iqdbModeration";
-import { handleRoleplayUmagram } from "./roleplayUmagram";
-import { handleArtMediaModeration } from "./artMediaModeration";
-import { handleAIModeration } from "./moderationAgent";
-import { handleAnnouncementReaction } from "./announcementReaction";
+import { handleMessageCreate } from "./messageCreate";
import { handleRoleProtection } from "./roleProtection";
import { handleChannelDeletion } from "./channelDeletion";
import { handleMessageDeletion } from "./messageDeletion";
import { handleMessageEdit } from "./messageEdit";
import { handleClientReady } from "./clientReady";
-import { handleRoleMentionCooldown } from "./roleMentionCooldown";
export const handleListeners = (client: Client) => {
handleClientReady(client);
- handleIqdbModeration(client);
- handleRoleplayUmagram(client);
- handleArtMediaModeration(client);
- handleAIModeration(client);
- handleAnnouncementReaction(client);
+ handleMessageCreate(client);
handleRoleProtection(client);
handleChannelDeletion(client);
handleMessageDeletion(client);
handleMessageEdit(client);
- handleRoleMentionCooldown(client);
};
diff --git a/packages/gateway/src/listeners/iqdbModeration.ts b/packages/gateway/src/listeners/iqdbModeration.ts
index c914227..2266497 100644
--- a/packages/gateway/src/listeners/iqdbModeration.ts
+++ b/packages/gateway/src/listeners/iqdbModeration.ts
@@ -1,4 +1,4 @@
-import { Client, Events, Message } from "discord.js";
+import { Message } from "discord.js";
import { sendAuditLog } from "../commands/utilities";
const IQDB_MODERATION_CHANNEL_IDS = [
@@ -6,8 +6,7 @@ const IQDB_MODERATION_CHANNEL_IDS = [
"1420297845998620733",
];
-export const handleIqdbModeration = (client: Client) => {
- client.on(Events.MessageCreate, async (message: Message) => {
+export const handleIqdbModeration = async (message: Message) => {
if (!IQDB_MODERATION_CHANNEL_IDS.includes(message.channelId)) return;
const imageAttachments = message.attachments.filter((attachment) =>
@@ -175,7 +174,7 @@ export const handleIqdbModeration = (client: Client) => {
try {
const channelId = "1406422619934167106";
- const channel = client.channels.cache.get(channelId);
+ const channel = message.client.channels.cache.get(channelId);
if (channel && "send" in channel) {
const imageResponse = await fetch(attachment.url);
@@ -194,7 +193,7 @@ export const handleIqdbModeration = (client: Client) => {
console.error("Error sending image attachment:", error);
await sendAuditLog(
- client,
+ message.client,
embed,
undefined,
"1406422619934167106",
@@ -222,5 +221,4 @@ export const handleIqdbModeration = (client: Client) => {
} catch (error) {
console.error("Error in iqdb moderation:", error);
}
- });
};
diff --git a/packages/gateway/src/listeners/messageCreate.ts b/packages/gateway/src/listeners/messageCreate.ts
new file mode 100644
index 0000000..72f4f2b
--- /dev/null
+++ b/packages/gateway/src/listeners/messageCreate.ts
@@ -0,0 +1,20 @@
+import { Client, Events, Message } from "discord.js";
+import { handleIqdbModeration } from "./iqdbModeration";
+import { handleRoleplayUmagram } from "./roleplayUmagram";
+import { handleArtMediaModeration } from "./artMediaModeration";
+import { handleAIModeration } from "./moderationAgent";
+import { handleAnnouncementReaction } from "./announcementReaction";
+import { handleRoleMentionCooldown } from "./roleMentionCooldown";
+
+export const handleMessageCreate = (client: Client) => {
+ client.on(Events.MessageCreate, async (message: Message) => {
+ await Promise.allSettled([
+ handleIqdbModeration(message),
+ handleRoleplayUmagram(message),
+ handleArtMediaModeration(message),
+ handleAIModeration(message),
+ handleAnnouncementReaction(message),
+ handleRoleMentionCooldown(message),
+ ]);
+ });
+};
diff --git a/packages/gateway/src/listeners/moderationAgent/index.ts b/packages/gateway/src/listeners/moderationAgent/index.ts
index 84528f7..7c7c170 100644
--- a/packages/gateway/src/listeners/moderationAgent/index.ts
+++ b/packages/gateway/src/listeners/moderationAgent/index.ts
@@ -18,8 +18,7 @@ import {
} from "./constants";
import { analyzeMessageWithAI, fetchMessageContext } from "./utilities";
-export const handleAIModeration = (client: Client) => {
- client.on(Events.MessageCreate, async (message: Message) => {
+export const handleAIModeration = async (message: Message) => {
if (message.author.bot) return;
if (!message.content && message.attachments.size === 0) return;
@@ -222,7 +221,7 @@ export const handleAIModeration = (client: Client) => {
if (!SKIP_PRIMARY_NOTIFICATION)
await sendAuditLog(
- client,
+ message.client,
embed,
message.content && message.content.length > 1000
? message.content
@@ -231,7 +230,7 @@ export const handleAIModeration = (client: Client) => {
);
await sendAuditLog(
- client,
+ message.client,
embed,
message.content && message.content.length > 1000
? message.content
@@ -241,5 +240,4 @@ export const handleAIModeration = (client: Client) => {
} catch (error) {
console.error("Error in AI moderation:", error);
}
- });
};
diff --git a/packages/gateway/src/listeners/roleMentionCooldown.ts b/packages/gateway/src/listeners/roleMentionCooldown.ts
index a94357c..a4e9a0b 100644
--- a/packages/gateway/src/listeners/roleMentionCooldown.ts
+++ b/packages/gateway/src/listeners/roleMentionCooldown.ts
@@ -1,4 +1,4 @@
-import { Client, Events, Message, Role } from "discord.js";
+import { Message, Role } from "discord.js";
const COOLDOWN_ROLES = [
"1421632398302515271",
@@ -7,8 +7,7 @@ const COOLDOWN_ROLES = [
const COOLDOWN_DURATION = 30 * 60 * 1000;
const roleCooldowns = new Map<string, number>();
-export const handleRoleMentionCooldown = (client: Client) => {
- client.on(Events.MessageCreate, async (message: Message) => {
+export const handleRoleMentionCooldown = async (message: Message) => {
if (message.author.bot) return;
if (!message.guild) return;
@@ -59,5 +58,4 @@ export const handleRoleMentionCooldown = (client: Client) => {
console.error(`Failed to disable mention permissions for role ${role.name}:`, error);
}
}
- });
};
diff --git a/packages/gateway/src/listeners/roleplayUmagram.ts b/packages/gateway/src/listeners/roleplayUmagram.ts
index 6588a03..9a2fa32 100644
--- a/packages/gateway/src/listeners/roleplayUmagram.ts
+++ b/packages/gateway/src/listeners/roleplayUmagram.ts
@@ -1,8 +1,7 @@
-import { Client, Events, Message } from "discord.js";
+import { Message } from "discord.js";
import { ROLEPLAY_UMAGRAM_CHANNEL_ID } from "./constants";
-export const handleRoleplayUmagram = (client: Client) => {
- client.on(Events.MessageCreate, async (message: Message) => {
+export const handleRoleplayUmagram = async (message: Message) => {
const isMainChannel = message.channelId === ROLEPLAY_UMAGRAM_CHANNEL_ID;
const isThreadInChannel =
message.channel?.isThread() &&
@@ -11,7 +10,7 @@ export const handleRoleplayUmagram = (client: Client) => {
if (!isMainChannel && !isThreadInChannel) return;
try {
- if (message.author.id === client.user?.id) return;
+ if (message.author.id === message.client.user?.id) return;
try {
await message.react("❤️");
@@ -43,5 +42,4 @@ export const handleRoleplayUmagram = (client: Client) => {
} catch (error) {
console.error("Error in roleplay-umagram moderation:", error);
}
- });
};