Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automod: Censor images #573

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/automod/automod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ import warn from "../punishments/warn.js";
import tryCensor, { badWordRegexps, badWordsAllowed } from "./misc.js";
import { stripMarkdown } from "../../util/markdown.js";
import { joinWithAnd } from "../../util/text.js";
import { createWorker } from "tesseract.js";

const worker = await createWorker("eng");
TheYande marked this conversation as resolved.
Show resolved Hide resolved
async function getMessageImageText(message: Message): Promise<string[]> {
const imageTextPromises = message.attachments
.filter((attachment) => attachment?.contentType?.match(/^image\/(bmp|jpeg|png|bpm|webp)$/i))
RedGuy12 marked this conversation as resolved.
Show resolved Hide resolved
.map(async ({ url }) => {
if (url) {
const ret = await worker.recognize(url);
return ret.data.text;
}
})
.filter(Boolean);

const imageTextResults = await Promise.all(imageTextPromises);
return imageTextResults as string[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need this as here i don't think

}

const WHITELISTED_INVITE_GUILDS = new Set([
config.guild.id,
Expand Down Expand Up @@ -120,6 +137,7 @@ export default async function automodMessage(message: Message): Promise<boolean>

const badWords = [
tryCensor(stripMarkdown(message.content)),
...(await getMessageImageText(message)).map((text) => tryCensor(text)),
...message.stickers.map(({ name }) => tryCensor(name)),
...invites.map(([, invite]) => !!invite?.guild && tryCensor(invite.guild.name)),
].reduce(
Expand Down
214 changes: 213 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading