diff options
| author | Fuwn <[email protected]> | 2025-09-30 18:47:43 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-30 18:47:43 -0700 |
| commit | ad34f7e4637a26cd4ccabe28b98ecddd39aa7e69 (patch) | |
| tree | ff92e94997e0003695928b66eb1c6f518f66ad62 | |
| parent | fix(listeners:voiceConnection): Handle errors (diff) | |
| download | umabotdiscord-ad34f7e4637a26cd4ccabe28b98ecddd39aa7e69.tar.xz umabotdiscord-ad34f7e4637a26cd4ccabe28b98ecddd39aa7e69.zip | |
fix(listeners:messageDeletion): Add additional output channel
| -rw-r--r-- | packages/gateway/src/listeners/messageDeletion.ts | 31 | ||||
| -rw-r--r-- | packages/gateway/src/listeners/moderationAgent/utilities.ts | 4 | ||||
| -rw-r--r-- | packages/gateway/src/listeners/voiceConnection.ts | 4 |
3 files changed, 29 insertions, 10 deletions
diff --git a/packages/gateway/src/listeners/messageDeletion.ts b/packages/gateway/src/listeners/messageDeletion.ts index 737970a..8fbc62e 100644 --- a/packages/gateway/src/listeners/messageDeletion.ts +++ b/packages/gateway/src/listeners/messageDeletion.ts @@ -2,12 +2,20 @@ import { Client, Events, EmbedBuilder } from "discord.js"; import { GUILD_ID } from "../constants"; import { sendAuditLog } from "../commands/utilities"; +const EDIT_LOG_CHANNEL_ID = "1422501525678198855"; + export const handleMessageDeletion = (client: Client) => { client.on(Events.MessageDelete, async (deletedMessage) => { if (deletedMessage.guildId !== GUILD_ID) return; if (deletedMessage.author?.bot) return; + const application = await client.application?.fetch(); + const ownerId = application?.owner?.id; + const isBotOrOwner = + deletedMessage.author?.id === client.user?.id || + deletedMessage.author?.id === ownerId; + try { const channel = deletedMessage.channel; const author = deletedMessage.author; @@ -71,25 +79,36 @@ export const handleMessageDeletion = (client: Client) => { .map((a) => `[${a.name}](${a.url})`) .join("\n").length <= 1024) ) { - await sendAuditLog(client, embed); + if (isBotOrOwner) { + await sendAuditLog(client, embed); + } else { + await sendAuditLog(client, embed, undefined, EDIT_LOG_CHANNEL_ID); + } } else { let additionalContent = ""; - if (content.length > 1024) { + if (content.length > 1024) additionalContent += "**Content:**\n" + content + "\n\n"; - } if (attachments.size > 0) { const attachmentList = Array.from(attachments.values()) .map((attachment) => `[${attachment.name}](${attachment.url})`) .join("\n"); - if (attachmentList.length > 1024) { + if (attachmentList.length > 1024) additionalContent += "**Attachments:**\n" + attachmentList; - } } - await sendAuditLog(client, embed, additionalContent); + if (isBotOrOwner) { + await sendAuditLog(client, embed, additionalContent); + } else { + await sendAuditLog( + client, + embed, + additionalContent, + EDIT_LOG_CHANNEL_ID, + ); + } } } catch (error) { console.error("Error logging message deletion:", error); diff --git a/packages/gateway/src/listeners/moderationAgent/utilities.ts b/packages/gateway/src/listeners/moderationAgent/utilities.ts index 7611cab..14bf563 100644 --- a/packages/gateway/src/listeners/moderationAgent/utilities.ts +++ b/packages/gateway/src/listeners/moderationAgent/utilities.ts @@ -377,7 +377,7 @@ Remember: Only enforce the exact rules provided. Do not make assumptions or inte .replace(/"([^"]*)"([^",}:])/g, '"$1"$2'); return JSON.parse(fixedJson); - } catch (e) { + } catch { return JSON.parse(jsonContent); } } catch (parseError) { @@ -416,7 +416,7 @@ Remember: Only enforce the exact rules provided. Do not make assumptions or inte .replace(/"([^"]*)"([^",}:])/g, '"$1"$2'); return JSON.parse(fixedJson); - } catch (e) { + } catch { return JSON.parse(fallbackContent); } } catch (fallbackError) { diff --git a/packages/gateway/src/listeners/voiceConnection.ts b/packages/gateway/src/listeners/voiceConnection.ts index 1bf51b7..2de1f90 100644 --- a/packages/gateway/src/listeners/voiceConnection.ts +++ b/packages/gateway/src/listeners/voiceConnection.ts @@ -28,7 +28,7 @@ export const handleVoiceConnection = (client: Client) => { const player = createAudioPlayer(); connection.subscribe(player); - connection.on('error', (error) => { + connection.on("error", (error) => { console.error("Voice connection error:", error); setTimeout(() => { handleVoiceConnection(client); @@ -45,7 +45,7 @@ export const handleVoiceConnection = (client: Client) => { const newPlayer = createAudioPlayer(); newConnection.subscribe(newPlayer); - newConnection.on('error', (error) => { + newConnection.on("error", (error) => { console.error("Voice reconnection error:", error); setTimeout(() => { handleVoiceConnection(client); |