From 9386696f4b5377e5a1ffb563a21d99e36e6f6f9e Mon Sep 17 00:00:00 2001 From: rubyowo Date: Mon, 9 Jan 2023 17:02:41 +0400 Subject: [PATCH 01/11] fix: crash when the arr argument for concatArr isn't specified fix: formatting Co-authored-by: Almeida --- backend/src/templateFormatter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/templateFormatter.ts b/backend/src/templateFormatter.ts index 0dcb7bde..af30fd4e 100644 --- a/backend/src/templateFormatter.ts +++ b/backend/src/templateFormatter.ts @@ -346,6 +346,7 @@ const baseValues = { return [...args].join(""); }, concatArr(arr, separator = "") { + if (!Array.isArray(arr)) return ""; return arr.join(separator); }, eq(...args) { From 48d56965522cd4e95d162b161c2957a8ecfd6fb6 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Fri, 22 Dec 2023 20:21:22 +0000 Subject: [PATCH 02/11] add missing "where" Signed-off-by: GitHub --- backend/src/data/GuildCounters.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/data/GuildCounters.ts b/backend/src/data/GuildCounters.ts index 4e69857b..fc853367 100644 --- a/backend/src/data/GuildCounters.ts +++ b/backend/src/data/GuildCounters.ts @@ -285,7 +285,11 @@ export class GuildCounters extends BaseGuildRepository { reverse_comparison_value: reverseComparisonValue, }); - return (await entityManager.findOne(CounterTrigger, insertResult.identifiers[0].id))!; + return (await entityManager.findOne(CounterTrigger, { + where: { + id: insertResult.identifiers[0].id + } + }))!; }); } From 94a712832a0e429cb8d96a5034e54eae82079bdb Mon Sep 17 00:00:00 2001 From: Tiago R Date: Wed, 27 Dec 2023 18:20:48 +0000 Subject: [PATCH 03/11] Display available emojis separately from total on server info (#433) * respect .available (almeida-approved code!!) Signed-off-by: GitHub * Update backend/src/plugins/Utility/functions/getServerInfoEmbed.ts Co-authored-by: Almeida --------- Signed-off-by: GitHub Co-authored-by: Almeida --- .../src/plugins/Utility/functions/getServerInfoEmbed.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts index 37050613..d0202db7 100644 --- a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts @@ -205,9 +205,14 @@ export async function getServerInfoEmbed( [GuildPremiumTier.Tier3]: 60, }[restGuild.premiumTier] ?? 0; + const availableEmojis = restGuild.emojis.cache.filter((e) => e.available); otherStats.push( - `Emojis: **${restGuild.emojis.cache.size}** / ${maxEmojis * 2}${ + `Emojis: **${availableEmojis.size}** / ${maxEmojis * 2}${ roleLockedEmojis ? ` (__${roleLockedEmojis} role-locked__)` : "" + }${ + availableEmojis.size < restGuild.emojis.cache.size + ? ` (__+${restGuild.emojis.cache.size - availableEmojis.size} unavailable__)` + : "" }`, ); otherStats.push(`Stickers: **${restGuild.stickers.cache.size}** / ${maxStickers}`); From cf55eb161f4e2adc7cb5e7c7060b5603b06e96dc Mon Sep 17 00:00:00 2001 From: Almeida Date: Wed, 27 Dec 2023 18:30:08 +0000 Subject: [PATCH 04/11] fix formatting and globs in package.json (#440) --- backend/src/data/GuildCounters.ts | 4 ++-- package.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/data/GuildCounters.ts b/backend/src/data/GuildCounters.ts index fc853367..0c8fde5b 100644 --- a/backend/src/data/GuildCounters.ts +++ b/backend/src/data/GuildCounters.ts @@ -287,8 +287,8 @@ export class GuildCounters extends BaseGuildRepository { return (await entityManager.findOne(CounterTrigger, { where: { - id: insertResult.identifiers[0].id - } + id: insertResult.identifiers[0].id, + }, }))!; }); } diff --git a/package.json b/package.json index 0cec2093..3250124d 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "", "private": true, "scripts": { - "format": "prettier --write './backend/src/**/*.{css,html,js,json,ts,tsx}' './dashboard/src/**/*.{css,html,js,json,ts,tsx}'", - "lint": "eslint './backend/src/**/*.{js,ts,tsx}' './dashboard/src/**/*.{js,ts,tsx}'", - "codestyle-check": "prettier --check './backend/src/**/*.{css,html,js,json,ts,tsx}' './dashboard/src/**/*.{css,html,js,json,ts,tsx}'" + "format": "prettier --write \"./backend/src/**/*.{css,html,js,json,ts,tsx}\" \"./dashboard/src/**/*.{css,html,js,json,ts,tsx}\"", + "lint": "eslint \"./backend/src/**/*.{js,ts,tsx}\" \"./dashboard/src/**/*.{js,ts,tsx}\"", + "codestyle-check": "prettier --check \"./backend/src/**/*.{css,html,js,json,ts,tsx}\" \"./dashboard/src/**/*.{css,html,js,json,ts,tsx}\"" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.59.5", From e5e574625a2ee7442c01df2e5da1117754b27ed0 Mon Sep 17 00:00:00 2001 From: zay <87788699+zayKenyon@users.noreply.github.com> Date: Wed, 27 Dec 2023 18:33:20 +0000 Subject: [PATCH 05/11] chore(basic-config): rename plugin (#359) --- dashboard/src/components/docs/ConfigurationFormat.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard/src/components/docs/ConfigurationFormat.vue b/dashboard/src/components/docs/ConfigurationFormat.vue index 1d790ffa..426563e1 100644 --- a/dashboard/src/components/docs/ConfigurationFormat.vue +++ b/dashboard/src/components/docs/ConfigurationFormat.vue @@ -20,7 +20,7 @@ "172950000412655616": 50 # Example mod plugins: - mod_plugin: + mod_actions: config: kick_message: 'You have been kicked' can_kick: false From f17232e0c142012cf236443b8f03cbcb3cea1e3d Mon Sep 17 00:00:00 2001 From: Tiago R Date: Wed, 27 Dec 2023 18:35:16 +0000 Subject: [PATCH 06/11] dont allow self targeting for set-perms (#434) Signed-off-by: GitHub --- backend/src/api/guilds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/guilds.ts b/backend/src/api/guilds.ts index ba937093..4fef738f 100644 --- a/backend/src/api/guilds.ts +++ b/backend/src/api/guilds.ts @@ -126,7 +126,7 @@ export function initGuildsAPI(app: express.Express) { if (type !== ApiPermissionTypes.User) { return clientError(res, "Invalid type"); } - if (!isSnowflake(targetId)) { + if (!isSnowflake(targetId) || targetId === req.user!.userId) { return clientError(res, "Invalid targetId"); } const validPermissions = new Set(Object.values(ApiPermissions)); From 00fb71f26d2772904ef6fb89312161fcd922ef1a Mon Sep 17 00:00:00 2001 From: Tiago R Date: Wed, 27 Dec 2023 18:36:37 +0000 Subject: [PATCH 07/11] compose: Don't expose MySQL through all interfaces (#435) Signed-off-by: GitHub --- docker-compose.production.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.production.yml b/docker-compose.production.yml index 672b9044..7dfc145b 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -21,7 +21,7 @@ services: MYSQL_USER: zeppelin MYSQL_PASSWORD: ${DOCKER_PROD_MYSQL_PASSWORD?:Missing DOCKER_PROD_MYSQL_PASSWORD} ports: - - ${DOCKER_PROD_MYSQL_PORT:?Missing DOCKER_PROD_MYSQL_PORT}:3306 + - 127.0.0.1:${DOCKER_PROD_MYSQL_PORT:?Missing DOCKER_PROD_MYSQL_PORT}:3306 volumes: - ./docker/production/data/mysql:/var/lib/mysql command: --authentication-policy=mysql_native_password From d162418be5288edcca7483acac089c2ff6da130e Mon Sep 17 00:00:00 2001 From: Tiago R Date: Wed, 27 Dec 2023 18:38:26 +0000 Subject: [PATCH 08/11] Add missing dependency to mutes plugin & fix timeout expiry (#430) * +debug Signed-off-by: GitHub * Revert "+debug" This reverts commit 83daee09d9e63ad0c162f4ec30d42b03ab4bdc7f. * add missing dependency to mutes Signed-off-by: GitHub * lower max timeout duration Signed-off-by: GitHub --------- Signed-off-by: GitHub --- backend/src/data/Mutes.ts | 2 +- backend/src/plugins/Mutes/MutesPlugin.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/data/Mutes.ts b/backend/src/data/Mutes.ts index ec7f11cc..ad50dcee 100644 --- a/backend/src/data/Mutes.ts +++ b/backend/src/data/Mutes.ts @@ -8,7 +8,7 @@ import { Mute } from "./entities/Mute"; const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS; -export const MAX_TIMEOUT_DURATION = 28 * DAYS; +export const MAX_TIMEOUT_DURATION = 27 * DAYS; // When a timeout is under this duration but the mute expires later, the timeout will be reset to max duration export const TIMEOUT_RENEWAL_THRESHOLD = 21 * DAYS; diff --git a/backend/src/plugins/Mutes/MutesPlugin.ts b/backend/src/plugins/Mutes/MutesPlugin.ts index 1a205bbe..ddc347ec 100644 --- a/backend/src/plugins/Mutes/MutesPlugin.ts +++ b/backend/src/plugins/Mutes/MutesPlugin.ts @@ -8,6 +8,7 @@ import { GuildMutes } from "../../data/GuildMutes"; import { makeIoTsConfigParser, mapToPublicFn } from "../../pluginUtils"; import { CasesPlugin } from "../Cases/CasesPlugin"; import { LogsPlugin } from "../Logs/LogsPlugin"; +import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin.js"; import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint"; import { ClearBannedMutesCmd } from "./commands/ClearBannedMutesCmd"; import { ClearMutesCmd } from "./commands/ClearMutesCmd"; @@ -68,7 +69,7 @@ export const MutesPlugin = zeppelinGuildPlugin()({ configSchema: ConfigSchema, }, - dependencies: () => [CasesPlugin, LogsPlugin], + dependencies: () => [CasesPlugin, LogsPlugin, RoleManagerPlugin], configParser: makeIoTsConfigParser(ConfigSchema), defaultOptions, From 047ab872df05f986564f6e465f9cc7deca65ca27 Mon Sep 17 00:00:00 2001 From: Almeida Date: Wed, 27 Dec 2023 18:44:35 +0000 Subject: [PATCH 09/11] fix parsing of file extension in match_attachment_type trigger (#425) --- backend/src/plugins/Automod/triggers/matchAttachmentType.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/Automod/triggers/matchAttachmentType.ts b/backend/src/plugins/Automod/triggers/matchAttachmentType.ts index 659be65b..bb6c06fe 100644 --- a/backend/src/plugins/Automod/triggers/matchAttachmentType.ts +++ b/backend/src/plugins/Automod/triggers/matchAttachmentType.ts @@ -1,5 +1,6 @@ import { escapeInlineCode, Snowflake } from "discord.js"; import * as t from "io-ts"; +import { extname } from "path"; import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils"; import { automodTrigger } from "../helpers"; @@ -33,7 +34,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger()({ } for (const attachment of context.message.data.attachments) { - const attachmentType = attachment.url.split(".").pop()!.toLowerCase(); + const attachmentType = extname(new URL(attachment.url).pathname).slice(1).toLowerCase(); const blacklist = trigger.blacklist_enabled ? (trigger.filetype_blacklist || []).map((_t) => _t.toLowerCase()) From 8860d4fb22e175a543332c6b880427508e09411f Mon Sep 17 00:00:00 2001 From: Tiago R Date: Thu, 28 Dec 2023 14:41:32 +0000 Subject: [PATCH 10/11] Timeouts: better validations (#438) * better timeout validations Signed-off-by: GitHub * almeida reviews Signed-off-by: GitHub * better error handling Signed-off-by: GitHub * add missing catch noops Signed-off-by: GitHub --------- Signed-off-by: GitHub --- backend/src/RecoverablePluginError.ts | 4 ++++ .../events/ReapplyActiveMuteOnJoinEvt.ts | 12 ++++++++-- .../src/plugins/Mutes/functions/muteUser.ts | 22 +++++++++++++++++-- .../Mutes/functions/renewTimeoutMute.ts | 12 ++++++++-- .../src/plugins/Mutes/functions/unmuteUser.ts | 8 ++++--- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/backend/src/RecoverablePluginError.ts b/backend/src/RecoverablePluginError.ts index b621fd41..46a86ae5 100644 --- a/backend/src/RecoverablePluginError.ts +++ b/backend/src/RecoverablePluginError.ts @@ -9,6 +9,8 @@ export enum ERRORS { INVALID_USER, INVALID_MUTE_ROLE_ID, MUTE_ROLE_ABOVE_ZEP, + USER_ABOVE_ZEP, + USER_NOT_MODERATABLE, } export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = { @@ -20,6 +22,8 @@ export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = { [ERRORS.INVALID_USER]: "Invalid user", [ERRORS.INVALID_MUTE_ROLE_ID]: "Specified mute role is not valid", [ERRORS.MUTE_ROLE_ABOVE_ZEP]: "Specified mute role is above Zeppelin in the role hierarchy", + [ERRORS.USER_ABOVE_ZEP]: "Cannot mute user, specified user is above Zeppelin in the role hierarchy", + [ERRORS.USER_NOT_MODERATABLE]: "Cannot mute user, specified user is not moderatable", }; export class RecoverablePluginError extends Error { diff --git a/backend/src/plugins/Mutes/events/ReapplyActiveMuteOnJoinEvt.ts b/backend/src/plugins/Mutes/events/ReapplyActiveMuteOnJoinEvt.ts index a859f7ad..6db4f27c 100644 --- a/backend/src/plugins/Mutes/events/ReapplyActiveMuteOnJoinEvt.ts +++ b/backend/src/plugins/Mutes/events/ReapplyActiveMuteOnJoinEvt.ts @@ -1,5 +1,6 @@ import moment from "moment-timezone"; import { MuteTypes } from "../../../data/MuteTypes"; +import { noop } from "../../../utils.js"; import { LogsPlugin } from "../../Logs/LogsPlugin"; import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin"; import { getTimeoutExpiryTime } from "../functions/getTimeoutExpiryTime"; @@ -12,6 +13,7 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({ event: "guildMemberAdd", async listener({ pluginData, args: { member } }) { const mute = await pluginData.state.mutes.findExistingMuteForUserId(member.id); + const logs = pluginData.getPlugin(LogsPlugin); if (!mute) { return; } @@ -25,11 +27,17 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({ if (!member.isCommunicationDisabled()) { const expiresAt = mute.expires_at ? moment.utc(mute.expires_at).valueOf() : null; const timeoutExpiresAt = getTimeoutExpiryTime(expiresAt); - await member.disableCommunicationUntil(timeoutExpiresAt); + if (member.moderatable) { + await member.disableCommunicationUntil(timeoutExpiresAt).catch(noop); + } else { + logs.logBotAlert({ + body: `Cannot mute user, specified user is not moderatable`, + }); + } } } - pluginData.getPlugin(LogsPlugin).logMemberMuteRejoin({ + logs.logMemberMuteRejoin({ member, }); }, diff --git a/backend/src/plugins/Mutes/functions/muteUser.ts b/backend/src/plugins/Mutes/functions/muteUser.ts index fc864ada..575f96fb 100644 --- a/backend/src/plugins/Mutes/functions/muteUser.ts +++ b/backend/src/plugins/Mutes/functions/muteUser.ts @@ -13,6 +13,7 @@ import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFor import { UserNotificationMethod, UserNotificationResult, + noop, notifyUser, resolveMember, resolveUser, @@ -108,7 +109,7 @@ export async function muteUser( if (zepRoles.size === 0 || !zepRoles.some((zepRole) => zepRole.position > actualMuteRole.position)) { lock.unlock(); logs.logBotAlert({ - body: `Cannot mute users, specified mute role is above Zeppelin in the role hierarchy`, + body: `Cannot mute user, specified mute role is above Zeppelin in the role hierarchy`, }); throw new RecoverablePluginError(ERRORS.MUTE_ROLE_ABOVE_ZEP, pluginData.guild); } @@ -117,7 +118,24 @@ export async function muteUser( pluginData.getPlugin(RoleManagerPlugin).addPriorityRole(member.id, muteRole!); } } else { - await member.disableCommunicationUntil(timeoutUntil); + if (!member.manageable) { + lock.unlock(); + logs.logBotAlert({ + body: `Cannot mute user, specified user is above Zeppelin in the role hierarchy`, + }); + throw new RecoverablePluginError(ERRORS.USER_ABOVE_ZEP, pluginData.guild); + } + + if (!member.moderatable) { + // redundant safety, since canActOn already checks this + lock.unlock(); + logs.logBotAlert({ + body: `Cannot mute user, specified user is not moderatable`, + }); + throw new RecoverablePluginError(ERRORS.USER_NOT_MODERATABLE, pluginData.guild); + } + + await member.disableCommunicationUntil(timeoutUntil).catch(noop); } // If enabled, move the user to the mute voice channel (e.g. afk - just to apply the voice perms from the mute role) diff --git a/backend/src/plugins/Mutes/functions/renewTimeoutMute.ts b/backend/src/plugins/Mutes/functions/renewTimeoutMute.ts index 57def080..8363cf9f 100644 --- a/backend/src/plugins/Mutes/functions/renewTimeoutMute.ts +++ b/backend/src/plugins/Mutes/functions/renewTimeoutMute.ts @@ -3,7 +3,8 @@ import { GuildPluginData } from "knub"; import moment from "moment-timezone"; import { MAX_TIMEOUT_DURATION } from "../../../data/Mutes"; import { Mute } from "../../../data/entities/Mute"; -import { DBDateFormat, resolveMember } from "../../../utils"; +import { DBDateFormat, noop, resolveMember } from "../../../utils"; +import { LogsPlugin } from "../../Logs/LogsPlugin.js"; import { MutesPluginType } from "../types"; export async function renewTimeoutMute(pluginData: GuildPluginData, mute: Mute) { @@ -24,6 +25,13 @@ export async function renewTimeoutMute(pluginData: GuildPluginData Date: Thu, 28 Dec 2023 20:14:26 +0000 Subject: [PATCH 11/11] Reworked automod "set_slowmode" action (#441) * initial * fixes Signed-off-by: GitHub --------- Signed-off-by: GitHub Co-authored-by: Almeida --- .../src/plugins/Automod/actions/setSlowmode.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/src/plugins/Automod/actions/setSlowmode.ts b/backend/src/plugins/Automod/actions/setSlowmode.ts index 7b527f10..abd27f8a 100644 --- a/backend/src/plugins/Automod/actions/setSlowmode.ts +++ b/backend/src/plugins/Automod/actions/setSlowmode.ts @@ -6,7 +6,7 @@ import { automodAction } from "../helpers"; export const SetSlowmodeAction = automodAction({ configType: t.type({ - channels: t.array(t.string), + channels: tNullable(t.array(t.string)), duration: tNullable(tDelayString), }), @@ -14,14 +14,17 @@ export const SetSlowmodeAction = automodAction({ duration: "10s", }, - async apply({ pluginData, actionConfig }) { + async apply({ pluginData, actionConfig, contexts }) { const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0); - - for (const channelId of actionConfig.channels) { + const channels: Snowflake[] = actionConfig.channels ?? []; + if (channels.length === 0) { + channels.push(...contexts.filter((c) => c.message?.channel_id).map((c) => c.message!.channel_id)); + } + for (const channelId of channels) { const channel = pluginData.guild.channels.cache.get(channelId as Snowflake); - // Only text channels and text channels within categories support slowmodes - if (!channel || (!channel.isTextBased() && channel.type !== ChannelType.GuildCategory)) { + + if (!channel?.isTextBased() && channel?.type !== ChannelType.GuildCategory) { continue; }