3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

feat: add thread_create_spam automod trigger (#273)

This commit is contained in:
Almeida 2021-10-31 17:23:26 +00:00 committed by GitHub
parent f9c0e661af
commit 6709115166
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 0 deletions

View file

@ -16,4 +16,5 @@ export enum RecentActionType {
MemberJoin,
Sticker,
MemberLeave,
ThreadCreate,
}

View file

@ -1,4 +1,5 @@
import { typedGuildEventListener } from "knub";
import { RecentActionType } from "../constants";
import { runAutomod } from "../functions/runAutomod";
import { AutomodContext, AutomodPluginType } from "../types";
@ -19,6 +20,13 @@ export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginTyp
};
pluginData.state.queue.add(() => {
pluginData.state.recentActions.push({
type: RecentActionType.ThreadCreate,
context,
count: 1,
identifier: null,
});
runAutomod(pluginData, context);
});
},

View file

@ -27,6 +27,7 @@ import { RoleAddedTrigger } from "./roleAdded";
import { RoleRemovedTrigger } from "./roleRemoved";
import { StickerSpamTrigger } from "./stickerSpam";
import { ThreadCreateTrigger } from "./threadCreate";
import { ThreadCreateSpamTrigger } from "./threadCreateSpam";
import { ThreadDeleteTrigger } from "./threadDelete";
import { UnbanTrigger } from "./unban";
import { UnmuteTrigger } from "./unmute";
@ -54,6 +55,7 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
character_spam: CharacterSpamTrigger,
member_join_spam: MemberJoinSpamTrigger,
sticker_spam: StickerSpamTrigger,
thread_create_spam: ThreadCreateSpamTrigger,
counter_trigger: CounterTrigger,
@ -94,6 +96,7 @@ export const AvailableTriggers = t.type({
character_spam: CharacterSpamTrigger.configType,
member_join_spam: MemberJoinSpamTrigger.configType,
sticker_spam: StickerSpamTrigger.configType,
thread_create_spam: ThreadCreateSpamTrigger.configType,
counter_trigger: CounterTrigger.configType,

View 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 "";
},
});