3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-06 23:55:03 +00:00

chore: format

This commit is contained in:
Dragory 2025-05-31 18:19:26 +00:00
parent 6c55b98eee
commit aaf4e02c5f
No known key found for this signature in database
56 changed files with 282 additions and 255 deletions

View file

@ -1,5 +1,5 @@
import { EventEmitter } from "node:events";
import { CooldownManager } from "knub";
import { EventEmitter } from "node:events";
import { RegExpWorker, TimeoutError } from "regexp-worker";
import { MINUTES, SECONDS } from "./utils.js";
import Timeout = NodeJS.Timeout;

View file

@ -73,7 +73,10 @@ function formatZodConfigSchema(schema: z.ZodType) {
return schema.def.values;
}
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") {
return "string";
@ -131,7 +134,7 @@ export function initDocs(router: express.Router) {
config: cmd.config,
}));
const defaultOptions = (pluginInfo.plugin as any /* TODO */).defaultOptions || {};
const defaultOptions = (pluginInfo.plugin as any) /* TODO */.defaultOptions || {};
res.json({
name: pluginInfo.plugin.name,

View file

@ -28,12 +28,15 @@ export async function validateGuildConfig(config: any): Promise<string | null> {
}
const plugin = pluginNameToPlugin.get(pluginName)!;
const configManager = new PluginConfigManager({}, {
configSchema: plugin.configSchema,
defaultOverrides: plugin.defaultOverrides ?? [],
levels: {},
customOverrideCriteriaFunctions: plugin.customOverrideCriteriaFunctions,
});
const configManager = new PluginConfigManager(
{},
{
configSchema: plugin.configSchema,
defaultOverrides: plugin.defaultOverrides ?? [],
levels: {},
customOverrideCriteriaFunctions: plugin.customOverrideCriteriaFunctions,
},
);
try {
await configManager.init();

View file

@ -37,6 +37,7 @@ const envType = z.object({
.optional(),
PHISHERMAN_API_KEY: z.string().optional(),
FISHFISH_API_KEY: z.string().optional(),
DB_HOST: z.string().optional(),
DB_PORT: z.preprocess((v) => Number(v), z.number()).optional(),

View file

@ -1,8 +1,8 @@
import fs from "node:fs";
import { z } from "zod/v4";
import { availableGuildPlugins } from "./plugins/availablePlugins.js";
import { zZeppelinGuildConfig } from "./types.js";
import { deepPartial } from "./utils/zodDeepPartial.js";
import fs from "node:fs";
const basePluginOverrideCriteriaSchema = z.strictObject({
channel: z

View file

@ -3,7 +3,6 @@
*/
import {
BaseChannel,
BitField,
BitFieldResolvable,
ChatInputCommandInteraction,
@ -19,15 +18,21 @@ import {
MessageFlagsString,
ModalSubmitInteraction,
PermissionsBitField,
SendableChannels,
TextBasedChannel,
User,
} 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 { TZeppelinKnub } from "./types.js";
import { Tail } from "./utils/typeUtils.js";
import z from "zod/v4";
const { getMemberLevel } = helpers;
@ -66,18 +71,14 @@ export type GenericCommandSource = Message | CommandInteraction | ModalSubmitInt
export function isContextInteraction(
context: GenericCommandSource,
): context is CommandInteraction | ModalSubmitInteraction {
return (context instanceof CommandInteraction || context instanceof ModalSubmitInteraction);
return context instanceof CommandInteraction || context instanceof ModalSubmitInteraction;
}
export function isContextMessage(
context: GenericCommandSource,
): context is Message {
return (context instanceof Message);
export function isContextMessage(context: GenericCommandSource): context is Message {
return context instanceof Message;
}
export async function getContextChannel(
context: GenericCommandSource,
): Promise<TextBasedChannel | null> {
export async function getContextChannel(context: GenericCommandSource): Promise<TextBasedChannel | null> {
if (isContextInteraction(context)) {
return context.channel;
}
@ -87,9 +88,7 @@ export async function getContextChannel(
throw new Error("Unknown context type");
}
export function getContextChannelId(
context: GenericCommandSource,
): string | null {
export function getContextChannelId(context: GenericCommandSource): string | null {
return context.channelId;
}
@ -104,13 +103,10 @@ export async function fetchContextChannel(context: GenericCommandSource) {
return (await context.guild.channels.fetch(channelId))!;
}
function flagsWithEphemeral<
TFlags extends string,
TType extends number | bigint
>(flags: BitFieldResolvable<TFlags, any>, ephemeral: boolean): BitFieldResolvable<
TFlags | Extract<MessageFlagsString, "Ephemeral">,
TType | MessageFlags.Ephemeral
> {
function flagsWithEphemeral<TFlags extends string, TType extends number | bigint>(
flags: BitFieldResolvable<TFlags, any>,
ephemeral: boolean,
): BitFieldResolvable<TFlags | Extract<MessageFlagsString, "Ephemeral">, TType | MessageFlags.Ephemeral> {
if (!ephemeral) {
return flags;
}
@ -150,7 +146,7 @@ export async function sendContextResponse(
if (!contextChannel?.isSendable()) {
throw new Error("Context channel does not exist or is not sendable");
}
return contextChannel.send(content);
}
@ -167,7 +163,10 @@ export async function deleteContextResponse(response: ContextResponse): Promise<
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) {
// TODO: Support for modal interactions (here and Knub)
return config.getForInteraction(context);

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { GuildLogs } from "../../data/GuildLogs.js";
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
import { LogsPlugin } from "../Logs/LogsPlugin.js";

View file

@ -1,4 +1,4 @@
import { ChannelType, PermissionsBitField, Snowflake } from "discord.js";
import { PermissionsBitField, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { LogType } from "../../../data/LogType.js";

View file

@ -1,7 +1,7 @@
import { escapeInlineCode } from "discord.js";
import z from "zod/v4";
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils.js";
import { automodTrigger } from "../helpers.js";
import z from "zod/v4";
interface MatchResultType {
matchedType: string;

View file

@ -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 moment from "moment-timezone";
import { CaseTypes } from "../../../data/CaseTypes.js";

View file

@ -1,4 +1,4 @@
import { PluginOptions, PluginOverride, guildPlugin } from "knub";
import { PluginOverride, guildPlugin } from "knub";
import { GuildLogs } from "../../data/GuildLogs.js";
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners.js";

View file

@ -18,7 +18,10 @@ export const zCensorConfig = z.strictObject({
domain_blacklist: z.array(zBoundedCharacters(0, 255)).nullable().default(null),
blocked_tokens: 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 {

View file

@ -1,6 +1,6 @@
import { BasePluginType, guildPluginMessageCommand, pluginUtils } from "knub";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { z } from "zod/v4";
import { CommonPlugin } from "../Common/CommonPlugin.js";
export const zChannelArchiverPluginConfig = z.strictObject({});

View file

@ -1,9 +1,4 @@
import {
Attachment,
MessageMentionOptions,
SendableChannels,
TextBasedChannel
} from "discord.js";
import { Attachment, MessageMentionOptions, SendableChannels, TextBasedChannel } from "discord.js";
import { guildPlugin } from "knub";
import { GenericCommandSource, sendContextResponse } from "../../pluginUtils.js";
import { errorMessage, successMessage } from "../../utils.js";
@ -28,9 +23,7 @@ export const CommonPlugin = guildPlugin<CommonPluginType>()({
) => {
const emoji = getSuccessEmoji(pluginData);
const formattedBody = successMessage(body, emoji);
const content = allowedMentions
? { content: formattedBody, allowedMentions }
: { content: formattedBody };
const content = allowedMentions ? { content: formattedBody, allowedMentions } : { content: formattedBody };
if ("isSendable" in context) {
return context.send(content);
}
@ -46,9 +39,7 @@ export const CommonPlugin = guildPlugin<CommonPluginType>()({
) => {
const emoji = getErrorEmoji(pluginData);
const formattedBody = errorMessage(body, emoji);
const content = allowedMentions
? { content: formattedBody, allowedMentions }
: { content: formattedBody };
const content = allowedMentions ? { content: formattedBody, allowedMentions } : { content: formattedBody };
if ("isSendable" in context) {
return context.send(content);
}
@ -67,9 +58,7 @@ export const CommonPlugin = guildPlugin<CommonPluginType>()({
);
}
if (!channel.isSendable()) {
throw new Error(
"Passed attachment storage channel is not sendable",
);
throw new Error("Passed attachment storage channel is not sendable");
}
return channel.send({

View file

@ -1,4 +1,4 @@
import { PluginOptions, PluginOverride, guildPlugin } from "knub";
import { PluginOverride, guildPlugin } from "knub";
import { GuildCases } from "../../data/GuildCases.js";
import { CasesPlugin } from "../Cases/CasesPlugin.js";
import { LogsPlugin } from "../Logs/LogsPlugin.js";

View file

@ -34,7 +34,7 @@ export async function cleanAction(
.catch((err) => logger.error(`Clean interaction reply failed: ${err}`));
return;
}
const targetChannel = await pluginData.guild.channels.fetch(targetChannelId);
if (!targetChannel?.isTextBased()) {
await interaction
@ -62,7 +62,11 @@ export async function cleanAction(
if (fetchMessagesResult.messages.length > 0) {
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 {
interaction.editReply("No messages to clean");
}

View file

@ -1,7 +1,12 @@
import { EventEmitter } from "events";
import { PluginOptions, PluginOverride, guildPlugin } from "knub";
import { PluginOverride, guildPlugin } from "knub";
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 { MINUTES, convertDelayStringToMS } from "../../utils.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";
@ -98,7 +103,9 @@ export const CountersPlugin = guildPlugin<CountersPluginType>()({
// Initialize triggers
for (const [triggerName, trigger] of Object.entries(counter.triggers)) {
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 counterTrigger = await state.counters.initCounterTrigger(
dbCounter.id,

View file

@ -15,19 +15,18 @@ import Timeout = NodeJS.Timeout;
const MAX_COUNTERS = 5;
const MAX_TRIGGERS_PER_COUNTER = 5;
export const zTrigger = z
.strictObject({
// Dummy type because name gets replaced by the property key in transform()
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
condition: zBoundedCharacters(1, 64).refine((str) => parseCounterConditionString(str) !== null, {
message: "Invalid counter trigger condition",
}),
reverse_condition: zBoundedCharacters(1, 64)
.refine((str) => parseCounterConditionString(str) !== null, {
message: "Invalid counter trigger reverse condition",
})
.optional(),
});
export const zTrigger = z.strictObject({
// Dummy type because name gets replaced by the property key in transform()
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
condition: zBoundedCharacters(1, 64).refine((str) => parseCounterConditionString(str) !== null, {
message: "Invalid counter trigger condition",
}),
reverse_condition: zBoundedCharacters(1, 64)
.refine((str) => parseCounterConditionString(str) !== null, {
message: "Invalid counter trigger reverse condition",
})
.optional(),
});
const zTriggerFromString = zBoundedCharacters(0, 100).transform((val, ctx) => {
const parsedCondition = parseCounterConditionString(val);

View file

@ -1,4 +1,3 @@
import { Message } from "discord.js";
import { GuildPluginData } from "knub";
import { TemplateSafeValueContainer } from "../../../templateFormatter.js";
import { ActionError } from "../ActionError.js";

View file

@ -1,5 +1,5 @@
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 { Configs } from "../../data/Configs.js";
import { env } from "../../env.js";

View file

@ -1,5 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import z from "zod/v4";
import { guildPlugin } from "knub";
import { Queue } from "../../Queue.js";
import { Webhooks } from "../../data/Webhooks.js";
import { makePublicFn } from "../../pluginUtils.js";

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { onGuildEvent } from "../../data/GuildEvents.js";
import { GuildVCAlerts } from "../../data/GuildVCAlerts.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { SaveMessagesToDBCmd } from "./commands/SaveMessagesToDB.js";

View file

@ -31,7 +31,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
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
let mod = member;

View file

@ -41,7 +41,7 @@ export const BanMsgCmd = modActionsMsgCmd({
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
let mod = member;

View file

@ -41,7 +41,7 @@ export const CasesUserMsgCmd = modActionsMsgCmd({
pluginData.state.common.sendErrorMessage(msg, `User not found`);
return;
}
const member = await resolveMessageMember(msg);
return actualCasesCmd(

View file

@ -48,12 +48,7 @@ export async function actualDeleteCaseCmd(
content: "Delete the following case? Answer 'Yes' to continue, 'No' to cancel.",
});
const reply = await helpers.waitForReply(
pluginData.client,
channel,
author.id,
15 * SECONDS,
);
const reply = await helpers.waitForReply(pluginData.client, channel, author.id, 15 * SECONDS);
const normalizedReply = (reply?.content || "").toLowerCase().trim();
if (normalizedReply !== "yes" && normalizedReply !== "y") {
sendContextResponse(context, "Cancelled. Case was not deleted.");

View file

@ -39,7 +39,7 @@ export const ForceMuteMsgCmd = modActionsMsgCmd({
return;
}
const authorMember = await resolveMessageMember(msg)
const authorMember = await resolveMessageMember(msg);
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
// Make sure we're allowed to mute this user

View file

@ -1,10 +1,10 @@
import { hasPermission } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../../commandTypes.js";
import { resolveMessageMember } from "../../../../pluginUtils.js";
import { resolveUser } from "../../../../utils.js";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs.js";
import { modActionsMsgCmd } from "../../types.js";
import { actualKickCmd } from "./actualKickCmd.js";
import { resolveMessageMember } from "../../../../pluginUtils.js";
const opts = {
mod: ct.member({ option: true }),

View file

@ -1,6 +1,6 @@
import { waitForReply } from "knub/helpers";
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 { actualMassBanCmd } from "./actualMassBanCmd.js";

View file

@ -3,7 +3,14 @@ import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes.js";
import { LogType } from "../../../../data/LogType.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 { CasesPlugin } from "../../../Cases/CasesPlugin.js";
import { LogsPlugin } from "../../../Logs/LogsPlugin.js";

View file

@ -1,6 +1,6 @@
import { waitForReply } from "knub/helpers";
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 { actualMassMuteCmd } from "./actualMassMuteCmd.js";

View file

@ -3,6 +3,7 @@ import { GuildPluginData } from "knub";
import { LogType } from "../../../../data/LogType.js";
import { logger } from "../../../../logger.js";
import { canActOn, deleteContextResponse, isContextInteraction, sendContextResponse } from "../../../../pluginUtils.js";
import { noop } from "../../../../utils.js";
import { LogsPlugin } from "../../../Logs/LogsPlugin.js";
import { MutesPlugin } from "../../../Mutes/MutesPlugin.js";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction.js";
@ -11,7 +12,6 @@ import {
formatReasonWithMessageLinkForAttachments,
} from "../../functions/formatReasonForAttachments.js";
import { ModActionsPluginType } from "../../types.js";
import { noop } from "../../../../utils.js";
export async function actualMassMuteCmd(
pluginData: GuildPluginData<ModActionsPluginType>,

View file

@ -1,6 +1,6 @@
import { waitForReply } from "knub/helpers";
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 { actualMassUnbanCmd } from "./actualMassUnbanCmd.js";

View file

@ -30,16 +30,28 @@ export const zModActionsConfig = z.strictObject({
message_on_ban: z.boolean().default(false),
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}"),
kick_message: z.nullable(z.string()).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}"),
kick_message: z
.nullable(z.string())
.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_channel: z.nullable(z.string()).default(null),
warn_notify_enabled: z.boolean().default(false),
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),
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_warn: z.boolean().default(false),
can_mute: z.boolean().default(false),

View file

@ -23,7 +23,10 @@ export const zMutesConfig = z.strictObject({
message_on_update: z.boolean().default(false),
message_channel: z.string().nullable().default(null),
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}."),
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),

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { Queue } from "../../Queue.js";
import { GuildNicknameHistory } from "../../data/GuildNicknameHistory.js";
import { UsernameHistory } from "../../data/UsernameHistory.js";

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { GuildLogs } from "../../data/GuildLogs.js";
import { GuildPersistedData } from "../../data/GuildPersistedData.js";
import { LogsPlugin } from "../Logs/LogsPlugin.js";

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { Queue } from "../../Queue.js";
import { GuildReactionRoles } from "../../data/GuildReactionRoles.js";
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";

View file

@ -1,10 +1,10 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils.js";
import { canReadChannel } from "../../../utils/canReadChannel.js";
import { TReactionRolePair, reactionRolesCmd } from "../types.js";
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
const CLEAR_ROLES_EMOJI = "❌";

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { onGuildEvent } from "../../data/GuildEvents.js";
import { GuildReminders } from "../../data/GuildReminders.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { GuildLogs } from "../../data/GuildLogs.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { LogsPlugin } from "../Logs/LogsPlugin.js";

View file

@ -1,4 +1,4 @@
import { CooldownManager, PluginOptions, guildPlugin } from "knub";
import { CooldownManager, guildPlugin } from "knub";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { RoleAddCmd } from "./commands/RoleAddCmd.js";
import { RoleHelpCmd } from "./commands/RoleHelpCmd.js";

View file

@ -1,12 +1,12 @@
import { Role, Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
import { memberRolesLock } from "../../../utils/lockNameHelpers.js";
import { selfGrantableRolesCmd } from "../types.js";
import { findMatchingRoles } from "../util/findMatchingRoles.js";
import { getApplyingEntries } from "../util/getApplyingEntries.js";
import { normalizeRoleNames } from "../util/normalizeRoleNames.js";
import { splitRoleNames } from "../util/splitRoleNames.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
export const RoleAddCmd = selfGrantableRolesCmd({
trigger: ["role", "role add"],

View file

@ -1,12 +1,12 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
import { memberRolesLock } from "../../../utils/lockNameHelpers.js";
import { selfGrantableRolesCmd } from "../types.js";
import { findMatchingRoles } from "../util/findMatchingRoles.js";
import { getApplyingEntries } from "../util/getApplyingEntries.js";
import { normalizeRoleNames } from "../util/normalizeRoleNames.js";
import { splitRoleNames } from "../util/splitRoleNames.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
export const RoleRemoveCmd = selfGrantableRolesCmd({
trigger: "role remove",

View file

@ -1,11 +1,11 @@
import { MessageCreateOptions } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { logger } from "../../../logger.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
import { TemplateParseError } from "../../../templateFormatter.js";
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects.js";
import { tagsCmd } from "../types.js";
import { renderTagBody } from "../util/renderTagBody.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
export const TagEvalCmd = tagsCmd({
trigger: "tag eval",

View file

@ -1,11 +1,10 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { GuildMemberTimezones } from "../../data/GuildMemberTimezones.js";
import { makePublicFn } from "../../pluginUtils.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { ResetTimezoneCmd } from "./commands/ResetTimezoneCmd.js";
import { SetTimezoneCmd } from "./commands/SetTimezoneCmd.js";
import { ViewTimezoneCmd } from "./commands/ViewTimezoneCmd.js";
import { defaultDateFormats } from "./defaultDateFormats.js";
import { getDateFormat } from "./functions/getDateFormat.js";
import { getGuildTz } from "./functions/getGuildTz.js";
import { getMemberTz } from "./functions/getMemberTz.js";

View file

@ -1,9 +1,9 @@
import { Snowflake, TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
import { messageLink } from "../../../utils.js";
import { canReadChannel } from "../../../utils/canReadChannel.js";
import { utilityCmd } from "../types.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
export const ContextCmd = utilityCmd({
trigger: "context",

View file

@ -1,6 +1,7 @@
import { Snowflake } from "discord.js";
import { getChannelId, getRoleId } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils.js";
import { canReadChannel } from "../../../utils/canReadChannel.js";
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget.js";
@ -15,7 +16,6 @@ import { getServerInfoEmbed } from "../functions/getServerInfoEmbed.js";
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed.js";
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed.js";
import { utilityCmd } from "../types.js";
import { resolveMessageMember } from "../../../pluginUtils.js";
export const InfoCmd = utilityCmd({
trigger: "info",

View file

@ -1,11 +1,11 @@
import { GuildPluginData } from "knub";
import { UtilityPluginType } from "../types.js";
import { GuildBasedChannel, Snowflake, TextBasedChannel, User } from "discord.js";
import { GuildPluginData } from "knub";
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
import { LogType } from "../../../data/LogType.js";
import { chunkArray } from "../../../utils.js";
import { getBaseUrl } from "../../../pluginUtils.js";
import { chunkArray } from "../../../utils.js";
import { LogsPlugin } from "../../Logs/LogsPlugin.js";
import { UtilityPluginType } from "../types.js";
export async function cleanMessages(
pluginData: GuildPluginData<UtilityPluginType>,

View file

@ -1,11 +1,11 @@
import { GuildBasedChannel, Message, OmitPartialGroupDMChannel, Snowflake, TextBasedChannel } from "discord.js";
import { DAYS, getInviteCodesInString } from "../../../utils.js";
import { GuildPluginData } from "knub";
import { UtilityPluginType } from "../types.js";
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp.js";
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
import { humanizeDurationShort } from "../../../humanizeDuration.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_TIME = 1 * DAYS;
@ -33,7 +33,11 @@ export interface 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) {
return { error: `Clean count must be between 1 and ${MAX_CLEAN_COUNT}` };
}
@ -75,7 +79,10 @@ export async function fetchChannelMessagesToClean(pluginData: GuildPluginData<Ut
break;
}
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;
}

View file

@ -2,7 +2,6 @@ import { APIEmbed, ChannelType } from "discord.js";
import { GuildPluginData } from "knub";
import {
EmbedWith,
GroupDMInvite,
formatNumber,
inviteHasCounts,
isGroupDMInvite,

View file

@ -1,4 +1,4 @@
import { PluginOptions, guildPlugin } from "knub";
import { guildPlugin } from "knub";
import { GuildLogs } from "../../data/GuildLogs.js";
import { LogsPlugin } from "../Logs/LogsPlugin.js";
import { SendWelcomeMessageEvt } from "./events/SendWelcomeMessageEvt.js";

View file

@ -1,11 +1,4 @@
import {
Client,
Message,
MessageReaction,
PartialMessageReaction,
PartialUser,
User
} from "discord.js";
import { Client, Message, MessageReaction, PartialMessageReaction, PartialUser, User } from "discord.js";
import { ContextResponseOptions, fetchContextChannel, GenericCommandSource } from "../pluginUtils.js";
import { MINUTES, noop } from "../utils.js";
import { Awaitable } from "./typeUtils.js";

View file

@ -4,7 +4,7 @@ import {
ButtonStyle,
MessageActionRowComponentBuilder,
MessageComponentInteraction,
MessageCreateOptions
MessageCreateOptions,
} from "discord.js";
import moment from "moment";
import { v4 as uuidv4 } from "uuid";

View file

@ -23,143 +23,143 @@ import { $ZodRecordKey, $ZodType } from "zod/v4/core";
const RESOLVING = Symbol("mapOnSchema/resolving");
export function mapOnSchema<T extends $ZodType, TResult extends $ZodType>(
schema: T,
fn: (schema: $ZodType) => TResult,
schema: T,
fn: (schema: $ZodType) => TResult,
): TResult;
/**
/**
* Applies {@link fn} to each element of the schema recursively, replacing every schema with its return value.
* 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 {
// Cache results to support recursive schemas
const results = new Map<$ZodType, $ZodType | typeof RESOLVING>();
// Cache results to support recursive schemas
const results = new Map<$ZodType, $ZodType | typeof RESOLVING>();
function mapElement(s: $ZodType) {
const value = results.get(s);
if (value === RESOLVING) {
throw new Error("Recursive schema access detected");
} else if (value !== undefined) {
return value;
}
results.set(s, RESOLVING);
const result = mapOnSchema(s, fn);
results.set(s, result);
return result;
function mapElement(s: $ZodType) {
const value = results.get(s);
if (value === RESOLVING) {
throw new Error("Recursive schema access detected");
} else if (value !== undefined) {
return value;
}
function mapInner() {
if (schema instanceof z.ZodObject) {
const newShape: Record<string, $ZodType> = {};
for (const [key, value] of Object.entries(schema.shape)) {
newShape[key] = mapElement(value);
}
results.set(s, RESOLVING);
const result = mapOnSchema(s, fn);
results.set(s, result);
return result;
}
return new z.ZodObject({
...schema.def,
shape: newShape,
});
} else if (schema instanceof z.ZodArray) {
return new z.ZodArray({
...schema.def,
type: "array",
element: mapElement(schema.def.element),
});
} else if (schema instanceof z.ZodMap) {
return new z.ZodMap({
...schema.def,
keyType: mapElement(schema.def.keyType),
valueType: mapElement(schema.def.valueType),
});
} else if (schema instanceof z.ZodSet) {
return new z.ZodSet({
...schema.def,
valueType: mapElement(schema.def.valueType),
});
} else if (schema instanceof z.ZodOptional) {
return new z.ZodOptional({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodNullable) {
return new z.ZodNullable({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodDefault) {
return new z.ZodDefault({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodReadonly) {
return new z.ZodReadonly({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodLazy) {
return new z.ZodLazy({
...schema.def,
// NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
getter: () => mapElement(schema._def.getter()),
});
} else if (schema instanceof z.ZodPromise) {
return new z.ZodPromise({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodCatch) {
return new z.ZodCatch({
...schema.def,
innerType: mapElement(schema._def.innerType),
});
} else if (schema instanceof z.ZodTuple) {
return new z.ZodTuple({
...schema.def,
items: schema.def.items.map((item: $ZodType) => mapElement(item)),
rest: schema.def.rest && mapElement(schema.def.rest),
});
} else if (schema instanceof z.ZodDiscriminatedUnion) {
return new z.ZodDiscriminatedUnion({
...schema.def,
options: schema.options.map((option) => mapOnSchema(option, fn)),
});
} else if (schema instanceof z.ZodUnion) {
return new z.ZodUnion({
...schema.def,
options: schema.options.map((option) => mapOnSchema(option, fn)),
});
} else if (schema instanceof z.ZodIntersection) {
return new z.ZodIntersection({
...schema.def,
right: mapElement(schema.def.right),
left: mapElement(schema.def.left),
});
} 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;
}
function mapInner() {
if (schema instanceof z.ZodObject) {
const newShape: Record<string, $ZodType> = {};
for (const [key, value] of Object.entries(schema.shape)) {
newShape[key] = mapElement(value);
}
return new z.ZodObject({
...schema.def,
shape: newShape,
});
} else if (schema instanceof z.ZodArray) {
return new z.ZodArray({
...schema.def,
type: "array",
element: mapElement(schema.def.element),
});
} else if (schema instanceof z.ZodMap) {
return new z.ZodMap({
...schema.def,
keyType: mapElement(schema.def.keyType),
valueType: mapElement(schema.def.valueType),
});
} else if (schema instanceof z.ZodSet) {
return new z.ZodSet({
...schema.def,
valueType: mapElement(schema.def.valueType),
});
} else if (schema instanceof z.ZodOptional) {
return new z.ZodOptional({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodNullable) {
return new z.ZodNullable({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodDefault) {
return new z.ZodDefault({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodReadonly) {
return new z.ZodReadonly({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodLazy) {
return new z.ZodLazy({
...schema.def,
// NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
getter: () => mapElement(schema._def.getter()),
});
} else if (schema instanceof z.ZodPromise) {
return new z.ZodPromise({
...schema.def,
innerType: mapElement(schema.def.innerType),
});
} else if (schema instanceof z.ZodCatch) {
return new z.ZodCatch({
...schema.def,
innerType: mapElement(schema._def.innerType),
});
} else if (schema instanceof z.ZodTuple) {
return new z.ZodTuple({
...schema.def,
items: schema.def.items.map((item: $ZodType) => mapElement(item)),
rest: schema.def.rest && mapElement(schema.def.rest),
});
} else if (schema instanceof z.ZodDiscriminatedUnion) {
return new z.ZodDiscriminatedUnion({
...schema.def,
options: schema.options.map((option) => mapOnSchema(option, fn)),
});
} else if (schema instanceof z.ZodUnion) {
return new z.ZodUnion({
...schema.def,
options: schema.options.map((option) => mapOnSchema(option, fn)),
});
} else if (schema instanceof z.ZodIntersection) {
return new z.ZodIntersection({
...schema.def,
right: mapElement(schema.def.right),
left: mapElement(schema.def.left),
});
} 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 {
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()` */
export function deepStrict<T extends z.ZodType>(schema: T): T {
return mapOnSchema(schema, (s) =>
s instanceof z.ZodObject /* && s.def.unknownKeys !== "passthrough" */ ? s.strict() : s,
) as T;
return mapOnSchema(schema, (s) =>
s instanceof z.ZodObject /* && s.def.unknownKeys !== "passthrough" */ ? s.strict() : s,
) as 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;
}