3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Automod work vol 3

This commit is contained in:
Dragory 2020-07-27 22:19:34 +03:00
parent 0e9f65e0d5
commit 0f0728bc1c
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
18 changed files with 133 additions and 38 deletions

View file

@ -12,6 +12,8 @@ import { MatchRegexTrigger } from "./matchRegex";
import { MatchInvitesTrigger } from "./matchInvites";
import { MatchLinksTrigger } from "./matchLinks";
import { MatchAttachmentTypeTrigger } from "./matchAttachmentType";
import { MemberJoinSpamTrigger } from "./memberJoinSpam";
import { MemberJoinTrigger } from "./memberJoin";
export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>> = {
match_words: MatchWordsTrigger,
@ -19,6 +21,7 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
match_invites: MatchInvitesTrigger,
match_links: MatchLinksTrigger,
match_attachment_type: MatchAttachmentTypeTrigger,
member_join: MemberJoinTrigger,
message_spam: MessageSpamTrigger,
mention_spam: MentionSpamTrigger,
@ -27,6 +30,7 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
emoji_spam: EmojiSpamTrigger,
line_spam: LineSpamTrigger,
character_spam: CharacterSpamTrigger,
member_join_spam: MemberJoinSpamTrigger,
};
export const AvailableTriggers = t.type({
@ -35,6 +39,7 @@ export const AvailableTriggers = t.type({
match_invites: MatchInvitesTrigger.configType,
match_links: MatchLinksTrigger.configType,
match_attachment_type: MatchAttachmentTypeTrigger.configType,
member_join: MemberJoinTrigger.configType,
message_spam: MessageSpamTrigger.configType,
mention_spam: MentionSpamTrigger.configType,
@ -43,4 +48,5 @@ export const AvailableTriggers = t.type({
emoji_spam: EmojiSpamTrigger.configType,
line_spam: LineSpamTrigger.configType,
character_spam: CharacterSpamTrigger.configType,
member_join_spam: MemberJoinSpamTrigger.configType,
});

View file

@ -1,19 +1,6 @@
import * as t from "io-ts";
import { transliterate } from "transliteration";
import escapeStringRegexp from "escape-string-regexp";
import { AnyInvite, Attachment, GuildInvite } from "eris";
import { automodTrigger } from "../helpers";
import {
asSingleLine,
disableCodeBlocks,
disableInlineCode,
getInviteCodesInString,
isGuildInvite,
resolveInvite,
tNullable,
verboseChannelMention,
} from "../../../utils";
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
import { asSingleLine, disableCodeBlocks, disableInlineCode, verboseChannelMention } from "../../../utils";
interface MatchResultType {
matchedType: string;

View file

@ -1,12 +1,8 @@
import * as t from "io-ts";
import { transliterate } from "transliteration";
import escapeStringRegexp from "escape-string-regexp";
import { AnyInvite, GuildInvite } from "eris";
import { GuildInvite } from "eris";
import { automodTrigger } from "../helpers";
import {
asSingleLine,
disableCodeBlocks,
disableInlineCode,
getInviteCodesInString,
isGuildInvite,
resolveInvite,

View file

@ -1,16 +1,11 @@
import * as t from "io-ts";
import { transliterate } from "transliteration";
import escapeStringRegexp from "escape-string-regexp";
import { AnyInvite, GuildInvite } from "eris";
import { automodTrigger } from "../helpers";
import {
asSingleLine,
disableCodeBlocks,
disableInlineCode,
getInviteCodesInString,
getUrlsInString,
isGuildInvite,
resolveInvite,
tNullable,
verboseChannelMention,
} from "../../../utils";

View file

@ -1,6 +1,5 @@
import * as t from "io-ts";
import { transliterate } from "transliteration";
import escapeStringRegexp from "escape-string-regexp";
import { automodTrigger } from "../helpers";
import { disableInlineCode, verboseChannelMention } from "../../../utils";
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";

View file

@ -0,0 +1,34 @@
import * as t from "io-ts";
import { automodTrigger } from "../helpers";
import { convertDelayStringToMS, tDelayString } from "../../../utils";
export const MemberJoinTrigger = automodTrigger<unknown>()({
configType: t.type({
only_new: t.boolean,
new_threshold: tDelayString,
}),
defaultConfig: {
only_new: false,
new_threshold: "1h",
},
async match({ pluginData, context, triggerConfig }) {
if (!context.joined || !context.member) {
return;
}
if (triggerConfig.only_new) {
const threshold = Date.now() - convertDelayStringToMS(triggerConfig.new_threshold);
if (context.member.createdAt >= threshold) {
return {};
}
}
return {};
},
renderMatchInformation({ pluginData, contexts, triggerConfig }) {
return null;
},
});

View file

@ -0,0 +1,55 @@
import * as t from "io-ts";
import { automodTrigger } from "../helpers";
import { convertDelayStringToMS, tDelayString } from "../../../utils";
import { getMatchingRecentActions } from "../functions/getMatchingRecentActions";
import { RecentActionType } from "../constants";
import { sumRecentActionCounts } from "../functions/sumRecentActionCounts";
import { findRecentSpam } from "../functions/findRecentSpam";
export const MemberJoinSpamTrigger = automodTrigger<unknown>()({
configType: t.type({
amount: t.number,
within: tDelayString,
}),
defaultConfig: {},
async match({ pluginData, context, triggerConfig }) {
if (!context.joined || !context.member) {
return;
}
const recentSpam = findRecentSpam(pluginData, RecentActionType.MemberJoin);
if (recentSpam) {
context.actioned = true;
return {};
}
const since = Date.now() - convertDelayStringToMS(triggerConfig.within);
const matchingActions = getMatchingRecentActions(pluginData, RecentActionType.MemberJoin, null, since);
const totalCount = sumRecentActionCounts(matchingActions);
if (totalCount >= triggerConfig.amount) {
const contexts = [context, ...matchingActions.map(a => a.context).filter(c => c !== context)];
for (const _context of contexts) {
_context.actioned = true;
}
pluginData.state.recentSpam.push({
type: RecentActionType.MemberJoin,
timestamp: Date.now(),
archiveId: null,
userIds: [],
});
return {
extraContexts: contexts,
};
}
},
renderMatchInformation({ pluginData, contexts, triggerConfig }) {
return null;
},
});