diff options
| author | Fuwn <[email protected]> | 2025-10-08 00:03:22 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-08 00:03:22 -0700 |
| commit | 307076547a829d9342757e3ec5839a54e3ca64dc (patch) | |
| tree | c0c0a04f0501cafba62e211a4b2b2a8c2d323e3d | |
| parent | fix(gateway:messageDeletion): Better handle privilged actions (diff) | |
| download | umabotdiscord-307076547a829d9342757e3ec5839a54e3ca64dc.tar.xz umabotdiscord-307076547a829d9342757e3ec5839a54e3ca64dc.zip | |
refactor: Move Discord interaction constants to shared constants package
| -rw-r--r-- | packages/gateway/src/constants.ts | 4 | ||||
| -rw-r--r-- | packages/gateway/src/listeners/channelDeletion.ts | 4 | ||||
| -rw-r--r-- | packages/gateway/src/listeners/clientReady/activity.ts | 5 | ||||
| -rw-r--r-- | packages/gateway/src/listeners/messageDeletion.ts | 3 | ||||
| -rw-r--r-- | packages/gateway/src/listeners/roleProtection.ts | 3 | ||||
| -rw-r--r-- | packages/interactions/constants.ts | 4 | ||||
| -rw-r--r-- | packages/interactions/discord/commands/index.ts | 39 | ||||
| -rw-r--r-- | packages/shared/index.ts | 31 |
8 files changed, 75 insertions, 18 deletions
diff --git a/packages/gateway/src/constants.ts b/packages/gateway/src/constants.ts index 2a680e1..dbe8a45 100644 --- a/packages/gateway/src/constants.ts +++ b/packages/gateway/src/constants.ts @@ -33,4 +33,8 @@ export { CENTRAL_OKBUDDY_EMOJI_ID, BOT_ID, COLOR_ROLE_IDS, + DISCORD_AUDIT_LOG_TYPES, + DISCORD_ACTIVITY_TYPES, + DISCORD_APPLICATION_COMMAND_OPTION_TYPES, + DISCORD_INTERACTION_CONTEXTS, } from "../../shared"; diff --git a/packages/gateway/src/listeners/channelDeletion.ts b/packages/gateway/src/listeners/channelDeletion.ts index 44c58f6..c576f50 100644 --- a/packages/gateway/src/listeners/channelDeletion.ts +++ b/packages/gateway/src/listeners/channelDeletion.ts @@ -1,5 +1,5 @@ import { Client, Events } from "discord.js"; -import { CENTRAL_GUILD_ID } from "../constants"; +import { CENTRAL_GUILD_ID, DISCORD_AUDIT_LOG_TYPES } from "../constants"; const channelDeletionTracker = new Map< string, @@ -22,7 +22,7 @@ export const handleChannelDeletion = (client: Client) => { const guildOwner = await guild.fetchOwner(); const auditLogs = await guild.fetchAuditLogs({ - type: 12, + type: DISCORD_AUDIT_LOG_TYPES.CHANNEL_DELETE, limit: 5, }); const channelDeletionLog = auditLogs.entries.find( diff --git a/packages/gateway/src/listeners/clientReady/activity.ts b/packages/gateway/src/listeners/clientReady/activity.ts index 8abd50b..3e201dd 100644 --- a/packages/gateway/src/listeners/clientReady/activity.ts +++ b/packages/gateway/src/listeners/clientReady/activity.ts @@ -1,5 +1,8 @@ import { Client } from "discord.js"; +import { DISCORD_ACTIVITY_TYPES } from "../../constants"; export const handleActivity = (client: Client) => { - client.user?.setActivity("r/okbuddyumamusume", { type: 3 }); + client.user?.setActivity("r/okbuddyumamusume", { + type: DISCORD_ACTIVITY_TYPES.WATCHING, + }); }; diff --git a/packages/gateway/src/listeners/messageDeletion.ts b/packages/gateway/src/listeners/messageDeletion.ts index 992091f..568448b 100644 --- a/packages/gateway/src/listeners/messageDeletion.ts +++ b/packages/gateway/src/listeners/messageDeletion.ts @@ -6,6 +6,7 @@ import { CENTRAL_MESSAGE_LOG_CHANNEL_ID, ROLEPLAY_MESSAGE_LOG_CHANNEL_ID, BOT_ID, + DISCORD_AUDIT_LOG_TYPES, } from "../constants"; const GUILD_CHANNEL_MAPPINGS = { @@ -37,7 +38,7 @@ export const handleMessageDeletion = (client: Client) => { try { const auditLogs = await guild?.fetchAuditLogs({ limit: 10, - type: 72, // MESSAGE_DELETE + type: DISCORD_AUDIT_LOG_TYPES.MESSAGE_DELETE, }); if (!auditLogs || auditLogs.entries.size === 0) return; diff --git a/packages/gateway/src/listeners/roleProtection.ts b/packages/gateway/src/listeners/roleProtection.ts index 61d60da..2b9f6cc 100644 --- a/packages/gateway/src/listeners/roleProtection.ts +++ b/packages/gateway/src/listeners/roleProtection.ts @@ -3,6 +3,7 @@ import { CENTRAL_GUILD_ID, CENTRAL_PROTECTED_ROLE_ID, COLOR_ROLE_IDS, + DISCORD_AUDIT_LOG_TYPES, } from "../constants"; export const handleRoleProtection = (client: Client) => { @@ -36,7 +37,7 @@ export const handleRoleProtection = (client: Client) => { if (role.position > protectedRole.position) { try { const auditLogs = await newMember.guild.fetchAuditLogs({ - type: 25, // MEMBER_ROLE_UPDATE + type: DISCORD_AUDIT_LOG_TYPES.MEMBER_ROLE_UPDATE, limit: 10, }); diff --git a/packages/interactions/constants.ts b/packages/interactions/constants.ts new file mode 100644 index 0000000..f18e44c --- /dev/null +++ b/packages/interactions/constants.ts @@ -0,0 +1,4 @@ +export { + DISCORD_APPLICATION_COMMAND_OPTION_TYPES, + DISCORD_INTERACTION_CONTEXTS, +} from "../shared"; diff --git a/packages/interactions/discord/commands/index.ts b/packages/interactions/discord/commands/index.ts index 2c39b28..c22d3aa 100644 --- a/packages/interactions/discord/commands/index.ts +++ b/packages/interactions/discord/commands/index.ts @@ -1,4 +1,8 @@ import type { DiscordCommand } from "../interfaces.ts"; +import { + DISCORD_APPLICATION_COMMAND_OPTION_TYPES, + DISCORD_INTERACTION_CONTEXTS, +} from "../../constants.ts"; export type { DiscordCommand }; @@ -24,7 +28,7 @@ export const TOP_COMMAND: DiscordCommand = { "Fetch a random top post from r/okbuddyumamusume (defaults to today)", options: [ { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "time", description: "Time period for top posts (defaults to today)", required: false, @@ -61,10 +65,13 @@ export const TOP_COMMAND: DiscordCommand = { export const COMPLAIN_COMMAND: DiscordCommand = { name: "complain", description: "Submit a complaint to the moderators", - contexts: [0, 1], + contexts: [ + DISCORD_INTERACTION_CONTEXTS.GUILD, + DISCORD_INTERACTION_CONTEXTS.BOT_DM, + ], options: [ { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "message", description: "Your complaint message", required: true, @@ -75,10 +82,13 @@ export const COMPLAIN_COMMAND: DiscordCommand = { export const APPEAL_COMMAND: DiscordCommand = { name: "appeal", description: "Submit an appeal to the moderators", - contexts: [0, 1], + contexts: [ + DISCORD_INTERACTION_CONTEXTS.GUILD, + DISCORD_INTERACTION_CONTEXTS.BOT_DM, + ], options: [ { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "message", description: "Your appeal message", required: true, @@ -89,10 +99,13 @@ export const APPEAL_COMMAND: DiscordCommand = { export const NSFW_APPLY_COMMAND: DiscordCommand = { name: "nsfw-apply", description: "Submit an NSFW access application to the moderators", - contexts: [0, 1], + contexts: [ + DISCORD_INTERACTION_CONTEXTS.GUILD, + DISCORD_INTERACTION_CONTEXTS.BOT_DM, + ], options: [ { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "message", description: "Your NSFW access application message", required: true, @@ -111,7 +124,7 @@ export const ROLEPLAY_VERIFY_COMMAND: DiscordCommand = { "Manage the verified roleplay role (Admin/Roleplay Curator only)", options: [ { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "action", description: "Action to perform on the role", required: true, @@ -131,7 +144,7 @@ export const ROLEPLAY_VERIFY_COMMAND: DiscordCommand = { ], }, { - type: 6, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.USER, name: "user", description: "User to perform the action on", required: true, @@ -144,7 +157,7 @@ export const AGE_VERIFY_COMMAND: DiscordCommand = { description: "Manage the verified age role (Staff only)", options: [ { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "action", description: "Action to perform on the role", required: true, @@ -164,13 +177,13 @@ export const AGE_VERIFY_COMMAND: DiscordCommand = { ], }, { - type: 6, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.USER, name: "user", description: "User to perform the action on", required: true, }, { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "access", description: "Type of access to grant", required: true, @@ -186,7 +199,7 @@ export const AGE_VERIFY_COMMAND: DiscordCommand = { ], }, { - type: 3, + type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, name: "reason", description: "Reason for verification (how and why you verified the user)", diff --git a/packages/shared/index.ts b/packages/shared/index.ts index 91247c9..ae038c8 100644 --- a/packages/shared/index.ts +++ b/packages/shared/index.ts @@ -61,3 +61,34 @@ export const COLOR_ROLE_IDS = [ "1416583690217328660", // Neo Universe Pastel Yellow "1416595046249267364", // Manhattan Cafe Jet Black ]; +export const DISCORD_AUDIT_LOG_TYPES = { + MESSAGE_DELETE: 72, + MEMBER_ROLE_UPDATE: 25, + CHANNEL_DELETE: 12, +} as const; +export const DISCORD_ACTIVITY_TYPES = { + PLAYING: 0, + STREAMING: 1, + LISTENING: 2, + WATCHING: 3, + CUSTOM_STATUS: 4, + COMPETING: 5, +} as const; +export const DISCORD_APPLICATION_COMMAND_OPTION_TYPES = { + SUB_COMMAND: 1, + SUB_COMMAND_GROUP: 2, + STRING: 3, + INTEGER: 4, + BOOLEAN: 5, + USER: 6, + CHANNEL: 7, + ROLE: 8, + MENTIONABLE: 9, + NUMBER: 10, + ATTACHMENT: 11, +} as const; +export const DISCORD_INTERACTION_CONTEXTS = { + GUILD: 0, + BOT_DM: 1, + PRIVATE_CHANNEL: 2, +} as const; |