diff options
| author | Fuwn <[email protected]> | 2025-09-25 14:30:52 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-25 14:30:52 -0700 |
| commit | abe71694b3b9cee240d853af05f2ca7db1f5d718 (patch) | |
| tree | 11c765a578552644d59c5e5dd042867fa8fb1f69 | |
| parent | refactor(gateway:iqdbModeration): Lint (diff) | |
| download | umabotdiscord-abe71694b3b9cee240d853af05f2ca7db1f5d718.tar.xz umabotdiscord-abe71694b3b9cee240d853af05f2ca7db1f5d718.zip | |
feat(gateway:iqdbModeration): Add similarity-based behaviours
| -rw-r--r-- | packages/gateway/src/listeners/iqdbModeration.ts | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/packages/gateway/src/listeners/iqdbModeration.ts b/packages/gateway/src/listeners/iqdbModeration.ts index 296ae4c..d6c71a7 100644 --- a/packages/gateway/src/listeners/iqdbModeration.ts +++ b/packages/gateway/src/listeners/iqdbModeration.ts @@ -131,16 +131,21 @@ export const handleIqdbModeration = (client: Client) => { ); if (foundProhibitedTags.length > 0) { + const similarity = match.similarity!; + const isHighConfidence = similarity > 0.75; + console.log( - `Prohibited tags detected: ${foundProhibitedTags.join(", ")}, deleting message...`, + `Prohibited tags detected: ${foundProhibitedTags.join(", ")}, similarity: ${(similarity * 100).toFixed(1)}%, ${isHighConfidence ? "deleting message" : "sending notification"}...`, ); - await message.delete(); - const { EmbedBuilder } = await import("discord.js"); const embed = new EmbedBuilder() - .setTitle("🚫 Image Deleted - Prohibited Tags Detected") - .setColor("#ff0000") + .setTitle( + isHighConfidence + ? "🚫 Image Deleted - Prohibited Tags Detected" + : "⚠️ Potential Prohibited Content Detected", + ) + .setColor(isHighConfidence ? "#ff0000" : "#ffaa00") .addFields( { name: "Channel", @@ -164,7 +169,7 @@ export const handleIqdbModeration = (client: Client) => { }, { name: "Similarity", - value: `${(match.similarity! * 100).toFixed(1)}%`, + value: `${(similarity * 100).toFixed(1)}%`, inline: true, }, { @@ -178,12 +183,35 @@ export const handleIqdbModeration = (client: Client) => { text: `Guild: ${message.guild?.name || "Unknown"}`, }); - await sendAuditLog( - client, - embed, - undefined, - "1406422619934167106", - ); + if (isHighConfidence) await message.delete(); + + try { + const channelId = "1406422619934167106"; + const channel = client.channels.cache.get(channelId); + + if (channel && "send" in channel) { + const imageResponse = await fetch(attachment.url); + const imageBuffer = await imageResponse.arrayBuffer(); + const imageAttachment = { + attachment: Buffer.from(imageBuffer), + name: attachment.name || "flagged_image.jpg", + }; + + await (channel as any).send({ + embeds: [embed], + files: [imageAttachment], + }); + } + } catch (error) { + console.error("Error sending image attachment:", error); + + await sendAuditLog( + client, + embed, + undefined, + "1406422619934167106", + ); + } return; } |