diff --git a/.clabot b/.clabot index 381bf599..43dcfc5f 100644 --- a/.clabot +++ b/.clabot @@ -23,7 +23,12 @@ "iamshoXy", "Scraayp", "app/dependabot", - "zayKenyon" + "zayKenyon", + "rukogit", + "Obliie", + "brawaru", + "Benricheson101", + "hawkeye7662" ], "message": "Thank you for contributing to Zeppelin! We require contributors to sign our Contributor License Agreement (CLA). To let us review and merge your code, please visit https://github.com/ZeppelinBot/CLA to sign the CLA!" } diff --git a/backend/package-lock.json b/backend/package-lock.json index c617dd51..59f6e3a4 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -17,7 +17,6 @@ "discord.js": "^14.14.1", "dotenv": "^4.0.0", "emoji-regex": "^8.0.0", - "erlpack": "github:discord/erlpack", "escape-string-regexp": "^1.0.5", "express": "^4.17.0", "fp-ts": "^2.0.1", @@ -1573,14 +1572,6 @@ "node": ">=8" } }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, "node_modules/bit-twiddle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-1.0.2.tgz", @@ -3487,16 +3478,6 @@ "resolved": "https://registry.npmjs.org/env-string/-/env-string-1.0.1.tgz", "integrity": "sha512-/DhCJDf5DSFK32joQiWRpWrT0h7p3hVQfMKxiBb7Nt8C8IF8BYyPtclDnuGGLOoj16d/8udKeiE7JbkotDmorQ==" }, - "node_modules/erlpack": { - "version": "0.1.3", - "resolved": "git+ssh://git@github.com/discord/erlpack.git#cbe76be04c2210fc9cb6ff95910f0937c1011d04", - "hasInstallScript": true, - "license": "MIT", - "dependencies": { - "bindings": "^1.5.0", - "nan": "^2.15.0" - } - }, "node_modules/es5-ext": { "version": "0.10.62", "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", @@ -3945,10 +3926,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + "node_modules/file-type": { + "version": "18.5.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-18.5.0.tgz", + "integrity": "sha512-yvpl5U868+V6PqXHMmsESpg6unQ5GfnPssl4dxdJudBrr9qy7Fddt7EVX1VLlddFfe8Gj9N7goCZH22FXuSQXQ==", + "dependencies": { + "readable-web-to-node-stream": "^3.0.2", + "strtok3": "^7.0.0", + "token-types": "^5.0.1" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sindresorhus/file-type?sponsor=1" + } }, "node_modules/fill-range": { "version": "7.0.1", diff --git a/backend/package.json b/backend/package.json index 44101e51..d267aa6d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -38,7 +38,6 @@ "discord.js": "^14.14.1", "dotenv": "^4.0.0", "emoji-regex": "^8.0.0", - "erlpack": "github:discord/erlpack", "escape-string-regexp": "^1.0.5", "express": "^4.17.0", "fp-ts": "^2.0.1", diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index 3f253bc0..b77f3942 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -11,6 +11,7 @@ import { CleanAction } from "./clean"; import { KickAction } from "./kick"; import { LogAction } from "./log"; import { MuteAction } from "./mute"; +import { PauseInvitesAction } from "./pauseInvites"; import { RemoveRolesAction } from "./removeRoles"; import { ReplyAction } from "./reply"; import { SetAntiraidLevelAction } from "./setAntiraidLevel"; @@ -38,6 +39,7 @@ export const availableActions: Record> = { start_thread: StartThreadAction, archive_thread: ArchiveThreadAction, change_perms: ChangePermsAction, + pause_invites: PauseInvitesAction, }; export const AvailableActions = t.type({ @@ -59,4 +61,5 @@ export const AvailableActions = t.type({ start_thread: StartThreadAction.configType, archive_thread: ArchiveThreadAction.configType, change_perms: ChangePermsAction.configType, + pause_invites: PauseInvitesAction.configType, }); diff --git a/backend/src/plugins/Automod/actions/pauseInvites.ts b/backend/src/plugins/Automod/actions/pauseInvites.ts new file mode 100644 index 00000000..262b6912 --- /dev/null +++ b/backend/src/plugins/Automod/actions/pauseInvites.ts @@ -0,0 +1,19 @@ +import { GuildFeature } from "discord.js"; +import * as t from "io-ts"; +import { automodAction } from "../helpers"; + +export const PauseInvitesAction = automodAction({ + configType: t.type({ + paused: t.boolean, + }), + + defaultConfig: {}, + + async apply({ pluginData, actionConfig }) { + const hasInvitesDisabled = pluginData.guild.features.includes(GuildFeature.InvitesDisabled); + + if (actionConfig.paused !== hasInvitesDisabled) { + await pluginData.guild.disableInvites(actionConfig.paused); + } + }, +}); diff --git a/backend/src/plugins/Automod/events/runAutomodOnAntiraidLevel.ts b/backend/src/plugins/Automod/events/runAutomodOnAntiraidLevel.ts index 2dfc4bac..05dbb6f3 100644 --- a/backend/src/plugins/Automod/events/runAutomodOnAntiraidLevel.ts +++ b/backend/src/plugins/Automod/events/runAutomodOnAntiraidLevel.ts @@ -5,13 +5,15 @@ import { AutomodContext, AutomodPluginType } from "../types"; export async function runAutomodOnAntiraidLevel( pluginData: GuildPluginData, - level: string | null, + newLevel: string | null, + oldLevel: string | null, user?: User, ) { const context: AutomodContext = { timestamp: Date.now(), antiraid: { - level, + level: newLevel, + oldLevel, }, user, }; diff --git a/backend/src/plugins/Automod/functions/applyCooldown.ts b/backend/src/plugins/Automod/functions/applyCooldown.ts new file mode 100644 index 00000000..387ac448 --- /dev/null +++ b/backend/src/plugins/Automod/functions/applyCooldown.ts @@ -0,0 +1,10 @@ +import { GuildPluginData } from "knub"; +import { convertDelayStringToMS } from "../../../utils"; +import { AutomodContext, AutomodPluginType, TRule } from "../types"; + +export function applyCooldown(pluginData: GuildPluginData, rule: TRule, context: AutomodContext) { + const cooldownKey = `${rule.name}-${context.user?.id}`; + + const cooldownTime = convertDelayStringToMS(rule.cooldown, "s"); + if (cooldownTime) pluginData.state.cooldownManager.setCooldown(cooldownKey, cooldownTime); +} diff --git a/backend/src/plugins/Automod/functions/checkAndUpdateCooldown.ts b/backend/src/plugins/Automod/functions/checkAndUpdateCooldown.ts deleted file mode 100644 index 6338d698..00000000 --- a/backend/src/plugins/Automod/functions/checkAndUpdateCooldown.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { GuildPluginData } from "knub"; -import { convertDelayStringToMS } from "../../../utils"; -import { AutomodContext, AutomodPluginType, TRule } from "../types"; - -export function checkAndUpdateCooldown( - pluginData: GuildPluginData, - rule: TRule, - context: AutomodContext, -) { - const cooldownKey = `${rule.name}-${context.user?.id}`; - - if (cooldownKey) { - if (pluginData.state.cooldownManager.isOnCooldown(cooldownKey)) { - return true; - } - - const cooldownTime = convertDelayStringToMS(rule.cooldown, "s"); - if (cooldownTime) { - pluginData.state.cooldownManager.setCooldown(cooldownKey, cooldownTime); - } - } - - return false; -} diff --git a/backend/src/plugins/Automod/functions/checkCooldown.ts b/backend/src/plugins/Automod/functions/checkCooldown.ts new file mode 100644 index 00000000..3640c142 --- /dev/null +++ b/backend/src/plugins/Automod/functions/checkCooldown.ts @@ -0,0 +1,8 @@ +import { GuildPluginData } from "knub"; +import { AutomodContext, AutomodPluginType, TRule } from "../types"; + +export function checkCooldown(pluginData: GuildPluginData, rule: TRule, context: AutomodContext) { + const cooldownKey = `${rule.name}-${context.user?.id}`; + + return pluginData.state.cooldownManager.isOnCooldown(cooldownKey); +} diff --git a/backend/src/plugins/Automod/functions/runAutomod.ts b/backend/src/plugins/Automod/functions/runAutomod.ts index e9c2e3a7..4ccc38de 100644 --- a/backend/src/plugins/Automod/functions/runAutomod.ts +++ b/backend/src/plugins/Automod/functions/runAutomod.ts @@ -7,7 +7,8 @@ import { CleanAction } from "../actions/clean"; import { AutomodTriggerMatchResult } from "../helpers"; import { availableTriggers } from "../triggers/availableTriggers"; import { AutomodContext, AutomodPluginType } from "../types"; -import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown"; +import { applyCooldown } from "./applyCooldown"; +import { checkCooldown } from "./checkCooldown"; export async function runAutomod(pluginData: GuildPluginData, context: AutomodContext) { const userId = context.user?.id || context.member?.id || context.message?.user_id; @@ -46,7 +47,7 @@ export async function runAutomod(pluginData: GuildPluginData, } if (!rule.affects_self && userId && userId === pluginData.client.user?.id) continue; - if (rule.cooldown && checkAndUpdateCooldown(pluginData, rule, context)) { + if (rule.cooldown && checkCooldown(pluginData, rule, context)) { continue; } @@ -84,6 +85,8 @@ export async function runAutomod(pluginData: GuildPluginData, } if (matchResult) { + if (rule.cooldown) applyCooldown(pluginData, rule, context); + contexts = [context, ...(matchResult.extraContexts || [])]; for (const _context of contexts) { diff --git a/backend/src/plugins/Automod/functions/setAntiraidLevel.ts b/backend/src/plugins/Automod/functions/setAntiraidLevel.ts index a21d58b0..c76555c2 100644 --- a/backend/src/plugins/Automod/functions/setAntiraidLevel.ts +++ b/backend/src/plugins/Automod/functions/setAntiraidLevel.ts @@ -9,10 +9,11 @@ export async function setAntiraidLevel( newLevel: string | null, user?: User, ) { + const oldLevel = pluginData.state.cachedAntiraidLevel; pluginData.state.cachedAntiraidLevel = newLevel; await pluginData.state.antiraidLevels.set(newLevel); - runAutomodOnAntiraidLevel(pluginData, newLevel, user); + runAutomodOnAntiraidLevel(pluginData, newLevel, oldLevel, user); const logs = pluginData.getPlugin(LogsPlugin); diff --git a/backend/src/plugins/Automod/triggers/antiraidLevel.ts b/backend/src/plugins/Automod/triggers/antiraidLevel.ts index 7c6d17af..f5caa3f0 100644 --- a/backend/src/plugins/Automod/triggers/antiraidLevel.ts +++ b/backend/src/plugins/Automod/triggers/antiraidLevel.ts @@ -7,6 +7,7 @@ interface AntiraidLevelTriggerResult {} export const AntiraidLevelTrigger = automodTrigger()({ configType: t.type({ level: tNullable(t.string), + only_on_change: tNullable(t.boolean), }), defaultConfig: {}, @@ -20,6 +21,14 @@ export const AntiraidLevelTrigger = automodTrigger() return; } + if ( + triggerConfig.only_on_change && + context.antiraid.oldLevel !== undefined && + context.antiraid.level === context.antiraid.oldLevel + ) { + return; + } + return { extra: {}, }; diff --git a/backend/src/plugins/Automod/triggers/matchWords.ts b/backend/src/plugins/Automod/triggers/matchWords.ts index c5ca79fc..1deb64e5 100644 --- a/backend/src/plugins/Automod/triggers/matchWords.ts +++ b/backend/src/plugins/Automod/triggers/matchWords.ts @@ -54,7 +54,7 @@ export const MatchWordsTrigger = automodTrigger()({ const looseMatchingThreshold = Math.min(Math.max(trigger.loose_matching_threshold, 1), 64); const patterns = trigger.words.map((word) => { let pattern = trigger.loose_matching - ? [...word].map((c) => escapeStringRegexp(c)).join(`(?:\\s*|.{0,${looseMatchingThreshold})`) + ? [...word].map((c) => escapeStringRegexp(c)).join(`(?:\\s*|.{0,${looseMatchingThreshold}})`) : escapeStringRegexp(word); if (trigger.only_full_words) { diff --git a/backend/src/plugins/Automod/types.ts b/backend/src/plugins/Automod/types.ts index bd3f05ee..b9900089 100644 --- a/backend/src/plugins/Automod/types.ts +++ b/backend/src/plugins/Automod/types.ts @@ -130,6 +130,7 @@ export interface AutomodContext { }; antiraid?: { level: string | null; + oldLevel?: string | null; }; threadChange?: { created?: ThreadChannel; diff --git a/backend/src/plugins/Mutes/functions/clearMute.ts b/backend/src/plugins/Mutes/functions/clearMute.ts index 0bef1881..f96068c7 100644 --- a/backend/src/plugins/Mutes/functions/clearMute.ts +++ b/backend/src/plugins/Mutes/functions/clearMute.ts @@ -57,9 +57,10 @@ export async function clearMute( await member.timeout(null); } } + pluginData.getPlugin(LogsPlugin).logMemberMuteExpired({ member }); } catch { pluginData.getPlugin(LogsPlugin).logBotAlert({ - body: `Failed to remove mute role from ${verboseUserMention(member.user)}`, + body: `Failed to clear mute from ${verboseUserMention(member.user)}`, }); } finally { lock.unlock(); diff --git a/backend/src/plugins/Persist/PersistPlugin.ts b/backend/src/plugins/Persist/PersistPlugin.ts index ecd50067..bc914c44 100644 --- a/backend/src/plugins/Persist/PersistPlugin.ts +++ b/backend/src/plugins/Persist/PersistPlugin.ts @@ -3,7 +3,6 @@ import { GuildLogs } from "../../data/GuildLogs"; import { GuildPersistedData } from "../../data/GuildPersistedData"; import { makeIoTsConfigParser } from "../../pluginUtils"; import { trimPluginDescription } from "../../utils"; -import { GuildMemberCachePlugin } from "../GuildMemberCache/GuildMemberCachePlugin"; import { LogsPlugin } from "../Logs/LogsPlugin"; import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin"; import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint"; @@ -31,7 +30,7 @@ export const PersistPlugin = zeppelinGuildPlugin()({ configSchema: ConfigSchema, }, - dependencies: () => [LogsPlugin, RoleManagerPlugin, GuildMemberCachePlugin], + dependencies: () => [LogsPlugin, RoleManagerPlugin], configParser: makeIoTsConfigParser(ConfigSchema), defaultOptions, diff --git a/backend/src/plugins/Persist/events/StoreDataEvt.ts b/backend/src/plugins/Persist/events/StoreDataEvt.ts index 537c7b62..9385c279 100644 --- a/backend/src/plugins/Persist/events/StoreDataEvt.ts +++ b/backend/src/plugins/Persist/events/StoreDataEvt.ts @@ -1,5 +1,4 @@ import { PersistedData } from "../../../data/entities/PersistedData"; -import { GuildMemberCachePlugin } from "../../GuildMemberCache/GuildMemberCachePlugin"; import { persistEvt } from "../types"; export const StoreDataEvt = persistEvt({ @@ -9,8 +8,11 @@ export const StoreDataEvt = persistEvt({ const config = await pluginData.config.getForUser(member.user); const persistData: Partial = {}; + // FIXME: New caching thing, or fix deadlocks with this plugin if (member.partial) { + return; // Djs hasn't cached member data => use db cache + /* const data = await pluginData.getPlugin(GuildMemberCachePlugin).getCachedMemberData(member.id); if (!data) { return; @@ -22,7 +24,7 @@ export const StoreDataEvt = persistEvt({ } if (config.persist_nicknames && data.nickname) { persistData.nickname = data.nickname; - } + }*/ } else { // Djs has cached member data => use that const memberRoles = Array.from(member.roles.cache.keys()); diff --git a/backend/src/plugins/ReactionRoles/util/applyReactionRoleReactionsToMessage.ts b/backend/src/plugins/ReactionRoles/util/applyReactionRoleReactionsToMessage.ts index 94de8631..5d1b3a37 100644 --- a/backend/src/plugins/ReactionRoles/util/applyReactionRoleReactionsToMessage.ts +++ b/backend/src/plugins/ReactionRoles/util/applyReactionRoleReactionsToMessage.ts @@ -86,6 +86,12 @@ export async function applyReactionRoleReactionsToMessage( body: `Error ${e.code} while applying reaction role reactions to ${channelId}/${messageId}: ${e.message}`, }); break; + } else if (e.code === 30010) { + errors.push(`Maximum number of reactions reached (20)`); + logs.logBotAlert({ + body: `Error ${e.code} while applying reaction role reactions to ${channelId}/${messageId}: ${e.message}`, + }); + break; } } diff --git a/backend/src/plugins/availablePlugins.ts b/backend/src/plugins/availablePlugins.ts index 58af41fc..3df9c347 100644 --- a/backend/src/plugins/availablePlugins.ts +++ b/backend/src/plugins/availablePlugins.ts @@ -12,7 +12,6 @@ import { CustomEventsPlugin } from "./CustomEvents/CustomEventsPlugin"; import { GuildAccessMonitorPlugin } from "./GuildAccessMonitor/GuildAccessMonitorPlugin"; import { GuildConfigReloaderPlugin } from "./GuildConfigReloader/GuildConfigReloaderPlugin"; import { GuildInfoSaverPlugin } from "./GuildInfoSaver/GuildInfoSaverPlugin"; -import { GuildMemberCachePlugin } from "./GuildMemberCache/GuildMemberCachePlugin"; import { InternalPosterPlugin } from "./InternalPoster/InternalPosterPlugin"; import { LocateUserPlugin } from "./LocateUser/LocateUserPlugin"; import { LogsPlugin } from "./Logs/LogsPlugin"; @@ -54,7 +53,7 @@ export const guildPlugins: Array> = [ PostPlugin, ReactionRolesPlugin, MessageSaverPlugin, - GuildMemberCachePlugin, + // GuildMemberCachePlugin, // FIXME: New caching thing, or fix deadlocks with this plugin ModActionsPlugin, NameHistoryPlugin, RemindersPlugin, @@ -93,7 +92,7 @@ export const baseGuildPlugins: Array> = [ GuildInfoSaverPlugin, MessageSaverPlugin, NameHistoryPlugin, - GuildMemberCachePlugin, + // GuildMemberCachePlugin, // FIXME: New caching thing, or fix deadlocks with this plugin CasesPlugin, MutesPlugin, TimeAndDatePlugin, diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 7d8e0a29..eccce81f 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -135,7 +135,7 @@ export interface TDeepPartialProps

{ [K in keyof P]?: TDeepPartial>; } - > { } + > {} export function tDeepPartial(type: T): TDeepPartial { if (type instanceof t.InterfaceType || type instanceof t.PartialType) { @@ -220,7 +220,7 @@ export interface PartialDictionaryC [K in t.OutputOf]?: t.OutputOf; }, unknown - > { } + > {} export const tPartialDictionary = ( domain: D, @@ -652,7 +652,13 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] { return urls; } - const hostnameParts = matchUrl.hostname.split("."); + let hostname = matchUrl.hostname.toLowerCase(); + + if (hostname.length > 3) { + hostname = hostname.replace(/[^a-z]+$/, ""); + } + + const hostnameParts = hostname.split("."); const tld = hostnameParts[hostnameParts.length - 1]; if (tlds.includes(tld)) { urls.push(matchUrl); @@ -1617,4 +1623,4 @@ export function renderUsername(username: string, discriminator: string): string export function renderUserUsername(user: User | UnknownUser): string { return renderUsername(user.username, user.discriminator); -} \ No newline at end of file +} diff --git a/dashboard/src/components/docs/Moderation.vue b/dashboard/src/components/docs/Moderation.vue new file mode 100644 index 00000000..ff2151e6 --- /dev/null +++ b/dashboard/src/components/docs/Moderation.vue @@ -0,0 +1,156 @@ + + + diff --git a/dashboard/src/routes.ts b/dashboard/src/routes.ts index 15ac3d96..b70c38db 100644 --- a/dashboard/src/routes.ts +++ b/dashboard/src/routes.ts @@ -51,7 +51,7 @@ export const router = new VueRouter({ }, { path: "setup-guides/moderation", - component: () => import("./components/docs/WorkInProgress.vue"), + component: () => import("./components/docs/Moderation.vue"), }, { path: "setup-guides/counters",