mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-07 16:05:01 +00:00
chore: format
This commit is contained in:
parent
6c55b98eee
commit
aaf4e02c5f
56 changed files with 282 additions and 255 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { EventEmitter } from "node:events";
|
|
||||||
import { CooldownManager } from "knub";
|
import { CooldownManager } from "knub";
|
||||||
|
import { EventEmitter } from "node:events";
|
||||||
import { RegExpWorker, TimeoutError } from "regexp-worker";
|
import { RegExpWorker, TimeoutError } from "regexp-worker";
|
||||||
import { MINUTES, SECONDS } from "./utils.js";
|
import { MINUTES, SECONDS } from "./utils.js";
|
||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
|
|
|
@ -73,7 +73,10 @@ function formatZodConfigSchema(schema: z.ZodType) {
|
||||||
return schema.def.values;
|
return schema.def.values;
|
||||||
}
|
}
|
||||||
if (isZodIntersection(schema)) {
|
if (isZodIntersection(schema)) {
|
||||||
return [formatZodConfigSchema(schema.def.left as z.ZodType), formatZodConfigSchema(schema.def.right as z.ZodType)].join(" & ");
|
return [
|
||||||
|
formatZodConfigSchema(schema.def.left as z.ZodType),
|
||||||
|
formatZodConfigSchema(schema.def.right as z.ZodType),
|
||||||
|
].join(" & ");
|
||||||
}
|
}
|
||||||
if (schema.def.type === "string") {
|
if (schema.def.type === "string") {
|
||||||
return "string";
|
return "string";
|
||||||
|
@ -131,7 +134,7 @@ export function initDocs(router: express.Router) {
|
||||||
config: cmd.config,
|
config: cmd.config,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const defaultOptions = (pluginInfo.plugin as any /* TODO */).defaultOptions || {};
|
const defaultOptions = (pluginInfo.plugin as any) /* TODO */.defaultOptions || {};
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
name: pluginInfo.plugin.name,
|
name: pluginInfo.plugin.name,
|
||||||
|
|
|
@ -28,12 +28,15 @@ export async function validateGuildConfig(config: any): Promise<string | null> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const plugin = pluginNameToPlugin.get(pluginName)!;
|
const plugin = pluginNameToPlugin.get(pluginName)!;
|
||||||
const configManager = new PluginConfigManager({}, {
|
const configManager = new PluginConfigManager(
|
||||||
configSchema: plugin.configSchema,
|
{},
|
||||||
defaultOverrides: plugin.defaultOverrides ?? [],
|
{
|
||||||
levels: {},
|
configSchema: plugin.configSchema,
|
||||||
customOverrideCriteriaFunctions: plugin.customOverrideCriteriaFunctions,
|
defaultOverrides: plugin.defaultOverrides ?? [],
|
||||||
});
|
levels: {},
|
||||||
|
customOverrideCriteriaFunctions: plugin.customOverrideCriteriaFunctions,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await configManager.init();
|
await configManager.init();
|
||||||
|
|
|
@ -37,6 +37,7 @@ const envType = z.object({
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|
||||||
PHISHERMAN_API_KEY: z.string().optional(),
|
PHISHERMAN_API_KEY: z.string().optional(),
|
||||||
|
FISHFISH_API_KEY: z.string().optional(),
|
||||||
|
|
||||||
DB_HOST: z.string().optional(),
|
DB_HOST: z.string().optional(),
|
||||||
DB_PORT: z.preprocess((v) => Number(v), z.number()).optional(),
|
DB_PORT: z.preprocess((v) => Number(v), z.number()).optional(),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
import fs from "node:fs";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
import { availableGuildPlugins } from "./plugins/availablePlugins.js";
|
import { availableGuildPlugins } from "./plugins/availablePlugins.js";
|
||||||
import { zZeppelinGuildConfig } from "./types.js";
|
import { zZeppelinGuildConfig } from "./types.js";
|
||||||
import { deepPartial } from "./utils/zodDeepPartial.js";
|
import { deepPartial } from "./utils/zodDeepPartial.js";
|
||||||
import fs from "node:fs";
|
|
||||||
|
|
||||||
const basePluginOverrideCriteriaSchema = z.strictObject({
|
const basePluginOverrideCriteriaSchema = z.strictObject({
|
||||||
channel: z
|
channel: z
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BaseChannel,
|
|
||||||
BitField,
|
BitField,
|
||||||
BitFieldResolvable,
|
BitFieldResolvable,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
|
@ -19,15 +18,21 @@ import {
|
||||||
MessageFlagsString,
|
MessageFlagsString,
|
||||||
ModalSubmitInteraction,
|
ModalSubmitInteraction,
|
||||||
PermissionsBitField,
|
PermissionsBitField,
|
||||||
SendableChannels,
|
|
||||||
TextBasedChannel,
|
TextBasedChannel,
|
||||||
User,
|
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { AnyPluginData, BasePluginData, CommandContext, ExtendedMatchParams, GuildPluginData, helpers, PluginConfigManager } from "knub";
|
import {
|
||||||
|
AnyPluginData,
|
||||||
|
BasePluginData,
|
||||||
|
CommandContext,
|
||||||
|
ExtendedMatchParams,
|
||||||
|
GuildPluginData,
|
||||||
|
helpers,
|
||||||
|
PluginConfigManager,
|
||||||
|
} from "knub";
|
||||||
|
import z from "zod/v4";
|
||||||
import { isStaff } from "./staff.js";
|
import { isStaff } from "./staff.js";
|
||||||
import { TZeppelinKnub } from "./types.js";
|
import { TZeppelinKnub } from "./types.js";
|
||||||
import { Tail } from "./utils/typeUtils.js";
|
import { Tail } from "./utils/typeUtils.js";
|
||||||
import z from "zod/v4";
|
|
||||||
|
|
||||||
const { getMemberLevel } = helpers;
|
const { getMemberLevel } = helpers;
|
||||||
|
|
||||||
|
@ -66,18 +71,14 @@ export type GenericCommandSource = Message | CommandInteraction | ModalSubmitInt
|
||||||
export function isContextInteraction(
|
export function isContextInteraction(
|
||||||
context: GenericCommandSource,
|
context: GenericCommandSource,
|
||||||
): context is CommandInteraction | ModalSubmitInteraction {
|
): context is CommandInteraction | ModalSubmitInteraction {
|
||||||
return (context instanceof CommandInteraction || context instanceof ModalSubmitInteraction);
|
return context instanceof CommandInteraction || context instanceof ModalSubmitInteraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isContextMessage(
|
export function isContextMessage(context: GenericCommandSource): context is Message {
|
||||||
context: GenericCommandSource,
|
return context instanceof Message;
|
||||||
): context is Message {
|
|
||||||
return (context instanceof Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getContextChannel(
|
export async function getContextChannel(context: GenericCommandSource): Promise<TextBasedChannel | null> {
|
||||||
context: GenericCommandSource,
|
|
||||||
): Promise<TextBasedChannel | null> {
|
|
||||||
if (isContextInteraction(context)) {
|
if (isContextInteraction(context)) {
|
||||||
return context.channel;
|
return context.channel;
|
||||||
}
|
}
|
||||||
|
@ -87,9 +88,7 @@ export async function getContextChannel(
|
||||||
throw new Error("Unknown context type");
|
throw new Error("Unknown context type");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getContextChannelId(
|
export function getContextChannelId(context: GenericCommandSource): string | null {
|
||||||
context: GenericCommandSource,
|
|
||||||
): string | null {
|
|
||||||
return context.channelId;
|
return context.channelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,13 +103,10 @@ export async function fetchContextChannel(context: GenericCommandSource) {
|
||||||
return (await context.guild.channels.fetch(channelId))!;
|
return (await context.guild.channels.fetch(channelId))!;
|
||||||
}
|
}
|
||||||
|
|
||||||
function flagsWithEphemeral<
|
function flagsWithEphemeral<TFlags extends string, TType extends number | bigint>(
|
||||||
TFlags extends string,
|
flags: BitFieldResolvable<TFlags, any>,
|
||||||
TType extends number | bigint
|
ephemeral: boolean,
|
||||||
>(flags: BitFieldResolvable<TFlags, any>, ephemeral: boolean): BitFieldResolvable<
|
): BitFieldResolvable<TFlags | Extract<MessageFlagsString, "Ephemeral">, TType | MessageFlags.Ephemeral> {
|
||||||
TFlags | Extract<MessageFlagsString, "Ephemeral">,
|
|
||||||
TType | MessageFlags.Ephemeral
|
|
||||||
> {
|
|
||||||
if (!ephemeral) {
|
if (!ephemeral) {
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +163,10 @@ export async function deleteContextResponse(response: ContextResponse): Promise<
|
||||||
await response.delete();
|
await response.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getConfigForContext<TPluginData extends BasePluginData<any>>(config: PluginConfigManager<TPluginData>, context: GenericCommandSource): Promise<z.output<TPluginData["_pluginType"]["configSchema"]>> {
|
export async function getConfigForContext<TPluginData extends BasePluginData<any>>(
|
||||||
|
config: PluginConfigManager<TPluginData>,
|
||||||
|
context: GenericCommandSource,
|
||||||
|
): Promise<z.output<TPluginData["_pluginType"]["configSchema"]>> {
|
||||||
if (context instanceof ChatInputCommandInteraction) {
|
if (context instanceof ChatInputCommandInteraction) {
|
||||||
// TODO: Support for modal interactions (here and Knub)
|
// TODO: Support for modal interactions (here and Knub)
|
||||||
return config.getForInteraction(context);
|
return config.getForInteraction(context);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GuildLogs } from "../../data/GuildLogs.js";
|
import { GuildLogs } from "../../data/GuildLogs.js";
|
||||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ChannelType, PermissionsBitField, Snowflake } from "discord.js";
|
import { PermissionsBitField, Snowflake } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { LogType } from "../../../data/LogType.js";
|
import { LogType } from "../../../data/LogType.js";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { escapeInlineCode } from "discord.js";
|
import { escapeInlineCode } from "discord.js";
|
||||||
|
import z from "zod/v4";
|
||||||
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils.js";
|
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils.js";
|
||||||
import { automodTrigger } from "../helpers.js";
|
import { automodTrigger } from "../helpers.js";
|
||||||
import z from "zod/v4";
|
|
||||||
|
|
||||||
interface MatchResultType {
|
interface MatchResultType {
|
||||||
matchedType: string;
|
matchedType: string;
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { escapeCodeBlock, InteractionEditReplyOptions, InteractionReplyOptions, MessageCreateOptions, MessageEditOptions } from "discord.js";
|
import {
|
||||||
|
escapeCodeBlock,
|
||||||
|
InteractionEditReplyOptions,
|
||||||
|
InteractionReplyOptions,
|
||||||
|
MessageCreateOptions,
|
||||||
|
MessageEditOptions,
|
||||||
|
} from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { CaseTypes } from "../../../data/CaseTypes.js";
|
import { CaseTypes } from "../../../data/CaseTypes.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, PluginOverride, guildPlugin } from "knub";
|
import { PluginOverride, guildPlugin } from "knub";
|
||||||
import { GuildLogs } from "../../data/GuildLogs.js";
|
import { GuildLogs } from "../../data/GuildLogs.js";
|
||||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
||||||
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners.js";
|
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners.js";
|
||||||
|
|
|
@ -18,7 +18,10 @@ export const zCensorConfig = z.strictObject({
|
||||||
domain_blacklist: z.array(zBoundedCharacters(0, 255)).nullable().default(null),
|
domain_blacklist: z.array(zBoundedCharacters(0, 255)).nullable().default(null),
|
||||||
blocked_tokens: z.array(zBoundedCharacters(0, 2000)).nullable().default(null),
|
blocked_tokens: z.array(zBoundedCharacters(0, 2000)).nullable().default(null),
|
||||||
blocked_words: z.array(zBoundedCharacters(0, 2000)).nullable().default(null),
|
blocked_words: z.array(zBoundedCharacters(0, 2000)).nullable().default(null),
|
||||||
blocked_regex: z.array(zRegex(z.string().max(1000))).nullable().default(null),
|
blocked_regex: z
|
||||||
|
.array(zRegex(z.string().max(1000)))
|
||||||
|
.nullable()
|
||||||
|
.default(null),
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface CensorPluginType extends BasePluginType {
|
export interface CensorPluginType extends BasePluginType {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { BasePluginType, guildPluginMessageCommand, pluginUtils } from "knub";
|
import { BasePluginType, guildPluginMessageCommand, pluginUtils } from "knub";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
|
|
||||||
export const zChannelArchiverPluginConfig = z.strictObject({});
|
export const zChannelArchiverPluginConfig = z.strictObject({});
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import {
|
import { Attachment, MessageMentionOptions, SendableChannels, TextBasedChannel } from "discord.js";
|
||||||
Attachment,
|
|
||||||
MessageMentionOptions,
|
|
||||||
SendableChannels,
|
|
||||||
TextBasedChannel
|
|
||||||
} from "discord.js";
|
|
||||||
import { guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GenericCommandSource, sendContextResponse } from "../../pluginUtils.js";
|
import { GenericCommandSource, sendContextResponse } from "../../pluginUtils.js";
|
||||||
import { errorMessage, successMessage } from "../../utils.js";
|
import { errorMessage, successMessage } from "../../utils.js";
|
||||||
|
@ -28,9 +23,7 @@ export const CommonPlugin = guildPlugin<CommonPluginType>()({
|
||||||
) => {
|
) => {
|
||||||
const emoji = getSuccessEmoji(pluginData);
|
const emoji = getSuccessEmoji(pluginData);
|
||||||
const formattedBody = successMessage(body, emoji);
|
const formattedBody = successMessage(body, emoji);
|
||||||
const content = allowedMentions
|
const content = allowedMentions ? { content: formattedBody, allowedMentions } : { content: formattedBody };
|
||||||
? { content: formattedBody, allowedMentions }
|
|
||||||
: { content: formattedBody };
|
|
||||||
if ("isSendable" in context) {
|
if ("isSendable" in context) {
|
||||||
return context.send(content);
|
return context.send(content);
|
||||||
}
|
}
|
||||||
|
@ -46,9 +39,7 @@ export const CommonPlugin = guildPlugin<CommonPluginType>()({
|
||||||
) => {
|
) => {
|
||||||
const emoji = getErrorEmoji(pluginData);
|
const emoji = getErrorEmoji(pluginData);
|
||||||
const formattedBody = errorMessage(body, emoji);
|
const formattedBody = errorMessage(body, emoji);
|
||||||
const content = allowedMentions
|
const content = allowedMentions ? { content: formattedBody, allowedMentions } : { content: formattedBody };
|
||||||
? { content: formattedBody, allowedMentions }
|
|
||||||
: { content: formattedBody };
|
|
||||||
if ("isSendable" in context) {
|
if ("isSendable" in context) {
|
||||||
return context.send(content);
|
return context.send(content);
|
||||||
}
|
}
|
||||||
|
@ -67,9 +58,7 @@ export const CommonPlugin = guildPlugin<CommonPluginType>()({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!channel.isSendable()) {
|
if (!channel.isSendable()) {
|
||||||
throw new Error(
|
throw new Error("Passed attachment storage channel is not sendable");
|
||||||
"Passed attachment storage channel is not sendable",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel.send({
|
return channel.send({
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, PluginOverride, guildPlugin } from "knub";
|
import { PluginOverride, guildPlugin } from "knub";
|
||||||
import { GuildCases } from "../../data/GuildCases.js";
|
import { GuildCases } from "../../data/GuildCases.js";
|
||||||
import { CasesPlugin } from "../Cases/CasesPlugin.js";
|
import { CasesPlugin } from "../Cases/CasesPlugin.js";
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
||||||
|
|
|
@ -62,7 +62,11 @@ export async function cleanAction(
|
||||||
|
|
||||||
if (fetchMessagesResult.messages.length > 0) {
|
if (fetchMessagesResult.messages.length > 0) {
|
||||||
await utility.cleanMessages(targetChannel, fetchMessagesResult.messages, interaction.user);
|
await utility.cleanMessages(targetChannel, fetchMessagesResult.messages, interaction.user);
|
||||||
interaction.editReply(`Cleaned ${fetchMessagesResult.messages.length} ${fetchMessagesResult.messages.length === 1 ? "message" : "messages"}`);
|
interaction.editReply(
|
||||||
|
`Cleaned ${fetchMessagesResult.messages.length} ${
|
||||||
|
fetchMessagesResult.messages.length === 1 ? "message" : "messages"
|
||||||
|
}`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
interaction.editReply("No messages to clean");
|
interaction.editReply("No messages to clean");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import { PluginOptions, PluginOverride, guildPlugin } from "knub";
|
import { PluginOverride, guildPlugin } from "knub";
|
||||||
import { GuildCounters } from "../../data/GuildCounters.js";
|
import { GuildCounters } from "../../data/GuildCounters.js";
|
||||||
import { buildCounterConditionString, CounterTrigger, getReverseCounterComparisonOp, parseCounterConditionString } from "../../data/entities/CounterTrigger.js";
|
import {
|
||||||
|
CounterTrigger,
|
||||||
|
buildCounterConditionString,
|
||||||
|
getReverseCounterComparisonOp,
|
||||||
|
parseCounterConditionString,
|
||||||
|
} from "../../data/entities/CounterTrigger.js";
|
||||||
import { makePublicFn } from "../../pluginUtils.js";
|
import { makePublicFn } from "../../pluginUtils.js";
|
||||||
import { MINUTES, convertDelayStringToMS } from "../../utils.js";
|
import { MINUTES, convertDelayStringToMS } from "../../utils.js";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
|
@ -98,7 +103,9 @@ export const CountersPlugin = guildPlugin<CountersPluginType>()({
|
||||||
// Initialize triggers
|
// Initialize triggers
|
||||||
for (const [triggerName, trigger] of Object.entries(counter.triggers)) {
|
for (const [triggerName, trigger] of Object.entries(counter.triggers)) {
|
||||||
const parsedCondition = parseCounterConditionString(trigger.condition)!;
|
const parsedCondition = parseCounterConditionString(trigger.condition)!;
|
||||||
const rawReverseCondition = trigger.reverse_condition || buildCounterConditionString(getReverseCounterComparisonOp(parsedCondition[0]), parsedCondition[1]);
|
const rawReverseCondition =
|
||||||
|
trigger.reverse_condition ||
|
||||||
|
buildCounterConditionString(getReverseCounterComparisonOp(parsedCondition[0]), parsedCondition[1]);
|
||||||
const parsedReverseCondition = parseCounterConditionString(rawReverseCondition)!;
|
const parsedReverseCondition = parseCounterConditionString(rawReverseCondition)!;
|
||||||
const counterTrigger = await state.counters.initCounterTrigger(
|
const counterTrigger = await state.counters.initCounterTrigger(
|
||||||
dbCounter.id,
|
dbCounter.id,
|
||||||
|
|
|
@ -15,19 +15,18 @@ import Timeout = NodeJS.Timeout;
|
||||||
const MAX_COUNTERS = 5;
|
const MAX_COUNTERS = 5;
|
||||||
const MAX_TRIGGERS_PER_COUNTER = 5;
|
const MAX_TRIGGERS_PER_COUNTER = 5;
|
||||||
|
|
||||||
export const zTrigger = z
|
export const zTrigger = z.strictObject({
|
||||||
.strictObject({
|
// Dummy type because name gets replaced by the property key in transform()
|
||||||
// Dummy type because name gets replaced by the property key in transform()
|
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
|
||||||
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
|
condition: zBoundedCharacters(1, 64).refine((str) => parseCounterConditionString(str) !== null, {
|
||||||
condition: zBoundedCharacters(1, 64).refine((str) => parseCounterConditionString(str) !== null, {
|
message: "Invalid counter trigger condition",
|
||||||
message: "Invalid counter trigger condition",
|
}),
|
||||||
}),
|
reverse_condition: zBoundedCharacters(1, 64)
|
||||||
reverse_condition: zBoundedCharacters(1, 64)
|
.refine((str) => parseCounterConditionString(str) !== null, {
|
||||||
.refine((str) => parseCounterConditionString(str) !== null, {
|
message: "Invalid counter trigger reverse condition",
|
||||||
message: "Invalid counter trigger reverse condition",
|
})
|
||||||
})
|
.optional(),
|
||||||
.optional(),
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const zTriggerFromString = zBoundedCharacters(0, 100).transform((val, ctx) => {
|
const zTriggerFromString = zBoundedCharacters(0, 100).transform((val, ctx) => {
|
||||||
const parsedCondition = parseCounterConditionString(val);
|
const parsedCondition = parseCounterConditionString(val);
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { Message } from "discord.js";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { TemplateSafeValueContainer } from "../../../templateFormatter.js";
|
import { TemplateSafeValueContainer } from "../../../templateFormatter.js";
|
||||||
import { ActionError } from "../ActionError.js";
|
import { ActionError } from "../ActionError.js";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Guild } from "discord.js";
|
import { Guild } from "discord.js";
|
||||||
import { BasePluginType, GlobalPluginData, globalPlugin, globalPluginEventListener } from "knub";
|
import { GlobalPluginData, globalPlugin, globalPluginEventListener } from "knub";
|
||||||
import { AllowedGuilds } from "../../data/AllowedGuilds.js";
|
import { AllowedGuilds } from "../../data/AllowedGuilds.js";
|
||||||
import { Configs } from "../../data/Configs.js";
|
import { Configs } from "../../data/Configs.js";
|
||||||
import { env } from "../../env.js";
|
import { env } from "../../env.js";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import z from "zod/v4";
|
|
||||||
import { Queue } from "../../Queue.js";
|
import { Queue } from "../../Queue.js";
|
||||||
import { Webhooks } from "../../data/Webhooks.js";
|
import { Webhooks } from "../../data/Webhooks.js";
|
||||||
import { makePublicFn } from "../../pluginUtils.js";
|
import { makePublicFn } from "../../pluginUtils.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { onGuildEvent } from "../../data/GuildEvents.js";
|
import { onGuildEvent } from "../../data/GuildEvents.js";
|
||||||
import { GuildVCAlerts } from "../../data/GuildVCAlerts.js";
|
import { GuildVCAlerts } from "../../data/GuildVCAlerts.js";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
import { SaveMessagesToDBCmd } from "./commands/SaveMessagesToDB.js";
|
import { SaveMessagesToDBCmd } from "./commands/SaveMessagesToDB.js";
|
||||||
|
|
|
@ -31,7 +31,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const member = msg.member || await msg.guild.members.fetch(msg.author.id);
|
const member = msg.member || (await msg.guild.members.fetch(msg.author.id));
|
||||||
|
|
||||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||||
let mod = member;
|
let mod = member;
|
||||||
|
|
|
@ -41,7 +41,7 @@ export const BanMsgCmd = modActionsMsgCmd({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const member = msg.member || await msg.guild.members.fetch(msg.author.id);
|
const member = msg.member || (await msg.guild.members.fetch(msg.author.id));
|
||||||
|
|
||||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||||
let mod = member;
|
let mod = member;
|
||||||
|
|
|
@ -48,12 +48,7 @@ export async function actualDeleteCaseCmd(
|
||||||
content: "Delete the following case? Answer 'Yes' to continue, 'No' to cancel.",
|
content: "Delete the following case? Answer 'Yes' to continue, 'No' to cancel.",
|
||||||
});
|
});
|
||||||
|
|
||||||
const reply = await helpers.waitForReply(
|
const reply = await helpers.waitForReply(pluginData.client, channel, author.id, 15 * SECONDS);
|
||||||
pluginData.client,
|
|
||||||
channel,
|
|
||||||
author.id,
|
|
||||||
15 * SECONDS,
|
|
||||||
);
|
|
||||||
const normalizedReply = (reply?.content || "").toLowerCase().trim();
|
const normalizedReply = (reply?.content || "").toLowerCase().trim();
|
||||||
if (normalizedReply !== "yes" && normalizedReply !== "y") {
|
if (normalizedReply !== "yes" && normalizedReply !== "y") {
|
||||||
sendContextResponse(context, "Cancelled. Case was not deleted.");
|
sendContextResponse(context, "Cancelled. Case was not deleted.");
|
||||||
|
|
|
@ -39,7 +39,7 @@ export const ForceMuteMsgCmd = modActionsMsgCmd({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authorMember = await resolveMessageMember(msg)
|
const authorMember = await resolveMessageMember(msg);
|
||||||
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||||
|
|
||||||
// Make sure we're allowed to mute this user
|
// Make sure we're allowed to mute this user
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { hasPermission } from "knub/helpers";
|
import { hasPermission } from "knub/helpers";
|
||||||
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
||||||
|
import { resolveMessageMember } from "../../../../pluginUtils.js";
|
||||||
import { resolveUser } from "../../../../utils.js";
|
import { resolveUser } from "../../../../utils.js";
|
||||||
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs.js";
|
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs.js";
|
||||||
import { modActionsMsgCmd } from "../../types.js";
|
import { modActionsMsgCmd } from "../../types.js";
|
||||||
import { actualKickCmd } from "./actualKickCmd.js";
|
import { actualKickCmd } from "./actualKickCmd.js";
|
||||||
import { resolveMessageMember } from "../../../../pluginUtils.js";
|
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
mod: ct.member({ option: true }),
|
mod: ct.member({ option: true }),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { waitForReply } from "knub/helpers";
|
import { waitForReply } from "knub/helpers";
|
||||||
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
||||||
import { getContextChannel, resolveMessageMember, sendContextResponse } from "../../../../pluginUtils.js";
|
import { resolveMessageMember } from "../../../../pluginUtils.js";
|
||||||
import { modActionsMsgCmd } from "../../types.js";
|
import { modActionsMsgCmd } from "../../types.js";
|
||||||
import { actualMassBanCmd } from "./actualMassBanCmd.js";
|
import { actualMassBanCmd } from "./actualMassBanCmd.js";
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,14 @@ import { GuildPluginData } from "knub";
|
||||||
import { CaseTypes } from "../../../../data/CaseTypes.js";
|
import { CaseTypes } from "../../../../data/CaseTypes.js";
|
||||||
import { LogType } from "../../../../data/LogType.js";
|
import { LogType } from "../../../../data/LogType.js";
|
||||||
import { humanizeDurationShort } from "../../../../humanizeDuration.js";
|
import { humanizeDurationShort } from "../../../../humanizeDuration.js";
|
||||||
import { canActOn, deleteContextResponse, editContextResponse, getConfigForContext, getContextChannel, isContextInteraction, sendContextResponse } from "../../../../pluginUtils.js";
|
import {
|
||||||
|
canActOn,
|
||||||
|
deleteContextResponse,
|
||||||
|
editContextResponse,
|
||||||
|
getConfigForContext,
|
||||||
|
isContextInteraction,
|
||||||
|
sendContextResponse,
|
||||||
|
} from "../../../../pluginUtils.js";
|
||||||
import { DAYS, MINUTES, SECONDS, noop } from "../../../../utils.js";
|
import { DAYS, MINUTES, SECONDS, noop } from "../../../../utils.js";
|
||||||
import { CasesPlugin } from "../../../Cases/CasesPlugin.js";
|
import { CasesPlugin } from "../../../Cases/CasesPlugin.js";
|
||||||
import { LogsPlugin } from "../../../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../../../Logs/LogsPlugin.js";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { waitForReply } from "knub/helpers";
|
import { waitForReply } from "knub/helpers";
|
||||||
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
||||||
import { getContextChannel, resolveMessageMember, sendContextResponse } from "../../../../pluginUtils.js";
|
import { resolveMessageMember } from "../../../../pluginUtils.js";
|
||||||
import { modActionsMsgCmd } from "../../types.js";
|
import { modActionsMsgCmd } from "../../types.js";
|
||||||
import { actualMassMuteCmd } from "./actualMassMuteCmd.js";
|
import { actualMassMuteCmd } from "./actualMassMuteCmd.js";
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { GuildPluginData } from "knub";
|
||||||
import { LogType } from "../../../../data/LogType.js";
|
import { LogType } from "../../../../data/LogType.js";
|
||||||
import { logger } from "../../../../logger.js";
|
import { logger } from "../../../../logger.js";
|
||||||
import { canActOn, deleteContextResponse, isContextInteraction, sendContextResponse } from "../../../../pluginUtils.js";
|
import { canActOn, deleteContextResponse, isContextInteraction, sendContextResponse } from "../../../../pluginUtils.js";
|
||||||
|
import { noop } from "../../../../utils.js";
|
||||||
import { LogsPlugin } from "../../../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../../../Logs/LogsPlugin.js";
|
||||||
import { MutesPlugin } from "../../../Mutes/MutesPlugin.js";
|
import { MutesPlugin } from "../../../Mutes/MutesPlugin.js";
|
||||||
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction.js";
|
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction.js";
|
||||||
|
@ -11,7 +12,6 @@ import {
|
||||||
formatReasonWithMessageLinkForAttachments,
|
formatReasonWithMessageLinkForAttachments,
|
||||||
} from "../../functions/formatReasonForAttachments.js";
|
} from "../../functions/formatReasonForAttachments.js";
|
||||||
import { ModActionsPluginType } from "../../types.js";
|
import { ModActionsPluginType } from "../../types.js";
|
||||||
import { noop } from "../../../../utils.js";
|
|
||||||
|
|
||||||
export async function actualMassMuteCmd(
|
export async function actualMassMuteCmd(
|
||||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { waitForReply } from "knub/helpers";
|
import { waitForReply } from "knub/helpers";
|
||||||
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
|
||||||
import { getContextChannel, resolveMessageMember, sendContextResponse } from "../../../../pluginUtils.js";
|
import { resolveMessageMember } from "../../../../pluginUtils.js";
|
||||||
import { modActionsMsgCmd } from "../../types.js";
|
import { modActionsMsgCmd } from "../../types.js";
|
||||||
import { actualMassUnbanCmd } from "./actualMassUnbanCmd.js";
|
import { actualMassUnbanCmd } from "./actualMassUnbanCmd.js";
|
||||||
|
|
||||||
|
|
|
@ -30,16 +30,28 @@ export const zModActionsConfig = z.strictObject({
|
||||||
message_on_ban: z.boolean().default(false),
|
message_on_ban: z.boolean().default(false),
|
||||||
message_channel: z.nullable(z.string()).default(null),
|
message_channel: z.nullable(z.string()).default(null),
|
||||||
warn_message: z.nullable(z.string()).default("You have received a warning on the {guildName} server: {reason}"),
|
warn_message: z.nullable(z.string()).default("You have received a warning on the {guildName} server: {reason}"),
|
||||||
kick_message: z.nullable(z.string()).default("You have been kicked from the {guildName} server. Reason given: {reason}"),
|
kick_message: z
|
||||||
ban_message: z.nullable(z.string()).default("You have been banned from the {guildName} server. Reason given: {reason}"),
|
.nullable(z.string())
|
||||||
tempban_message: z.nullable(z.string()).default("You have been banned from the {guildName} server for {banTime}. Reason given: {reason}"),
|
.default("You have been kicked from the {guildName} server. Reason given: {reason}"),
|
||||||
|
ban_message: z
|
||||||
|
.nullable(z.string())
|
||||||
|
.default("You have been banned from the {guildName} server. Reason given: {reason}"),
|
||||||
|
tempban_message: z
|
||||||
|
.nullable(z.string())
|
||||||
|
.default("You have been banned from the {guildName} server for {banTime}. Reason given: {reason}"),
|
||||||
alert_on_rejoin: z.boolean().default(false),
|
alert_on_rejoin: z.boolean().default(false),
|
||||||
alert_channel: z.nullable(z.string()).default(null),
|
alert_channel: z.nullable(z.string()).default(null),
|
||||||
warn_notify_enabled: z.boolean().default(false),
|
warn_notify_enabled: z.boolean().default(false),
|
||||||
warn_notify_threshold: z.number().default(5),
|
warn_notify_threshold: z.number().default(5),
|
||||||
warn_notify_message: z.string().default("The user already has **{priorWarnings}** warnings!\n Please check their prior cases and assess whether or not to warn anyways.\n Proceed with the warning?"),
|
warn_notify_message: z
|
||||||
|
.string()
|
||||||
|
.default(
|
||||||
|
"The user already has **{priorWarnings}** warnings!\n Please check their prior cases and assess whether or not to warn anyways.\n Proceed with the warning?",
|
||||||
|
),
|
||||||
ban_delete_message_days: z.number().default(1),
|
ban_delete_message_days: z.number().default(1),
|
||||||
attachment_link_reaction: z.nullable(z.union([z.literal("none"), z.literal("warn"), z.literal("restrict")])).default("warn"),
|
attachment_link_reaction: z
|
||||||
|
.nullable(z.union([z.literal("none"), z.literal("warn"), z.literal("restrict")]))
|
||||||
|
.default("warn"),
|
||||||
can_note: z.boolean().default(false),
|
can_note: z.boolean().default(false),
|
||||||
can_warn: z.boolean().default(false),
|
can_warn: z.boolean().default(false),
|
||||||
can_mute: z.boolean().default(false),
|
can_mute: z.boolean().default(false),
|
||||||
|
|
|
@ -23,7 +23,10 @@ export const zMutesConfig = z.strictObject({
|
||||||
message_on_update: z.boolean().default(false),
|
message_on_update: z.boolean().default(false),
|
||||||
message_channel: z.string().nullable().default(null),
|
message_channel: z.string().nullable().default(null),
|
||||||
mute_message: z.string().nullable().default("You have been muted on the {guildName} server. Reason given: {reason}"),
|
mute_message: z.string().nullable().default("You have been muted on the {guildName} server. Reason given: {reason}"),
|
||||||
timed_mute_message: z.string().nullable().default("You have been muted on the {guildName} server for {time}. Reason given: {reason}"),
|
timed_mute_message: z
|
||||||
|
.string()
|
||||||
|
.nullable()
|
||||||
|
.default("You have been muted on the {guildName} server for {time}. Reason given: {reason}"),
|
||||||
update_mute_message: z.string().nullable().default("Your mute on the {guildName} server has been updated to {time}."),
|
update_mute_message: z.string().nullable().default("Your mute on the {guildName} server has been updated to {time}."),
|
||||||
remove_roles_on_mute: z.union([z.boolean(), z.array(zSnowflake)]).default(false),
|
remove_roles_on_mute: z.union([z.boolean(), z.array(zSnowflake)]).default(false),
|
||||||
restore_roles_on_mute: z.union([z.boolean(), z.array(zSnowflake)]).default(false),
|
restore_roles_on_mute: z.union([z.boolean(), z.array(zSnowflake)]).default(false),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { Queue } from "../../Queue.js";
|
import { Queue } from "../../Queue.js";
|
||||||
import { GuildNicknameHistory } from "../../data/GuildNicknameHistory.js";
|
import { GuildNicknameHistory } from "../../data/GuildNicknameHistory.js";
|
||||||
import { UsernameHistory } from "../../data/UsernameHistory.js";
|
import { UsernameHistory } from "../../data/UsernameHistory.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GuildLogs } from "../../data/GuildLogs.js";
|
import { GuildLogs } from "../../data/GuildLogs.js";
|
||||||
import { GuildPersistedData } from "../../data/GuildPersistedData.js";
|
import { GuildPersistedData } from "../../data/GuildPersistedData.js";
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { Queue } from "../../Queue.js";
|
import { Queue } from "../../Queue.js";
|
||||||
import { GuildReactionRoles } from "../../data/GuildReactionRoles.js";
|
import { GuildReactionRoles } from "../../data/GuildReactionRoles.js";
|
||||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { Snowflake } from "discord.js";
|
import { Snowflake } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||||
|
import { resolveMessageMember } from "../../../pluginUtils.js";
|
||||||
import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils.js";
|
import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils.js";
|
||||||
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
||||||
import { TReactionRolePair, reactionRolesCmd } from "../types.js";
|
import { TReactionRolePair, reactionRolesCmd } from "../types.js";
|
||||||
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage.js";
|
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage.js";
|
||||||
import { resolveMessageMember } from "../../../pluginUtils.js";
|
|
||||||
|
|
||||||
const CLEAR_ROLES_EMOJI = "❌";
|
const CLEAR_ROLES_EMOJI = "❌";
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { onGuildEvent } from "../../data/GuildEvents.js";
|
import { onGuildEvent } from "../../data/GuildEvents.js";
|
||||||
import { GuildReminders } from "../../data/GuildReminders.js";
|
import { GuildReminders } from "../../data/GuildReminders.js";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GuildLogs } from "../../data/GuildLogs.js";
|
import { GuildLogs } from "../../data/GuildLogs.js";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { CooldownManager, PluginOptions, guildPlugin } from "knub";
|
import { CooldownManager, guildPlugin } from "knub";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
import { RoleAddCmd } from "./commands/RoleAddCmd.js";
|
import { RoleAddCmd } from "./commands/RoleAddCmd.js";
|
||||||
import { RoleHelpCmd } from "./commands/RoleHelpCmd.js";
|
import { RoleHelpCmd } from "./commands/RoleHelpCmd.js";
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { Role, Snowflake } from "discord.js";
|
import { Role, Snowflake } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||||
|
import { resolveMessageMember } from "../../../pluginUtils.js";
|
||||||
import { memberRolesLock } from "../../../utils/lockNameHelpers.js";
|
import { memberRolesLock } from "../../../utils/lockNameHelpers.js";
|
||||||
import { selfGrantableRolesCmd } from "../types.js";
|
import { selfGrantableRolesCmd } from "../types.js";
|
||||||
import { findMatchingRoles } from "../util/findMatchingRoles.js";
|
import { findMatchingRoles } from "../util/findMatchingRoles.js";
|
||||||
import { getApplyingEntries } from "../util/getApplyingEntries.js";
|
import { getApplyingEntries } from "../util/getApplyingEntries.js";
|
||||||
import { normalizeRoleNames } from "../util/normalizeRoleNames.js";
|
import { normalizeRoleNames } from "../util/normalizeRoleNames.js";
|
||||||
import { splitRoleNames } from "../util/splitRoleNames.js";
|
import { splitRoleNames } from "../util/splitRoleNames.js";
|
||||||
import { resolveMessageMember } from "../../../pluginUtils.js";
|
|
||||||
|
|
||||||
export const RoleAddCmd = selfGrantableRolesCmd({
|
export const RoleAddCmd = selfGrantableRolesCmd({
|
||||||
trigger: ["role", "role add"],
|
trigger: ["role", "role add"],
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { Snowflake } from "discord.js";
|
import { Snowflake } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||||
|
import { resolveMessageMember } from "../../../pluginUtils.js";
|
||||||
import { memberRolesLock } from "../../../utils/lockNameHelpers.js";
|
import { memberRolesLock } from "../../../utils/lockNameHelpers.js";
|
||||||
import { selfGrantableRolesCmd } from "../types.js";
|
import { selfGrantableRolesCmd } from "../types.js";
|
||||||
import { findMatchingRoles } from "../util/findMatchingRoles.js";
|
import { findMatchingRoles } from "../util/findMatchingRoles.js";
|
||||||
import { getApplyingEntries } from "../util/getApplyingEntries.js";
|
import { getApplyingEntries } from "../util/getApplyingEntries.js";
|
||||||
import { normalizeRoleNames } from "../util/normalizeRoleNames.js";
|
import { normalizeRoleNames } from "../util/normalizeRoleNames.js";
|
||||||
import { splitRoleNames } from "../util/splitRoleNames.js";
|
import { splitRoleNames } from "../util/splitRoleNames.js";
|
||||||
import { resolveMessageMember } from "../../../pluginUtils.js";
|
|
||||||
|
|
||||||
export const RoleRemoveCmd = selfGrantableRolesCmd({
|
export const RoleRemoveCmd = selfGrantableRolesCmd({
|
||||||
trigger: "role remove",
|
trigger: "role remove",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { MessageCreateOptions } from "discord.js";
|
import { MessageCreateOptions } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||||
import { logger } from "../../../logger.js";
|
import { logger } from "../../../logger.js";
|
||||||
|
import { resolveMessageMember } from "../../../pluginUtils.js";
|
||||||
import { TemplateParseError } from "../../../templateFormatter.js";
|
import { TemplateParseError } from "../../../templateFormatter.js";
|
||||||
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects.js";
|
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects.js";
|
||||||
import { tagsCmd } from "../types.js";
|
import { tagsCmd } from "../types.js";
|
||||||
import { renderTagBody } from "../util/renderTagBody.js";
|
import { renderTagBody } from "../util/renderTagBody.js";
|
||||||
import { resolveMessageMember } from "../../../pluginUtils.js";
|
|
||||||
|
|
||||||
export const TagEvalCmd = tagsCmd({
|
export const TagEvalCmd = tagsCmd({
|
||||||
trigger: "tag eval",
|
trigger: "tag eval",
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GuildMemberTimezones } from "../../data/GuildMemberTimezones.js";
|
import { GuildMemberTimezones } from "../../data/GuildMemberTimezones.js";
|
||||||
import { makePublicFn } from "../../pluginUtils.js";
|
import { makePublicFn } from "../../pluginUtils.js";
|
||||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||||
import { ResetTimezoneCmd } from "./commands/ResetTimezoneCmd.js";
|
import { ResetTimezoneCmd } from "./commands/ResetTimezoneCmd.js";
|
||||||
import { SetTimezoneCmd } from "./commands/SetTimezoneCmd.js";
|
import { SetTimezoneCmd } from "./commands/SetTimezoneCmd.js";
|
||||||
import { ViewTimezoneCmd } from "./commands/ViewTimezoneCmd.js";
|
import { ViewTimezoneCmd } from "./commands/ViewTimezoneCmd.js";
|
||||||
import { defaultDateFormats } from "./defaultDateFormats.js";
|
|
||||||
import { getDateFormat } from "./functions/getDateFormat.js";
|
import { getDateFormat } from "./functions/getDateFormat.js";
|
||||||
import { getGuildTz } from "./functions/getGuildTz.js";
|
import { getGuildTz } from "./functions/getGuildTz.js";
|
||||||
import { getMemberTz } from "./functions/getMemberTz.js";
|
import { getMemberTz } from "./functions/getMemberTz.js";
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { Snowflake, TextChannel } from "discord.js";
|
import { Snowflake, TextChannel } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||||
|
import { resolveMessageMember } from "../../../pluginUtils.js";
|
||||||
import { messageLink } from "../../../utils.js";
|
import { messageLink } from "../../../utils.js";
|
||||||
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
||||||
import { utilityCmd } from "../types.js";
|
import { utilityCmd } from "../types.js";
|
||||||
import { resolveMessageMember } from "../../../pluginUtils.js";
|
|
||||||
|
|
||||||
export const ContextCmd = utilityCmd({
|
export const ContextCmd = utilityCmd({
|
||||||
trigger: "context",
|
trigger: "context",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Snowflake } from "discord.js";
|
import { Snowflake } from "discord.js";
|
||||||
import { getChannelId, getRoleId } from "knub/helpers";
|
import { getChannelId, getRoleId } from "knub/helpers";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||||
|
import { resolveMessageMember } from "../../../pluginUtils.js";
|
||||||
import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils.js";
|
import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils.js";
|
||||||
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
||||||
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget.js";
|
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget.js";
|
||||||
|
@ -15,7 +16,6 @@ import { getServerInfoEmbed } from "../functions/getServerInfoEmbed.js";
|
||||||
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed.js";
|
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed.js";
|
||||||
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed.js";
|
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed.js";
|
||||||
import { utilityCmd } from "../types.js";
|
import { utilityCmd } from "../types.js";
|
||||||
import { resolveMessageMember } from "../../../pluginUtils.js";
|
|
||||||
|
|
||||||
export const InfoCmd = utilityCmd({
|
export const InfoCmd = utilityCmd({
|
||||||
trigger: "info",
|
trigger: "info",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { GuildPluginData } from "knub";
|
|
||||||
import { UtilityPluginType } from "../types.js";
|
|
||||||
import { GuildBasedChannel, Snowflake, TextBasedChannel, User } from "discord.js";
|
import { GuildBasedChannel, Snowflake, TextBasedChannel, User } from "discord.js";
|
||||||
|
import { GuildPluginData } from "knub";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
|
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
|
||||||
import { LogType } from "../../../data/LogType.js";
|
import { LogType } from "../../../data/LogType.js";
|
||||||
import { chunkArray } from "../../../utils.js";
|
|
||||||
import { getBaseUrl } from "../../../pluginUtils.js";
|
import { getBaseUrl } from "../../../pluginUtils.js";
|
||||||
|
import { chunkArray } from "../../../utils.js";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../../Logs/LogsPlugin.js";
|
||||||
|
import { UtilityPluginType } from "../types.js";
|
||||||
|
|
||||||
export async function cleanMessages(
|
export async function cleanMessages(
|
||||||
pluginData: GuildPluginData<UtilityPluginType>,
|
pluginData: GuildPluginData<UtilityPluginType>,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { GuildBasedChannel, Message, OmitPartialGroupDMChannel, Snowflake, TextBasedChannel } from "discord.js";
|
import { GuildBasedChannel, Message, OmitPartialGroupDMChannel, Snowflake, TextBasedChannel } from "discord.js";
|
||||||
import { DAYS, getInviteCodesInString } from "../../../utils.js";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { UtilityPluginType } from "../types.js";
|
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
|
||||||
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp.js";
|
|
||||||
import { humanizeDurationShort } from "../../../humanizeDuration.js";
|
import { humanizeDurationShort } from "../../../humanizeDuration.js";
|
||||||
import { allowTimeout } from "../../../RegExpRunner.js";
|
import { allowTimeout } from "../../../RegExpRunner.js";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
|
import { DAYS, getInviteCodesInString } from "../../../utils.js";
|
||||||
|
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp.js";
|
||||||
|
import { UtilityPluginType } from "../types.js";
|
||||||
|
|
||||||
const MAX_CLEAN_COUNT = 300;
|
const MAX_CLEAN_COUNT = 300;
|
||||||
const MAX_CLEAN_TIME = 1 * DAYS;
|
const MAX_CLEAN_TIME = 1 * DAYS;
|
||||||
|
@ -33,7 +33,11 @@ export interface ErrorResult {
|
||||||
|
|
||||||
export type FetchChannelMessagesToCleanResult = SuccessResult | ErrorResult;
|
export type FetchChannelMessagesToCleanResult = SuccessResult | ErrorResult;
|
||||||
|
|
||||||
export async function fetchChannelMessagesToClean(pluginData: GuildPluginData<UtilityPluginType>, targetChannel: GuildBasedChannel & TextBasedChannel, opts: FetchChannelMessagesToCleanOpts): Promise<FetchChannelMessagesToCleanResult> {
|
export async function fetchChannelMessagesToClean(
|
||||||
|
pluginData: GuildPluginData<UtilityPluginType>,
|
||||||
|
targetChannel: GuildBasedChannel & TextBasedChannel,
|
||||||
|
opts: FetchChannelMessagesToCleanOpts,
|
||||||
|
): Promise<FetchChannelMessagesToCleanResult> {
|
||||||
if (opts.count > MAX_CLEAN_COUNT || opts.count <= 0) {
|
if (opts.count > MAX_CLEAN_COUNT || opts.count <= 0) {
|
||||||
return { error: `Clean count must be between 1 and ${MAX_CLEAN_COUNT}` };
|
return { error: `Clean count must be between 1 and ${MAX_CLEAN_COUNT}` };
|
||||||
}
|
}
|
||||||
|
@ -75,7 +79,10 @@ export async function fetchChannelMessagesToClean(pluginData: GuildPluginData<Ut
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (message.createdTimestamp < timestampCutoff) continue;
|
if (message.createdTimestamp < timestampCutoff) continue;
|
||||||
if (opts.matchContent && !(await pluginData.state.regexRunner.exec(opts.matchContent, contentString).catch(allowTimeout))) {
|
if (
|
||||||
|
opts.matchContent &&
|
||||||
|
!(await pluginData.state.regexRunner.exec(opts.matchContent, contentString).catch(allowTimeout))
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { APIEmbed, ChannelType } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import {
|
import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
GroupDMInvite,
|
|
||||||
formatNumber,
|
formatNumber,
|
||||||
inviteHasCounts,
|
inviteHasCounts,
|
||||||
isGroupDMInvite,
|
isGroupDMInvite,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { PluginOptions, guildPlugin } from "knub";
|
import { guildPlugin } from "knub";
|
||||||
import { GuildLogs } from "../../data/GuildLogs.js";
|
import { GuildLogs } from "../../data/GuildLogs.js";
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
||||||
import { SendWelcomeMessageEvt } from "./events/SendWelcomeMessageEvt.js";
|
import { SendWelcomeMessageEvt } from "./events/SendWelcomeMessageEvt.js";
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
import {
|
import { Client, Message, MessageReaction, PartialMessageReaction, PartialUser, User } from "discord.js";
|
||||||
Client,
|
|
||||||
Message,
|
|
||||||
MessageReaction,
|
|
||||||
PartialMessageReaction,
|
|
||||||
PartialUser,
|
|
||||||
User
|
|
||||||
} from "discord.js";
|
|
||||||
import { ContextResponseOptions, fetchContextChannel, GenericCommandSource } from "../pluginUtils.js";
|
import { ContextResponseOptions, fetchContextChannel, GenericCommandSource } from "../pluginUtils.js";
|
||||||
import { MINUTES, noop } from "../utils.js";
|
import { MINUTES, noop } from "../utils.js";
|
||||||
import { Awaitable } from "./typeUtils.js";
|
import { Awaitable } from "./typeUtils.js";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
ButtonStyle,
|
ButtonStyle,
|
||||||
MessageActionRowComponentBuilder,
|
MessageActionRowComponentBuilder,
|
||||||
MessageComponentInteraction,
|
MessageComponentInteraction,
|
||||||
MessageCreateOptions
|
MessageCreateOptions,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
|
@ -23,8 +23,8 @@ import { $ZodRecordKey, $ZodType } from "zod/v4/core";
|
||||||
const RESOLVING = Symbol("mapOnSchema/resolving");
|
const RESOLVING = Symbol("mapOnSchema/resolving");
|
||||||
|
|
||||||
export function mapOnSchema<T extends $ZodType, TResult extends $ZodType>(
|
export function mapOnSchema<T extends $ZodType, TResult extends $ZodType>(
|
||||||
schema: T,
|
schema: T,
|
||||||
fn: (schema: $ZodType) => TResult,
|
fn: (schema: $ZodType) => TResult,
|
||||||
): TResult;
|
): TResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,134 +32,134 @@ export function mapOnSchema<T extends $ZodType, TResult extends $ZodType>(
|
||||||
* The rewriting is applied bottom-up (ie. {@link fn} will get called on "children" first).
|
* The rewriting is applied bottom-up (ie. {@link fn} will get called on "children" first).
|
||||||
*/
|
*/
|
||||||
export function mapOnSchema(schema: $ZodType, fn: (schema: $ZodType) => $ZodType): $ZodType {
|
export function mapOnSchema(schema: $ZodType, fn: (schema: $ZodType) => $ZodType): $ZodType {
|
||||||
// Cache results to support recursive schemas
|
// Cache results to support recursive schemas
|
||||||
const results = new Map<$ZodType, $ZodType | typeof RESOLVING>();
|
const results = new Map<$ZodType, $ZodType | typeof RESOLVING>();
|
||||||
|
|
||||||
function mapElement(s: $ZodType) {
|
function mapElement(s: $ZodType) {
|
||||||
const value = results.get(s);
|
const value = results.get(s);
|
||||||
if (value === RESOLVING) {
|
if (value === RESOLVING) {
|
||||||
throw new Error("Recursive schema access detected");
|
throw new Error("Recursive schema access detected");
|
||||||
} else if (value !== undefined) {
|
} else if (value !== undefined) {
|
||||||
return value;
|
return value;
|
||||||
}
|
|
||||||
|
|
||||||
results.set(s, RESOLVING);
|
|
||||||
const result = mapOnSchema(s, fn);
|
|
||||||
results.set(s, result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapInner() {
|
results.set(s, RESOLVING);
|
||||||
if (schema instanceof z.ZodObject) {
|
const result = mapOnSchema(s, fn);
|
||||||
const newShape: Record<string, $ZodType> = {};
|
results.set(s, result);
|
||||||
for (const [key, value] of Object.entries(schema.shape)) {
|
return result;
|
||||||
newShape[key] = mapElement(value);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new z.ZodObject({
|
function mapInner() {
|
||||||
...schema.def,
|
if (schema instanceof z.ZodObject) {
|
||||||
shape: newShape,
|
const newShape: Record<string, $ZodType> = {};
|
||||||
});
|
for (const [key, value] of Object.entries(schema.shape)) {
|
||||||
} else if (schema instanceof z.ZodArray) {
|
newShape[key] = mapElement(value);
|
||||||
return new z.ZodArray({
|
}
|
||||||
...schema.def,
|
|
||||||
type: "array",
|
return new z.ZodObject({
|
||||||
element: mapElement(schema.def.element),
|
...schema.def,
|
||||||
});
|
shape: newShape,
|
||||||
} else if (schema instanceof z.ZodMap) {
|
});
|
||||||
return new z.ZodMap({
|
} else if (schema instanceof z.ZodArray) {
|
||||||
...schema.def,
|
return new z.ZodArray({
|
||||||
keyType: mapElement(schema.def.keyType),
|
...schema.def,
|
||||||
valueType: mapElement(schema.def.valueType),
|
type: "array",
|
||||||
});
|
element: mapElement(schema.def.element),
|
||||||
} else if (schema instanceof z.ZodSet) {
|
});
|
||||||
return new z.ZodSet({
|
} else if (schema instanceof z.ZodMap) {
|
||||||
...schema.def,
|
return new z.ZodMap({
|
||||||
valueType: mapElement(schema.def.valueType),
|
...schema.def,
|
||||||
});
|
keyType: mapElement(schema.def.keyType),
|
||||||
} else if (schema instanceof z.ZodOptional) {
|
valueType: mapElement(schema.def.valueType),
|
||||||
return new z.ZodOptional({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodSet) {
|
||||||
innerType: mapElement(schema.def.innerType),
|
return new z.ZodSet({
|
||||||
});
|
...schema.def,
|
||||||
} else if (schema instanceof z.ZodNullable) {
|
valueType: mapElement(schema.def.valueType),
|
||||||
return new z.ZodNullable({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodOptional) {
|
||||||
innerType: mapElement(schema.def.innerType),
|
return new z.ZodOptional({
|
||||||
});
|
...schema.def,
|
||||||
} else if (schema instanceof z.ZodDefault) {
|
innerType: mapElement(schema.def.innerType),
|
||||||
return new z.ZodDefault({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodNullable) {
|
||||||
innerType: mapElement(schema.def.innerType),
|
return new z.ZodNullable({
|
||||||
});
|
...schema.def,
|
||||||
} else if (schema instanceof z.ZodReadonly) {
|
innerType: mapElement(schema.def.innerType),
|
||||||
return new z.ZodReadonly({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodDefault) {
|
||||||
innerType: mapElement(schema.def.innerType),
|
return new z.ZodDefault({
|
||||||
});
|
...schema.def,
|
||||||
} else if (schema instanceof z.ZodLazy) {
|
innerType: mapElement(schema.def.innerType),
|
||||||
return new z.ZodLazy({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodReadonly) {
|
||||||
// NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
|
return new z.ZodReadonly({
|
||||||
getter: () => mapElement(schema._def.getter()),
|
...schema.def,
|
||||||
});
|
innerType: mapElement(schema.def.innerType),
|
||||||
} else if (schema instanceof z.ZodPromise) {
|
});
|
||||||
return new z.ZodPromise({
|
} else if (schema instanceof z.ZodLazy) {
|
||||||
...schema.def,
|
return new z.ZodLazy({
|
||||||
innerType: mapElement(schema.def.innerType),
|
...schema.def,
|
||||||
});
|
// NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
|
||||||
} else if (schema instanceof z.ZodCatch) {
|
getter: () => mapElement(schema._def.getter()),
|
||||||
return new z.ZodCatch({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodPromise) {
|
||||||
innerType: mapElement(schema._def.innerType),
|
return new z.ZodPromise({
|
||||||
});
|
...schema.def,
|
||||||
} else if (schema instanceof z.ZodTuple) {
|
innerType: mapElement(schema.def.innerType),
|
||||||
return new z.ZodTuple({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodCatch) {
|
||||||
items: schema.def.items.map((item: $ZodType) => mapElement(item)),
|
return new z.ZodCatch({
|
||||||
rest: schema.def.rest && mapElement(schema.def.rest),
|
...schema.def,
|
||||||
});
|
innerType: mapElement(schema._def.innerType),
|
||||||
} else if (schema instanceof z.ZodDiscriminatedUnion) {
|
});
|
||||||
return new z.ZodDiscriminatedUnion({
|
} else if (schema instanceof z.ZodTuple) {
|
||||||
...schema.def,
|
return new z.ZodTuple({
|
||||||
options: schema.options.map((option) => mapOnSchema(option, fn)),
|
...schema.def,
|
||||||
});
|
items: schema.def.items.map((item: $ZodType) => mapElement(item)),
|
||||||
} else if (schema instanceof z.ZodUnion) {
|
rest: schema.def.rest && mapElement(schema.def.rest),
|
||||||
return new z.ZodUnion({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodDiscriminatedUnion) {
|
||||||
options: schema.options.map((option) => mapOnSchema(option, fn)),
|
return new z.ZodDiscriminatedUnion({
|
||||||
});
|
...schema.def,
|
||||||
} else if (schema instanceof z.ZodIntersection) {
|
options: schema.options.map((option) => mapOnSchema(option, fn)),
|
||||||
return new z.ZodIntersection({
|
});
|
||||||
...schema.def,
|
} else if (schema instanceof z.ZodUnion) {
|
||||||
right: mapElement(schema.def.right),
|
return new z.ZodUnion({
|
||||||
left: mapElement(schema.def.left),
|
...schema.def,
|
||||||
});
|
options: schema.options.map((option) => mapOnSchema(option, fn)),
|
||||||
} else if (schema instanceof z.ZodRecord) {
|
});
|
||||||
return new z.ZodRecord({
|
} else if (schema instanceof z.ZodIntersection) {
|
||||||
...schema.def,
|
return new z.ZodIntersection({
|
||||||
keyType: mapElement(schema.def.keyType) as $ZodRecordKey,
|
...schema.def,
|
||||||
valueType: mapElement(schema.def.valueType),
|
right: mapElement(schema.def.right),
|
||||||
});
|
left: mapElement(schema.def.left),
|
||||||
} else {
|
});
|
||||||
return schema;
|
} else if (schema instanceof z.ZodRecord) {
|
||||||
}
|
return new z.ZodRecord({
|
||||||
|
...schema.def,
|
||||||
|
keyType: mapElement(schema.def.keyType) as $ZodRecordKey,
|
||||||
|
valueType: mapElement(schema.def.valueType),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return schema;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fn(mapInner());
|
return fn(mapInner());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deepPartial<T extends z.ZodType>(schema: T): T {
|
export function deepPartial<T extends z.ZodType>(schema: T): T {
|
||||||
return mapOnSchema(schema, (s) => (s instanceof z.ZodObject ? s.partial() : s)) as T;
|
return mapOnSchema(schema, (s) => (s instanceof z.ZodObject ? s.partial() : s)) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make all object schemas "strict" (ie. fail on unknown keys), except if they are marked as `.passthrough()` */
|
/** Make all object schemas "strict" (ie. fail on unknown keys), except if they are marked as `.passthrough()` */
|
||||||
export function deepStrict<T extends z.ZodType>(schema: T): T {
|
export function deepStrict<T extends z.ZodType>(schema: T): T {
|
||||||
return mapOnSchema(schema, (s) =>
|
return mapOnSchema(schema, (s) =>
|
||||||
s instanceof z.ZodObject /* && s.def.unknownKeys !== "passthrough" */ ? s.strict() : s,
|
s instanceof z.ZodObject /* && s.def.unknownKeys !== "passthrough" */ ? s.strict() : s,
|
||||||
) as T;
|
) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deepStrictAll<T extends z.ZodType>(schema: T): T {
|
export function deepStrictAll<T extends z.ZodType>(schema: T): T {
|
||||||
return mapOnSchema(schema, (s) => (s instanceof z.ZodObject ? s.strict() : s)) as T;
|
return mapOnSchema(schema, (s) => (s instanceof z.ZodObject ? s.strict() : s)) as T;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue