Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions backend/src/data/GuildCases.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { In, InsertResult, Repository } from "typeorm";
import { FindOptionsWhere } from "typeorm";
import { FindOptionsWhere, In, InsertResult, Repository } from "typeorm";
import { Queue } from "../Queue.js";
import { chunkArray } from "../utils.js";
import { BaseGuildRepository } from "./BaseGuildRepository.js";
Expand Down
34 changes: 34 additions & 0 deletions backend/src/humanizeDuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import humanizeduration from "humanize-duration";

export const delayStringMultipliers = {
y: 1000 * 60 * 60 * 24 * (365 + 1 / 4 - 1 / 100 + 1 / 400),
mo: (1000 * 60 * 60 * 24 * (365 + 1 / 4 - 1 / 100 + 1 / 400)) / 12,
w: 1000 * 60 * 60 * 24 * 7,
d: 1000 * 60 * 60 * 24,
h: 1000 * 60 * 60,
m: 1000 * 60,
s: 1000,
x: 1,
};

export const humanizeDurationShort = humanizeduration.humanizer({
language: "shortEn",
languages: {
shortEn: {
y: () => "y",
mo: () => "mo",
w: () => "w",
d: () => "d",
h: () => "h",
m: () => "m",
s: () => "s",
ms: () => "ms",
},
},
spacer: "",
unitMeasures: delayStringMultipliers,
});

export const humanizeDuration = humanizeduration.humanizer({
unitMeasures: delayStringMultipliers,
});
18 changes: 0 additions & 18 deletions backend/src/humanizeDurationShort.ts

This file was deleted.

10 changes: 9 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ import { availableGlobalPlugins, availableGuildPlugins } from "./plugins/availab
import { setProfiler } from "./profiler.js";
import { logRateLimit } from "./rateLimitStats.js";
import { startUptimeCounter } from "./uptime.js";
import { MINUTES, SECONDS, errorMessage, isDiscordAPIError, isDiscordHTTPError, sleep, successMessage } from "./utils.js";
import {
MINUTES,
SECONDS,
errorMessage,
isDiscordAPIError,
isDiscordHTTPError,
sleep,
successMessage,
} from "./utils.js";
import { DecayingCounter } from "./utils/DecayingCounter.js";
import { enableProfiling } from "./utils/easyProfiler.js";
import { loadYamlSafely } from "./utils/loadYamlSafely.js";
Expand Down
7 changes: 6 additions & 1 deletion backend/src/plugins/Automod/functions/applyCooldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { GuildPluginData } from "knub";
import { convertDelayStringToMS } from "../../../utils.js";
import { AutomodContext, AutomodPluginType, TRule } from "../types.js";

export function applyCooldown(pluginData: GuildPluginData<AutomodPluginType>, rule: TRule, ruleName: string, context: AutomodContext) {
export function applyCooldown(
pluginData: GuildPluginData<AutomodPluginType>,
rule: TRule,
ruleName: string,
context: AutomodContext,
) {
const cooldownKey = `${ruleName}-${context.user?.id}`;

const cooldownTime = convertDelayStringToMS(rule.cooldown, "s");
Expand Down
7 changes: 6 additions & 1 deletion backend/src/plugins/Automod/functions/checkCooldown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { GuildPluginData } from "knub";
import { AutomodContext, AutomodPluginType, TRule } from "../types.js";

export function checkCooldown(pluginData: GuildPluginData<AutomodPluginType>, rule: TRule, ruleName: string, context: AutomodContext) {
export function checkCooldown(
pluginData: GuildPluginData<AutomodPluginType>,
rule: TRule,
ruleName: string,
context: AutomodContext,
) {
const cooldownKey = `${ruleName}-${context.user?.id}`;

return pluginData.state.cooldownManager.isOnCooldown(cooldownKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import z from "zod";
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
import { humanizeDurationShort } from "../../../humanizeDurationShort.js";
import { humanizeDurationShort } from "../../../humanizeDuration.js";
import { getBaseUrl } from "../../../pluginUtils.js";
import { convertDelayStringToMS, sorter, zDelayString } from "../../../utils.js";
import { RecentActionType } from "../constants.js";
Expand Down
25 changes: 13 additions & 12 deletions backend/src/plugins/Automod/triggers/matchAttachmentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ const baseConfig = z.strictObject({
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
filetype_whitelist: z.array(z.string().max(32)).max(255).default([]),
});
const configWithWhitelist = baseConfig.merge(z.strictObject({
whitelist_enabled: z.literal(true),
blacklist_enabled: z.literal(false).default(false),
}));
const configWithBlacklist = baseConfig.merge(z.strictObject({
blacklist_enabled: z.literal(true),
whitelist_enabled: z.literal(false).default(false),
}));
const configWithWhitelist = baseConfig.merge(
z.strictObject({
whitelist_enabled: z.literal(true),
blacklist_enabled: z.literal(false).default(false),
}),
);
const configWithBlacklist = baseConfig.merge(
z.strictObject({
blacklist_enabled: z.literal(true),
whitelist_enabled: z.literal(false).default(false),
}),
);

const configSchema = z.union([
configWithWhitelist,
configWithBlacklist,
]);
const configSchema = z.union([configWithWhitelist, configWithBlacklist]);

export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
configSchema,
Expand Down
25 changes: 13 additions & 12 deletions backend/src/plugins/Automod/triggers/matchMimeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ const baseConfig = z.strictObject({
mime_type_blacklist: z.array(z.string().max(32)).max(255).default([]),
mime_type_whitelist: z.array(z.string().max(32)).max(255).default([]),
});
const configWithWhitelist = baseConfig.merge(z.strictObject({
whitelist_enabled: z.literal(true),
blacklist_enabled: z.literal(false).default(false),
}));
const configWithBlacklist = baseConfig.merge(z.strictObject({
blacklist_enabled: z.literal(true),
whitelist_enabled: z.literal(false).default(false),
}));
const configWithWhitelist = baseConfig.merge(
z.strictObject({
whitelist_enabled: z.literal(true),
blacklist_enabled: z.literal(false).default(false),
}),
);
const configWithBlacklist = baseConfig.merge(
z.strictObject({
blacklist_enabled: z.literal(true),
whitelist_enabled: z.literal(false).default(false),
}),
);

const configSchema = z.union([
configWithWhitelist,
configWithBlacklist,
]);
const configSchema = z.union([configWithWhitelist, configWithBlacklist]);

export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
configSchema,
Expand Down
8 changes: 7 additions & 1 deletion backend/src/plugins/Censor/util/applyFiltersToMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { GuildPluginData } from "knub";
import { allowTimeout } from "../../../RegExpRunner.js";
import { ZalgoRegex } from "../../../data/Zalgo.js";
import { ISavedMessageEmbedData, SavedMessage } from "../../../data/entities/SavedMessage.js";
import { getInviteCodesInString, getUrlsInString, isGuildInvite, resolveInvite, resolveMember } from "../../../utils.js";
import {
getInviteCodesInString,
getUrlsInString,
isGuildInvite,
resolveInvite,
resolveMember,
} from "../../../utils.js";
import { CensorPluginType } from "../types.js";
import { censorMessage } from "./censorMessage.js";

Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/ContextMenus/actions/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
TextInputBuilder,
TextInputStyle,
} from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { logger } from "../../../logger.js";
import { canActOn } from "../../../pluginUtils.js";
import { convertDelayStringToMS, renderUserUsername } from "../../../utils.js";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/ContextMenus/actions/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
TextInputBuilder,
TextInputStyle,
} from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError.js";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { logger } from "../../../logger.js";
import { canActOn } from "../../../pluginUtils.js";
import { convertDelayStringToMS } from "../../../utils.js";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/Counters/CountersPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PluginOptions, guildPlugin } from "knub";
import { GuildCounters } from "../../data/GuildCounters.js";
import { CounterTrigger, parseCounterConditionString } from "../../data/entities/CounterTrigger.js";
import { makePublicFn } from "../../pluginUtils.js";
import { MINUTES, convertDelayStringToMS, values } from "../../utils.js";
import { MINUTES, convertDelayStringToMS } from "../../utils.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { AddCounterCmd } from "./commands/AddCounterCmd.js";
import { CountersListCmd } from "./commands/CountersListCmd.js";
Expand Down
8 changes: 6 additions & 2 deletions backend/src/plugins/Counters/commands/AddCounterCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ export const AddCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
`Added ${amount} to **${args.counterName}** for <@!${user.id}> in <#${channel.id}>. The value is now ${newValue}.`,
);
} else if (channel) {
message.channel.send(`Added ${amount} to **${args.counterName}** in <#${channel.id}>. The value is now ${newValue}.`);
message.channel.send(
`Added ${amount} to **${args.counterName}** in <#${channel.id}>. The value is now ${newValue}.`,
);
} else if (user) {
message.channel.send(`Added ${amount} to **${args.counterName}** for <@!${user.id}>. The value is now ${newValue}.`);
message.channel.send(
`Added ${amount} to **${args.counterName}** for <@!${user.id}>. The value is now ${newValue}.`,
);
} else {
message.channel.send(`Added ${amount} to **${args.counterName}**. The value is now ${newValue}.`);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/LocateUser/commands/FollowCmd.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import humanizeDuration from "humanize-duration";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { registerExpiringVCAlert } from "../../../data/loops/expiringVCAlertsLoop.js";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { MINUTES, SECONDS } from "../../../utils.js";
import { locateUserCmd } from "../types.js";

Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/Logs/LogsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { LogsThreadCreateEvt, LogsThreadDeleteEvt, LogsThreadUpdateEvt } from "./events/LogsThreadModifyEvts.js";
import { LogsGuildMemberUpdateEvt } from "./events/LogsUserUpdateEvts.js";
import { LogsVoiceStateUpdateEvt } from "./events/LogsVoiceChannelEvts.js";
import { FORMAT_NO_TIMESTAMP, LogsPluginType, zLogsConfig } from "./types.js";
import { LogsPluginType, zLogsConfig } from "./types.js";
import { getLogMessage } from "./util/getLogMessage.js";
import { log } from "./util/log.js";
import { onMessageDelete } from "./util/onMessageDelete.js";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/Logs/logFunctions/logMemberJoin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GuildMember } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { LogType } from "../../../data/LogType.js";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter.js";
import { memberToTemplateSafeMember } from "../../../utils/templateSafeObjects.js";
import { LogsPluginType } from "../types.js";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/Logs/logFunctions/logMessageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
userToTemplateSafeUser,
} from "../../../utils/templateSafeObjects.js";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin.js";
import { FORMAT_NO_TIMESTAMP, LogsPluginType } from "../types.js";
import { LogsPluginType } from "../types.js";
import { log } from "../util/log.js";

export interface LogMessageDeleteData {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/Logs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GuildCases } from "../../data/GuildCases.js";
import { GuildLogs } from "../../data/GuildLogs.js";
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
import { LogType } from "../../data/LogType.js";
import { keys, zBoundedCharacters, zMessageContent, zRegex, zSnowflake } from "../../utils.js";
import { zBoundedCharacters, zMessageContent, zRegex, zSnowflake } from "../../utils.js";
import { MessageBuffer } from "../../utils/MessageBuffer.js";
import {
TemplateSafeCase,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/Logs/util/getLogMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
TemplateSafeUser,
} from "../../../utils/templateSafeObjects.js";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin.js";
import { FORMAT_NO_TIMESTAMP, ILogTypeData, LogsPluginType, TLogChannel } from "../types.js";
import { ILogTypeData, LogsPluginType, TLogChannel } from "../types.js";

export async function getLogMessage<TLogType extends keyof ILogTypeData>(
pluginData: GuildPluginData<LogsPluginType>,
Expand Down
7 changes: 6 additions & 1 deletion backend/src/plugins/MessageSaver/MessageSaverPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
import { CommonPlugin } from "../Common/CommonPlugin.js";
import { SaveMessagesToDBCmd } from "./commands/SaveMessagesToDB.js";
import { SavePinsToDBCmd } from "./commands/SavePinsToDB.js";
import { MessageCreateEvt, MessageDeleteBulkEvt, MessageDeleteEvt, MessageUpdateEvt } from "./events/SaveMessagesEvts.js";
import {
MessageCreateEvt,
MessageDeleteBulkEvt,
MessageDeleteEvt,
MessageUpdateEvt,
} from "./events/SaveMessagesEvts.js";
import { MessageSaverPluginType, zMessageSaverConfig } from "./types.js";

const defaultOptions: PluginOptions<MessageSaverPluginType> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { getMemberLevel } from "knub/helpers";
import { CaseTypes } from "../../../../data/CaseTypes.js";
import { clearExpiringTempban, registerExpiringTempban } from "../../../../data/loops/expiringTempbansLoop.js";
import { humanizeDuration } from "../../../../humanizeDuration.js";
import { canActOn, getContextChannel } from "../../../../pluginUtils.js";
import { UnknownUser, UserNotificationMethod, renderUsername, resolveMember } from "../../../../utils.js";
import { banLock } from "../../../../utils/lockNameHelpers.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { APIEmbed, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import { GuildPluginData } from "knub";
import { In } from "typeorm";
import { FindOptionsWhere } from "typeorm";
import { FindOptionsWhere, In } from "typeorm";
import { CaseTypes } from "../../../../data/CaseTypes.js";
import { Case } from "../../../../data/entities/Case.js";
import { sendContextResponse } from "../../../../pluginUtils.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } f
import { GuildPluginData } from "knub";
import { LogType } from "../../../../data/LogType.js";
import { canActOn } from "../../../../pluginUtils.js";
import { DAYS, SECONDS, UnknownUser, UserNotificationMethod, renderUsername, resolveMember } from "../../../../utils.js";
import {
DAYS,
SECONDS,
UnknownUser,
UserNotificationMethod,
renderUsername,
resolveMember,
} from "../../../../utils.js";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction.js";
import {
formatReasonWithAttachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflak
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes.js";
import { LogType } from "../../../../data/LogType.js";
import { humanizeDurationShort } from "../../../../humanizeDurationShort.js";
import { humanizeDurationShort } from "../../../../humanizeDuration.js";
import { canActOn, getContextChannel, isContextInteraction, sendContextResponse } from "../../../../pluginUtils.js";
import { DAYS, MINUTES, SECONDS, noop } from "../../../../utils.js";
import { CasesPlugin } from "../../../Cases/CasesPlugin.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { ERRORS, RecoverablePluginError } from "../../../../RecoverablePluginError.js";
import { humanizeDuration } from "../../../../humanizeDuration.js";
import { logger } from "../../../../logger.js";
import {
UnknownUser,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { humanizeDuration } from "../../../../humanizeDuration.js";
import { UnknownUser, asSingleLine, renderUsername } from "../../../../utils.js";
import { MutesPlugin } from "../../../Mutes/MutesPlugin.js";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction.js";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/ModActions/functions/banUserId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DiscordAPIError, Snowflake } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../data/CaseTypes.js";
import { LogType } from "../../../data/LogType.js";
import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop.js";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { logger } from "../../../logger.js";
import { TemplateParseError, TemplateSafeValueContainer, renderTemplate } from "../../../templateFormatter.js";
import {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/ModActions/functions/clearTempban.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Snowflake } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { CaseTypes } from "../../../data/CaseTypes.js";
import { LogType } from "../../../data/LogType.js";
import { Tempban } from "../../../data/entities/Tempban.js";
import { humanizeDuration } from "../../../humanizeDuration.js";
import { logger } from "../../../logger.js";
import { resolveUser } from "../../../utils.js";
import { CasesPlugin } from "../../Cases/CasesPlugin.js";
Expand Down
Loading
Loading