mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
feat: add thread_create_spam automod trigger (#273)
This commit is contained in:
parent
f9c0e661af
commit
6709115166
4 changed files with 63 additions and 0 deletions
|
@ -16,4 +16,5 @@ export enum RecentActionType {
|
||||||
MemberJoin,
|
MemberJoin,
|
||||||
Sticker,
|
Sticker,
|
||||||
MemberLeave,
|
MemberLeave,
|
||||||
|
ThreadCreate,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { typedGuildEventListener } from "knub";
|
import { typedGuildEventListener } from "knub";
|
||||||
|
import { RecentActionType } from "../constants";
|
||||||
import { runAutomod } from "../functions/runAutomod";
|
import { runAutomod } from "../functions/runAutomod";
|
||||||
import { AutomodContext, AutomodPluginType } from "../types";
|
import { AutomodContext, AutomodPluginType } from "../types";
|
||||||
|
|
||||||
|
@ -19,6 +20,13 @@ export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginTyp
|
||||||
};
|
};
|
||||||
|
|
||||||
pluginData.state.queue.add(() => {
|
pluginData.state.queue.add(() => {
|
||||||
|
pluginData.state.recentActions.push({
|
||||||
|
type: RecentActionType.ThreadCreate,
|
||||||
|
context,
|
||||||
|
count: 1,
|
||||||
|
identifier: null,
|
||||||
|
});
|
||||||
|
|
||||||
runAutomod(pluginData, context);
|
runAutomod(pluginData, context);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,6 +27,7 @@ import { RoleAddedTrigger } from "./roleAdded";
|
||||||
import { RoleRemovedTrigger } from "./roleRemoved";
|
import { RoleRemovedTrigger } from "./roleRemoved";
|
||||||
import { StickerSpamTrigger } from "./stickerSpam";
|
import { StickerSpamTrigger } from "./stickerSpam";
|
||||||
import { ThreadCreateTrigger } from "./threadCreate";
|
import { ThreadCreateTrigger } from "./threadCreate";
|
||||||
|
import { ThreadCreateSpamTrigger } from "./threadCreateSpam";
|
||||||
import { ThreadDeleteTrigger } from "./threadDelete";
|
import { ThreadDeleteTrigger } from "./threadDelete";
|
||||||
import { UnbanTrigger } from "./unban";
|
import { UnbanTrigger } from "./unban";
|
||||||
import { UnmuteTrigger } from "./unmute";
|
import { UnmuteTrigger } from "./unmute";
|
||||||
|
@ -54,6 +55,7 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
|
||||||
character_spam: CharacterSpamTrigger,
|
character_spam: CharacterSpamTrigger,
|
||||||
member_join_spam: MemberJoinSpamTrigger,
|
member_join_spam: MemberJoinSpamTrigger,
|
||||||
sticker_spam: StickerSpamTrigger,
|
sticker_spam: StickerSpamTrigger,
|
||||||
|
thread_create_spam: ThreadCreateSpamTrigger,
|
||||||
|
|
||||||
counter_trigger: CounterTrigger,
|
counter_trigger: CounterTrigger,
|
||||||
|
|
||||||
|
@ -94,6 +96,7 @@ export const AvailableTriggers = t.type({
|
||||||
character_spam: CharacterSpamTrigger.configType,
|
character_spam: CharacterSpamTrigger.configType,
|
||||||
member_join_spam: MemberJoinSpamTrigger.configType,
|
member_join_spam: MemberJoinSpamTrigger.configType,
|
||||||
sticker_spam: StickerSpamTrigger.configType,
|
sticker_spam: StickerSpamTrigger.configType,
|
||||||
|
thread_create_spam: ThreadCreateSpamTrigger.configType,
|
||||||
|
|
||||||
counter_trigger: CounterTrigger.configType,
|
counter_trigger: CounterTrigger.configType,
|
||||||
|
|
||||||
|
|
51
backend/src/plugins/Automod/triggers/threadCreateSpam.ts
Normal file
51
backend/src/plugins/Automod/triggers/threadCreateSpam.ts
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import * as t from "io-ts";
|
||||||
|
import { convertDelayStringToMS, tDelayString } from "../../../utils";
|
||||||
|
import { RecentActionType } from "../constants";
|
||||||
|
import { findRecentSpam } from "../functions/findRecentSpam";
|
||||||
|
import { getMatchingRecentActions } from "../functions/getMatchingRecentActions";
|
||||||
|
import { sumRecentActionCounts } from "../functions/sumRecentActionCounts";
|
||||||
|
import { automodTrigger } from "../helpers";
|
||||||
|
|
||||||
|
export const ThreadCreateSpamTrigger = automodTrigger<unknown>()({
|
||||||
|
configType: t.type({
|
||||||
|
amount: t.number,
|
||||||
|
within: tDelayString,
|
||||||
|
}),
|
||||||
|
|
||||||
|
defaultConfig: {},
|
||||||
|
|
||||||
|
async match({ pluginData, context, triggerConfig }) {
|
||||||
|
if (!context.threadChange?.created) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const recentSpam = findRecentSpam(pluginData, RecentActionType.ThreadCreate);
|
||||||
|
if (recentSpam) {
|
||||||
|
context.actioned = true;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const since = Date.now() - convertDelayStringToMS(triggerConfig.within)!;
|
||||||
|
const matchingActions = getMatchingRecentActions(pluginData, RecentActionType.ThreadCreate, null, since);
|
||||||
|
const totalCount = sumRecentActionCounts(matchingActions);
|
||||||
|
|
||||||
|
if (totalCount >= triggerConfig.amount) {
|
||||||
|
const extraContexts = matchingActions.map(a => a.context).filter(c => c !== context);
|
||||||
|
|
||||||
|
pluginData.state.recentSpam.push({
|
||||||
|
type: RecentActionType.ThreadCreate,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
archiveId: null,
|
||||||
|
identifiers: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
extraContexts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
renderMatchInformation({ pluginData, contexts, triggerConfig }) {
|
||||||
|
return "";
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue