Fix image conversion and member update avatar checking, nsfw detection is still broken
diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts
index fe11ee1..d1bbd9b 100644
--- a/src/events/guildMemberUpdate.ts
+++ b/src/events/guildMemberUpdate.ts
@@ -87,6 +87,7 @@
await log(data);
}
}
+ if (before.displayAvatarURL !== after.displayAvatarURL) await doMemberChecks(after);
const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberUpdate)).filter(
(entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id
)[0];
@@ -125,7 +126,6 @@
};
await log(data);
}
- if (before.displayAvatarURL !== after.displayAvatarURL) await doMemberChecks(after);
if (
(before.communicationDisabledUntilTimestamp ?? 0) < Date.now() &&
new Date(after.communicationDisabledUntil ?? 0).getTime() > Date.now()
diff --git a/src/reflex/scanners.ts b/src/reflex/scanners.ts
index acd3b41..93af960 100644
--- a/src/reflex/scanners.ts
+++ b/src/reflex/scanners.ts
@@ -12,9 +12,7 @@
import getEmojiByName from "../utils/getEmojiByName.js";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import config from "../config/main.js";
-import GIFEncoder from "gifencoder";
-import gm_var from 'gm';
-const gm = gm_var.subClass({ imageMagick: '7+' });
+import gm from 'gm';
interface NSFWSchema {
nsfw: boolean;
@@ -34,7 +32,6 @@
export async function testNSFW(attachment: {
url: string;
- local: string;
height: number | null;
width: number | null;
}): Promise<NSFWSchema> {
@@ -44,12 +41,12 @@
return { nsfw: alreadyHaveCheck.nsfw }
};
- const image = gm(fileStream).command('convert').in('-')
+ const converted = await new Promise((resolve, reject) => gm(fileStream).command("convert").toBuffer("PNG", (err, buf) => {
+ if (err) return reject(err);
+ resolve(buf);
+ })) as Buffer;
+ const array = new Uint8Array(converted);
- const encoder = new GIFEncoder(attachment.width ?? 1024, attachment.height ?? 1024);
-
-
- // const array = new Uint8Array(fileStream);
const img = tf.node.decodeImage(array) as tf.Tensor3D;
const predictions = (await nsfw_model.classify(img, 1))[0]!;
@@ -156,7 +153,6 @@
export async function NSFWCheck(element: {
url: string;
- local: string;
height: number | null;
width: number | null;
}): Promise<boolean> {
@@ -238,7 +234,7 @@
// Is the profile picture NSFW
const avatar = member.displayAvatarURL({ extension: "png", size: 1024, forceStatic: true });
const avatarCheck =
- guildData.filters.images.NSFW && (await NSFWCheck({url: avatar, local: "", height: 1024, width: 1024}));
+ guildData.filters.images.NSFW && (await NSFWCheck({url: avatar, height: 1024, width: 1024}));
console.log(5, avatarCheck)
// Does the username contain an invite
const inviteCheck = guildData.filters.invite.enabled && /discord\.gg\/[a-zA-Z0-9]+/gi.test(member.user.username);
diff --git a/src/reflex/verify.ts b/src/reflex/verify.ts
index 540fb4d..8f68c0e 100644
--- a/src/reflex/verify.ts
+++ b/src/reflex/verify.ts
@@ -121,9 +121,11 @@
]
});
if (
- await NSFWCheck(
- (interaction.member as GuildMember).user.displayAvatarURL({ extension: "png", forceStatic: true })
- )
+ await NSFWCheck({
+ url: (interaction.member as GuildMember).user.displayAvatarURL({ extension: "png", forceStatic: true }),
+ height: 1024,
+ width: 1024,
+ })
) {
return await interaction.editReply({
embeds: [