From 418f11a9d3d5e8301aa694969b25b101a27e60fc Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 17 Dec 2025 10:39:48 +0100 Subject: [PATCH] Remove automod code in favor of dev/emma-wip stuff --- .husky/pre-commit | 22 ++++---- .../channels/#channel_id/messages/index.ts | 55 ------------------- 2 files changed, 12 insertions(+), 65 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index d1adb3823..dbbc6d5f0 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -3,18 +3,20 @@ . "$(dirname -- "$0")/_/husky.sh" # Check if nix is available -if [ -x "$(/usr/bin/env which nix-shell 2>/dev/null)" ]; then - # Check if we haven't re-executed ourselves yet - if [ ! "$HOOK_NIX_SHELL" ]; then - echo "Nix is available, updating nix flake..." - export HOOK_NIX_SHELL=1 - nix-shell $0 - exit $? +if [ -n "$(find "flake.lock" -mtime +7 -print)" ]; then + if [ -x "$(/usr/bin/env which nix-shell 2>/dev/null)" ]; then + # Check if we haven't re-executed ourselves yet + if [ ! "$HOOK_NIX_SHELL" ]; then + echo "Nix is available, updating nix flake..." + export HOOK_NIX_SHELL=1 + nix-shell $0 + exit $? + else + nix flake update --extra-experimental-features 'nix-command flakes' + fi else - nix flake update --extra-experimental-features 'nix-command flakes' + echo "You do not appear to have nix installed. Skipping update of nix dependencies." fi -else - echo "You do not appear to have nix installed. Skipping update of nix dependencies." fi npx -y lint-staged diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index 1c3b5d8a8..2ce37748f 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -441,61 +441,6 @@ router.post( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore message.member.roles = message.member.roles.filter((x) => x.id != x.guild_id).map((x) => x.id); - - if (message.content) - try { - const matchingRules = await AutomodRule.find({ - where: { guild_id: message.guild_id, enabled: true, event_type: AutomodRuleEventType.MESSAGE_SEND }, - order: { position: "ASC" }, - }); - for (const rule of matchingRules) { - if (rule.exempt_channels.includes(channel_id)) continue; - if (message.member.roles.some((x) => rule.exempt_roles.includes(x.id))) continue; - - if (rule.trigger_type == AutomodTriggerTypes.CUSTOM_WORDS) { - const triggerMeta = rule.trigger_metadata as AutomodCustomWordsRule; - const regexes = triggerMeta.regex_patterns.map((x) => new RegExp(x, "i")).concat(triggerMeta.keyword_filter.map((k) => stringGlobToRegexp(k, "i"))); - const allowedRegexes = triggerMeta.allow_list.map((k) => stringGlobToRegexp(k, "i")); - - const matches = regexes - .map((r) => message.content!.match(r)) - .filter((x) => x !== null && x.length > 0) - .filter((x) => !allowedRegexes.some((ar) => ar.test(x![0]))); - - if (matches.length > 0) { - console.log("Automod triggered by message:", message.id, "matches:", matches); - if (rule.actions.some((x) => x.type == AutomodRuleActionType.SEND_ALERT_MESSAGE && x.metadata.channel_id)) { - const alertActions = rule.actions.filter((x) => x.type == AutomodRuleActionType.SEND_ALERT_MESSAGE); - for (const action of alertActions) { - const alertChannel = await Channel.findOne({ where: { id: action.metadata.channel_id } }); - if (!alertChannel) continue; - const msg = await Message.createWithDefaults({ - content: `Automod Alert: Message ${message.id} by <@${message.author_id}> in <#${channel.id}> triggered automod rule "${rule.name}".\nMatched terms: ${matches - .map((x) => `\`${x![0]}\``) - .join(", ")}`, - author: message.author, - channel_id: alertChannel.id, - guild_id: message.guild_id, - member_id: message.member_id, - author_id: message.author_id, - }); - - await message.save(); - // await Promise.all([ - await emitEvent({ - event: "MESSAGE_CREATE", - channel_id: msg.channel_id, - data: msg.toJSON(), - } as MessageCreateEvent); - // ]); - } - } - } - } - } - } catch (e) { - console.log("[Automod] failed to process message:", e); - } } let read_state = await ReadState.findOne({