mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 11:07:19 +00:00
chore: run prettier
This commit is contained in:
parent
77ab2718e7
commit
873bf7eb99
54 changed files with 462 additions and 416 deletions
|
@ -1,9 +1,9 @@
|
|||
import { CooldownManager } from "knub";
|
||||
import { Queue } from "../../Queue";
|
||||
import { GuildAntiraidLevels } from "../../data/GuildAntiraidLevels";
|
||||
import { GuildArchives } from "../../data/GuildArchives";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { Queue } from "../../Queue";
|
||||
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners";
|
||||
import { MINUTES, SECONDS } from "../../utils";
|
||||
import { registerEventListenersFromMap } from "../../utils/registerEventListenersFromMap";
|
||||
|
@ -19,9 +19,9 @@ import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
|||
import { AntiraidClearCmd } from "./commands/AntiraidClearCmd";
|
||||
import { SetAntiraidCmd } from "./commands/SetAntiraidCmd";
|
||||
import { ViewAntiraidCmd } from "./commands/ViewAntiraidCmd";
|
||||
import { runAutomodOnCounterTrigger } from "./events/runAutomodOnCounterTrigger";
|
||||
import { RunAutomodOnJoinEvt, RunAutomodOnLeaveEvt } from "./events/RunAutomodOnJoinLeaveEvt";
|
||||
import { RunAutomodOnMemberUpdate } from "./events/RunAutomodOnMemberUpdate";
|
||||
import { runAutomodOnCounterTrigger } from "./events/runAutomodOnCounterTrigger";
|
||||
import { runAutomodOnMessage } from "./events/runAutomodOnMessage";
|
||||
import { runAutomodOnModAction } from "./events/runAutomodOnModAction";
|
||||
import {
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
zAllowedMentions,
|
||||
zBoundedCharacters,
|
||||
zNullishToUndefined,
|
||||
zSnowflake
|
||||
zSnowflake,
|
||||
} from "../../../utils";
|
||||
import { erisAllowedMentionsToDjsMentionOptions } from "../../../utils/erisAllowedMentionsToDjsMentionOptions";
|
||||
import { messageIsEmpty } from "../../../utils/messageIsEmpty";
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
import z from "zod";
|
||||
import { convertDelayStringToMS, nonNullish, unique, zBoundedCharacters, zDelayString, zSnowflake } from "../../../utils";
|
||||
import {
|
||||
convertDelayStringToMS,
|
||||
nonNullish,
|
||||
unique,
|
||||
zBoundedCharacters,
|
||||
zDelayString,
|
||||
zSnowflake,
|
||||
} from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { zNotify } from "../constants";
|
||||
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||
import { automodAction } from "../helpers";
|
||||
import { zNotify } from "../constants";
|
||||
|
||||
const configSchema = z.strictObject({
|
||||
reason: zBoundedCharacters(0, 4000).nullable().default(null),
|
||||
|
|
|
@ -68,10 +68,7 @@ export const ChangePermsAction = automodAction({
|
|||
configSchema: z.strictObject({
|
||||
target: zBoundedCharacters(1, 2000),
|
||||
channel: zBoundedCharacters(1, 2000).nullable().default(null),
|
||||
perms: z.record(
|
||||
z.enum(allPermissionNames),
|
||||
z.boolean().nullable(),
|
||||
),
|
||||
perms: z.record(z.enum(allPermissionNames), z.boolean().nullable()),
|
||||
}),
|
||||
|
||||
async apply({ pluginData, contexts, actionConfig }) {
|
||||
|
|
|
@ -2,9 +2,9 @@ import z from "zod";
|
|||
import { asyncMap, nonNullish, resolveMember, unique, zBoundedCharacters, zSnowflake } from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { zNotify } from "../constants";
|
||||
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||
import { automodAction } from "../helpers";
|
||||
import { zNotify } from "../constants";
|
||||
|
||||
export const KickAction = automodAction({
|
||||
configSchema: z.strictObject({
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
import z from "zod";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import { convertDelayStringToMS, nonNullish, unique, zBoundedCharacters, zDelayString, zSnowflake } from "../../../utils";
|
||||
import {
|
||||
convertDelayStringToMS,
|
||||
nonNullish,
|
||||
unique,
|
||||
zBoundedCharacters,
|
||||
zDelayString,
|
||||
zSnowflake,
|
||||
} from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { MutesPlugin } from "../../Mutes/MutesPlugin";
|
||||
import { zNotify } from "../constants";
|
||||
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||
import { automodAction } from "../helpers";
|
||||
import { zNotify } from "../constants";
|
||||
|
||||
export const MuteAction = automodAction({
|
||||
configSchema: z.strictObject({
|
||||
|
@ -14,8 +21,14 @@ export const MuteAction = automodAction({
|
|||
duration: zDelayString.nullable().default(null),
|
||||
notify: zNotify.nullable().default(null),
|
||||
notifyChannel: zSnowflake.nullable().default(null),
|
||||
remove_roles_on_mute: z.union([z.boolean(), z.array(zSnowflake)]).nullable().default(null),
|
||||
restore_roles_on_mute: z.union([z.boolean(), z.array(zSnowflake)]).nullable().default(null),
|
||||
remove_roles_on_mute: z
|
||||
.union([z.boolean(), z.array(zSnowflake)])
|
||||
.nullable()
|
||||
.default(null),
|
||||
restore_roles_on_mute: z
|
||||
.union([z.boolean(), z.array(zSnowflake)])
|
||||
.nullable()
|
||||
.default(null),
|
||||
postInCaseLog: z.boolean().nullable().default(null),
|
||||
hide_case: z.boolean().nullable().default(false),
|
||||
}),
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
verboseChannelMention,
|
||||
zBoundedCharacters,
|
||||
zDelayString,
|
||||
zMessageContent
|
||||
zMessageContent,
|
||||
} from "../../../utils";
|
||||
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
|
||||
import { messageIsEmpty } from "../../../utils/messageIsEmpty";
|
||||
|
|
|
@ -2,9 +2,9 @@ import z from "zod";
|
|||
import { asyncMap, nonNullish, resolveMember, unique, zBoundedCharacters, zSnowflake } from "../../../utils";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { zNotify } from "../constants";
|
||||
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||
import { automodAction } from "../helpers";
|
||||
import { zNotify } from "../constants";
|
||||
|
||||
export const WarnAction = automodAction({
|
||||
configSchema: z.strictObject({
|
||||
|
|
|
@ -20,7 +20,4 @@ export enum RecentActionType {
|
|||
ThreadCreate,
|
||||
}
|
||||
|
||||
export const zNotify = z.union([
|
||||
z.literal("dm"),
|
||||
z.literal("channel"),
|
||||
]);
|
||||
export const zNotify = z.union([z.literal("dm"), z.literal("channel")]);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import z from "zod";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { humanizeDurationShort } from "../../../humanizeDurationShort";
|
||||
import { getBaseUrl } from "../../../pluginUtils";
|
||||
|
@ -7,7 +8,6 @@ import { automodTrigger } from "../helpers";
|
|||
import { findRecentSpam } from "./findRecentSpam";
|
||||
import { getMatchingMessageRecentActions } from "./getMatchingMessageRecentActions";
|
||||
import { getMessageSpamIdentifier } from "./getSpamIdentifier";
|
||||
import z from "zod";
|
||||
|
||||
interface TMessageSpamMatchResultType {
|
||||
archiveId: string;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import z, { ZodTypeAny } from "zod";
|
||||
import { Awaitable } from "../../utils/typeUtils";
|
||||
import { AutomodContext, AutomodPluginType } from "./types";
|
||||
import z, { ZodTypeAny } from "zod";
|
||||
|
||||
interface BaseAutomodTriggerMatchResult {
|
||||
extraContexts?: AutomodContext[];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { automodTrigger } from "../helpers";
|
||||
import z from "zod";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
interface AntiraidLevelTriggerResult {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import z from "zod";
|
||||
import { verboseChannelMention } from "../../../utils";
|
||||
import { automodTrigger } from "../helpers";
|
||||
import z from "zod";
|
||||
|
||||
interface AnyMessageResultType {}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { escapeInlineCode, Snowflake } from "discord.js";
|
||||
import z from "zod";
|
||||
import { extname } from "path";
|
||||
import z from "zod";
|
||||
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
|
@ -9,28 +9,30 @@ interface MatchResultType {
|
|||
mode: "blacklist" | "whitelist";
|
||||
}
|
||||
|
||||
const configSchema = z.strictObject({
|
||||
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
|
||||
blacklist_enabled: z.boolean().default(false),
|
||||
filetype_whitelist: z.array(z.string().max(32)).max(255).default([]),
|
||||
whitelist_enabled: z.boolean().default(false),
|
||||
}).transform((parsed, ctx) => {
|
||||
if (parsed.blacklist_enabled && parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Cannot have both blacklist and whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
if (! parsed.blacklist_enabled && ! parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Must have either blacklist or whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return parsed;
|
||||
});
|
||||
const configSchema = z
|
||||
.strictObject({
|
||||
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
|
||||
blacklist_enabled: z.boolean().default(false),
|
||||
filetype_whitelist: z.array(z.string().max(32)).max(255).default([]),
|
||||
whitelist_enabled: z.boolean().default(false),
|
||||
})
|
||||
.transform((parsed, ctx) => {
|
||||
if (parsed.blacklist_enabled && parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Cannot have both blacklist and whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
if (!parsed.blacklist_enabled && !parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Must have either blacklist or whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return parsed;
|
||||
});
|
||||
|
||||
export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
||||
configSchema,
|
||||
|
|
|
@ -26,12 +26,20 @@ const configSchema = z.strictObject({
|
|||
include_subdomains: z.boolean().default(true),
|
||||
include_words: z.array(z.string().max(2000)).max(700).optional(),
|
||||
exclude_words: z.array(z.string().max(2000)).max(700).optional(),
|
||||
include_regex: z.array(zRegex(z.string().max(2000))).max(512).optional(),
|
||||
exclude_regex: z.array(zRegex(z.string().max(2000))).max(512).optional(),
|
||||
phisherman: z.strictObject({
|
||||
include_suspected: z.boolean().optional(),
|
||||
include_verified: z.boolean().optional(),
|
||||
}).optional(),
|
||||
include_regex: z
|
||||
.array(zRegex(z.string().max(2000)))
|
||||
.max(512)
|
||||
.optional(),
|
||||
exclude_regex: z
|
||||
.array(zRegex(z.string().max(2000)))
|
||||
.max(512)
|
||||
.optional(),
|
||||
phisherman: z
|
||||
.strictObject({
|
||||
include_suspected: z.boolean().optional(),
|
||||
include_verified: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
only_real_links: z.boolean().default(true),
|
||||
match_messages: z.boolean().default(true),
|
||||
match_embeds: z.boolean().default(true),
|
||||
|
|
|
@ -8,28 +8,30 @@ interface MatchResultType {
|
|||
mode: "blacklist" | "whitelist";
|
||||
}
|
||||
|
||||
const configSchema = z.strictObject({
|
||||
mime_type_blacklist: z.array(z.string().max(255)).max(255).default([]),
|
||||
blacklist_enabled: z.boolean().default(false),
|
||||
mime_type_whitelist: z.array(z.string().max(255)).max(255).default([]),
|
||||
whitelist_enabled: z.boolean().default(false),
|
||||
}).transform((parsed, ctx) => {
|
||||
if (parsed.blacklist_enabled && parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Cannot have both blacklist and whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
if (! parsed.blacklist_enabled && ! parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Must have either blacklist or whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return parsed;
|
||||
});
|
||||
const configSchema = z
|
||||
.strictObject({
|
||||
mime_type_blacklist: z.array(z.string().max(255)).max(255).default([]),
|
||||
blacklist_enabled: z.boolean().default(false),
|
||||
mime_type_whitelist: z.array(z.string().max(255)).max(255).default([]),
|
||||
whitelist_enabled: z.boolean().default(false),
|
||||
})
|
||||
.transform((parsed, ctx) => {
|
||||
if (parsed.blacklist_enabled && parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Cannot have both blacklist and whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
if (!parsed.blacklist_enabled && !parsed.whitelist_enabled) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Must have either blacklist or whitelist enabled",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return parsed;
|
||||
});
|
||||
|
||||
export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
|
||||
configSchema,
|
||||
|
|
|
@ -8,10 +8,7 @@ interface RoleAddedMatchResult {
|
|||
matchedRoleId: string;
|
||||
}
|
||||
|
||||
const configSchema = z.union([
|
||||
zSnowflake,
|
||||
z.array(zSnowflake).max(255),
|
||||
]).default([]);
|
||||
const configSchema = z.union([zSnowflake, z.array(zSnowflake).max(255)]).default([]);
|
||||
|
||||
export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
||||
configSchema,
|
||||
|
|
|
@ -8,10 +8,7 @@ interface RoleAddedMatchResult {
|
|||
matchedRoleId: string;
|
||||
}
|
||||
|
||||
const configSchema = z.union([
|
||||
zSnowflake,
|
||||
z.array(zSnowflake).max(255),
|
||||
]).default([]);
|
||||
const configSchema = z.union([zSnowflake, z.array(zSnowflake).max(255)]).default([]);
|
||||
|
||||
export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
||||
configSchema,
|
||||
|
|
|
@ -19,58 +19,62 @@ import { availableTriggers } from "./triggers/availableTriggers";
|
|||
import Timeout = NodeJS.Timeout;
|
||||
|
||||
export type ZTriggersMapHelper = {
|
||||
[TriggerName in keyof typeof availableTriggers]: typeof availableTriggers[TriggerName]["configSchema"];
|
||||
[TriggerName in keyof typeof availableTriggers]: (typeof availableTriggers)[TriggerName]["configSchema"];
|
||||
};
|
||||
const zTriggersMap = z.strictObject(entries(availableTriggers).reduce((map, [triggerName, trigger]) => {
|
||||
map[triggerName] = trigger.configSchema;
|
||||
return map;
|
||||
}, {} as ZTriggersMapHelper)).partial();
|
||||
const zTriggersMap = z
|
||||
.strictObject(
|
||||
entries(availableTriggers).reduce((map, [triggerName, trigger]) => {
|
||||
map[triggerName] = trigger.configSchema;
|
||||
return map;
|
||||
}, {} as ZTriggersMapHelper),
|
||||
)
|
||||
.partial();
|
||||
|
||||
type ZActionsMapHelper = {
|
||||
[ActionName in keyof typeof availableActions]: typeof availableActions[ActionName]["configSchema"];
|
||||
[ActionName in keyof typeof availableActions]: (typeof availableActions)[ActionName]["configSchema"];
|
||||
};
|
||||
const zActionsMap = z.strictObject(entries(availableActions).reduce((map, [actionName, action]) => {
|
||||
// @ts-expect-error TS can't infer this properly but it works fine thanks to our helper
|
||||
map[actionName] = action.configSchema;
|
||||
return map;
|
||||
}, {} as ZActionsMapHelper)).partial();
|
||||
const zActionsMap = z
|
||||
.strictObject(
|
||||
entries(availableActions).reduce((map, [actionName, action]) => {
|
||||
// @ts-expect-error TS can't infer this properly but it works fine thanks to our helper
|
||||
map[actionName] = action.configSchema;
|
||||
return map;
|
||||
}, {} as ZActionsMapHelper),
|
||||
)
|
||||
.partial();
|
||||
|
||||
const zRule = z.strictObject({
|
||||
enabled: z.boolean().default(true),
|
||||
// Typed as "never" because you are not expected to supply this directly.
|
||||
// The transform instead picks it up from the property key and the output type is a string.
|
||||
name: z.never().optional().transform((_, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
if (! ruleName) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Automod rules must have names",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return ruleName;
|
||||
}),
|
||||
name: z
|
||||
.never()
|
||||
.optional()
|
||||
.transform((_, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
if (!ruleName) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Automod rules must have names",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return ruleName;
|
||||
}),
|
||||
presets: z.array(z.string().max(100)).max(25).default([]),
|
||||
affects_bots: z.boolean().default(false),
|
||||
affects_self: z.boolean().default(false),
|
||||
cooldown: zDelayString.nullable().default(null),
|
||||
allow_further_rules: z.boolean().default(false),
|
||||
triggers: z.array(zTriggersMap),
|
||||
actions: zActionsMap.refine(
|
||||
(v) => ! (v.clean && v.start_thread),
|
||||
{
|
||||
message: "Cannot have both clean and start_thread active at the same time",
|
||||
}
|
||||
),
|
||||
actions: zActionsMap.refine((v) => !(v.clean && v.start_thread), {
|
||||
message: "Cannot have both clean and start_thread active at the same time",
|
||||
}),
|
||||
});
|
||||
export type TRule = z.infer<typeof zRule>;
|
||||
|
||||
export const zAutomodConfig = z.strictObject({
|
||||
rules: zBoundedRecord(
|
||||
z.record(z.string().max(100), zRule),
|
||||
0,
|
||||
255,
|
||||
),
|
||||
rules: zBoundedRecord(z.record(z.string().max(100), zRule), 0, 255),
|
||||
antiraid_levels: z.array(z.string().max(100)).max(10),
|
||||
can_set_antiraid: z.boolean(),
|
||||
can_view_antiraid: z.boolean(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue