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

Automod work vol 2

This commit is contained in:
Dragory 2020-07-27 21:51:03 +03:00
parent f657b169df
commit 0e9f65e0d5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
12 changed files with 420 additions and 59 deletions

View file

@ -14,18 +14,15 @@ const MessageSpamTriggerConfig = t.type({
});
type TMessageSpamTriggerConfig = t.TypeOf<typeof MessageSpamTriggerConfig>;
const MessageSpamMatchResultType = t.type({
archiveId: t.string,
});
type TMessageSpamMatchResultType = t.TypeOf<typeof MessageSpamMatchResultType>;
interface TMessageSpamMatchResultType {
archiveId: string;
}
export function createMessageSpamTrigger(spamType: RecentActionType, prettyName: string) {
return automodTrigger({
return automodTrigger<TMessageSpamMatchResultType>()({
configType: MessageSpamTriggerConfig,
defaultConfig: {},
matchResultType: MessageSpamMatchResultType,
async match({ pluginData, context, triggerConfig }) {
if (!context.message) {
return;

View file

@ -13,18 +13,9 @@ type TextTriggerWithMultipleMatchTypes = {
match_custom_status: boolean;
};
export const MatchableTextType = t.union([
t.literal("message"),
t.literal("embed"),
t.literal("visiblename"),
t.literal("username"),
t.literal("nickname"),
t.literal("customstatus"),
]);
export type MatchableTextType = "message" | "embed" | "visiblename" | "username" | "nickname" | "customstatus";
export type TMatchableTextType = t.TypeOf<typeof MatchableTextType>;
type YieldedContent = [TMatchableTextType, string];
type YieldedContent = [MatchableTextType, string];
/**
* Generator function that allows iterating through matchable pieces of text of a SavedMessage

View file

@ -7,6 +7,7 @@ import { CleanAction } from "../actions/clean";
export async function runAutomod(pluginData: PluginData<AutomodPluginType>, context: AutomodContext) {
const userId = context.user?.id || context.message?.user_id;
const user = userId && pluginData.client.users.get(userId);
const member = userId && pluginData.guild.members.get(userId);
const channelId = context.message?.channel_id;
const channel = channelId && pluginData.guild.channels.get(channelId);
@ -21,6 +22,7 @@ export async function runAutomod(pluginData: PluginData<AutomodPluginType>, cont
for (const [ruleName, rule] of Object.entries(config.rules)) {
if (rule.enabled === false) continue;
if (!rule.affects_bots && user.bot) continue;
let matchResult: AutomodTriggerMatchResult<any>;
let matchSummary: string;