summaryrefslogtreecommitdiff
path: root/packages/gateway
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-27 16:22:55 -0700
committerFuwn <[email protected]>2025-09-27 16:22:55 -0700
commit71ca6c5112ad38c20679d4075cc62146a017b95b (patch)
tree3f7d9692a63b38b176f2218fcae9c5142ad5c019 /packages/gateway
parentfeat(gateway:commands): Add react command (diff)
downloadumabotdiscord-71ca6c5112ad38c20679d4075cc62146a017b95b.tar.xz
umabotdiscord-71ca6c5112ad38c20679d4075cc62146a017b95b.zip
feat(gateway:listeners): Add revive role cooldowns
Diffstat (limited to 'packages/gateway')
-rw-r--r--packages/gateway/src/listeners/index.ts2
-rw-r--r--packages/gateway/src/listeners/roleMentionCooldown.ts65
2 files changed, 67 insertions, 0 deletions
diff --git a/packages/gateway/src/listeners/index.ts b/packages/gateway/src/listeners/index.ts
index 5224da8..846ac87 100644
--- a/packages/gateway/src/listeners/index.ts
+++ b/packages/gateway/src/listeners/index.ts
@@ -9,6 +9,7 @@ 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);
@@ -21,4 +22,5 @@ export const handleListeners = (client: Client) => {
handleChannelDeletion(client);
handleMessageDeletion(client);
handleMessageEdit(client);
+ handleRoleMentionCooldown(client);
};
diff --git a/packages/gateway/src/listeners/roleMentionCooldown.ts b/packages/gateway/src/listeners/roleMentionCooldown.ts
new file mode 100644
index 0000000..3063d70
--- /dev/null
+++ b/packages/gateway/src/listeners/roleMentionCooldown.ts
@@ -0,0 +1,65 @@
+import { Client, Events, Message, Role } from "discord.js";
+
+const COOLDOWN_ROLES = [
+ "1421632398302515271",
+ "1421632887219814572"
+];
+const COOLDOWN_DURATION = 30 * 60 * 1000;
+const roleCooldowns = new Map<string, number>();
+
+export const handleRoleMentionCooldown = (client: Client) => {
+ client.on(Events.MessageCreate, async (message: Message) => {
+ if (message.author.bot) return;
+
+ if (!message.guild) return;
+
+ const mentionedRoles = message.mentions.roles.filter(role =>
+ COOLDOWN_ROLES.includes(role.id)
+ );
+
+ if (mentionedRoles.size === 0) return;
+
+ const now = Date.now();
+
+ for (const role of mentionedRoles.values()) {
+ const cooldownEnd = roleCooldowns.get(role.id);
+
+ if (cooldownEnd && now < cooldownEnd) {
+ const timeLeft = Math.ceil((cooldownEnd - now) / 1000);
+ const minutesLeft = Math.ceil(timeLeft / 60);
+ const notification = await message.reply(
+ `This role is on cooldown for ${minutesLeft} more minute(s). This notification will be deleted in 10 seconds.`
+ );
+
+ setTimeout(async () => {
+ try {
+ await notification.delete();
+ } catch (error) {
+ console.error("Failed to delete cooldown notification:", error);
+ }
+ }, 10000);
+
+ return;
+ }
+
+ roleCooldowns.set(role.id, now + COOLDOWN_DURATION);
+
+ try {
+ await role.setMentionable(false, "Role mention cooldown activated");
+ console.warn(`Disabled mention permissions for role ${role.name} (${role.id})`);
+
+ setTimeout(async () => {
+ try {
+ await role.setMentionable(true, "Role mention cooldown expired");
+ roleCooldowns.delete(role.id);
+ console.warn(`Re-enabled mention permissions for role ${role.name} (${role.id})`);
+ } catch (error) {
+ console.error(`Failed to re-enable mention permissions for role ${role.name}:`, error);
+ }
+ }, COOLDOWN_DURATION);
+ } catch (error) {
+ console.error(`Failed to disable mention permissions for role ${role.name}:`, error);
+ }
+ }
+ });
+};