Remove automod code in favor of dev/emma-wip stuff

This commit is contained in:
Rory&
2025-12-17 10:39:48 +01:00
parent e008c9947e
commit 418f11a9d3
2 changed files with 12 additions and 65 deletions
+12 -10
View File
@@ -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
@@ -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({