mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Merge remote-tracking branch 'origin/master' into iots_to_zod
This commit is contained in:
commit
59c5176cbd
39 changed files with 1420 additions and 2208 deletions
7
.clabot
7
.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!"
|
||||
}
|
||||
|
|
3233
backend/package-lock.json
generated
3233
backend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -40,7 +40,6 @@
|
|||
"discord.js": "^14.11.0",
|
||||
"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",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}))!;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -10,6 +10,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";
|
||||
|
@ -37,4 +38,5 @@ export const availableActions = {
|
|||
start_thread: StartThreadAction,
|
||||
archive_thread: ArchiveThreadAction,
|
||||
change_perms: ChangePermsAction,
|
||||
pause_invites: PauseInvitesAction,
|
||||
} satisfies Record<string, AutomodActionBlueprint<any>>;
|
||||
|
|
17
backend/src/plugins/Automod/actions/pauseInvites.ts
Normal file
17
backend/src/plugins/Automod/actions/pauseInvites.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { GuildFeature } from "discord.js";
|
||||
import z from "zod";
|
||||
import { automodAction } from "../helpers";
|
||||
|
||||
export const PauseInvitesAction = automodAction({
|
||||
configSchema: z.strictObject({
|
||||
paused: z.boolean(),
|
||||
}),
|
||||
|
||||
async apply({ pluginData, actionConfig }) {
|
||||
const hasInvitesDisabled = pluginData.guild.features.includes(GuildFeature.InvitesDisabled);
|
||||
|
||||
if (actionConfig.paused !== hasInvitesDisabled) {
|
||||
await pluginData.guild.disableInvites(actionConfig.paused);
|
||||
}
|
||||
},
|
||||
});
|
|
@ -10,14 +10,17 @@ export const SetSlowmodeAction = automodAction({
|
|||
duration: zDelayString.nullable().default("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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,15 @@ import { AutomodContext, AutomodPluginType } from "../types";
|
|||
|
||||
export async function runAutomodOnAntiraidLevel(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
level: string | null,
|
||||
newLevel: string | null,
|
||||
oldLevel: string | null,
|
||||
user?: User,
|
||||
) {
|
||||
const context: AutomodContext = {
|
||||
timestamp: Date.now(),
|
||||
antiraid: {
|
||||
level,
|
||||
level: newLevel,
|
||||
oldLevel,
|
||||
},
|
||||
user,
|
||||
};
|
||||
|
|
10
backend/src/plugins/Automod/functions/applyCooldown.ts
Normal file
10
backend/src/plugins/Automod/functions/applyCooldown.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { convertDelayStringToMS } from "../../../utils";
|
||||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
|
||||
export function applyCooldown(pluginData: GuildPluginData<AutomodPluginType>, 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);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { convertDelayStringToMS } from "../../../utils";
|
||||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
|
||||
export function checkAndUpdateCooldown(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
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;
|
||||
}
|
8
backend/src/plugins/Automod/functions/checkCooldown.ts
Normal file
8
backend/src/plugins/Automod/functions/checkCooldown.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
|
||||
export function checkCooldown(pluginData: GuildPluginData<AutomodPluginType>, rule: TRule, context: AutomodContext) {
|
||||
const cooldownKey = `${rule.name}-${context.user?.id}`;
|
||||
|
||||
return pluginData.state.cooldownManager.isOnCooldown(cooldownKey);
|
||||
}
|
|
@ -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<AutomodPluginType>, context: AutomodContext) {
|
||||
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
||||
|
@ -46,7 +47,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
|
|||
}
|
||||
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<AutomodPluginType>,
|
|||
}
|
||||
|
||||
if (matchResult) {
|
||||
if (rule.cooldown) applyCooldown(pluginData, rule, context);
|
||||
|
||||
contexts = [context, ...(matchResult.extraContexts || [])];
|
||||
|
||||
for (const _context of contexts) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ interface AntiraidLevelTriggerResult {}
|
|||
|
||||
const configSchema = z.strictObject({
|
||||
level: z.nullable(z.string().max(100)),
|
||||
only_on_change: z.nullable(z.boolean()),
|
||||
});
|
||||
|
||||
export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()({
|
||||
|
@ -19,6 +20,14 @@ export const AntiraidLevelTrigger = automodTrigger<AntiraidLevelTriggerResult>()
|
|||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
triggerConfig.only_on_change &&
|
||||
context.antiraid.oldLevel !== undefined &&
|
||||
context.antiraid.level === context.antiraid.oldLevel
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {},
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { escapeInlineCode, Snowflake } from "discord.js";
|
||||
import z from "zod";
|
||||
import { extname } from "path";
|
||||
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils";
|
||||
import { automodTrigger } from "../helpers";
|
||||
|
||||
|
@ -44,7 +45,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
|||
}
|
||||
|
||||
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())
|
||||
|
|
|
@ -41,7 +41,7 @@ export const MatchWordsTrigger = automodTrigger<MatchResultType>()({
|
|||
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) {
|
||||
|
|
|
@ -167,6 +167,7 @@ export interface AutomodContext {
|
|||
};
|
||||
antiraid?: {
|
||||
level: string | null;
|
||||
oldLevel?: string | null;
|
||||
};
|
||||
threadChange?: {
|
||||
created?: ThreadChannel;
|
||||
|
|
|
@ -82,9 +82,9 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
}
|
||||
}
|
||||
|
||||
if (message.reactions && Object.keys(message.reactions).length > 0) {
|
||||
if (message.reactions.cache.size > 0) {
|
||||
const reactionCounts: string[] = [];
|
||||
for (const [emoji, info] of Object.entries(message.reactions)) {
|
||||
for (const [emoji, info] of message.reactions.cache) {
|
||||
reactionCounts.push(`${info.count}x ${emoji}`);
|
||||
}
|
||||
content += `\n-- Reactions: ${reactionCounts.join(", ")}`;
|
||||
|
|
|
@ -8,6 +8,7 @@ import { GuildMutes } from "../../data/GuildMutes";
|
|||
import { 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<MutesPluginType>()({
|
|||
configSchema: zMutesConfig,
|
||||
},
|
||||
|
||||
dependencies: () => [CasesPlugin, LogsPlugin],
|
||||
dependencies: () => [CasesPlugin, LogsPlugin, RoleManagerPlugin],
|
||||
configParser: (input) => zMutesConfig.parse(input),
|
||||
defaultOptions,
|
||||
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
},
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<MutesPluginType>, mute: Mute) {
|
||||
|
@ -24,6 +25,13 @@ export async function renewTimeoutMute(pluginData: GuildPluginData<MutesPluginTy
|
|||
}
|
||||
|
||||
const expiryTimestamp = moment.utc(newExpiryTime).valueOf();
|
||||
await member.disableCommunicationUntil(expiryTimestamp);
|
||||
if (!member.moderatable) {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Cannot renew user's timeout, specified user is not moderatable`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await member.disableCommunicationUntil(expiryTimestamp).catch(noop);
|
||||
await pluginData.state.mutes.updateTimeoutExpiresAt(mute.user_id, expiryTimestamp);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { CaseTypes } from "../../../data/CaseTypes";
|
|||
import { AddMuteParams } from "../../../data/GuildMutes";
|
||||
import { MuteTypes } from "../../../data/MuteTypes";
|
||||
import { Mute } from "../../../data/entities/Mute";
|
||||
import { resolveMember, resolveUser } from "../../../utils";
|
||||
import { noop, resolveMember, resolveUser } from "../../../utils";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
@ -54,8 +54,10 @@ export async function unmuteUser(
|
|||
}
|
||||
|
||||
// Update timeout
|
||||
if (existingMute?.type === MuteTypes.Timeout || createdMute?.type === MuteTypes.Timeout) {
|
||||
await member?.disableCommunicationUntil(timeoutExpiresAt);
|
||||
if (member && (existingMute?.type === MuteTypes.Timeout || createdMute?.type === MuteTypes.Timeout)) {
|
||||
if (!member.moderatable) return null;
|
||||
|
||||
await member.disableCommunicationUntil(timeoutExpiresAt).catch(noop);
|
||||
await pluginData.state.mutes.updateTimeoutExpiresAt(userId, timeoutExpiresAt);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,6 @@ import { PluginOptions } from "knub";
|
|||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildPersistedData } from "../../data/GuildPersistedData";
|
||||
import { trimPluginDescription } from "../../utils";
|
||||
import { GuildMemberCachePlugin } from "../GuildMemberCache/GuildMemberCachePlugin";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
|
@ -30,7 +29,7 @@ export const PersistPlugin = zeppelinGuildPlugin<PersistPluginType>()({
|
|||
configSchema: zPersistConfig,
|
||||
},
|
||||
|
||||
dependencies: () => [LogsPlugin, RoleManagerPlugin, GuildMemberCachePlugin],
|
||||
dependencies: () => [LogsPlugin, RoleManagerPlugin],
|
||||
configParser: (input) => zPersistConfig.parse(input),
|
||||
defaultOptions,
|
||||
|
||||
|
|
|
@ -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<PersistedData> = {};
|
||||
|
||||
// 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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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}`);
|
||||
|
|
|
@ -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<ZeppelinGuildPluginBlueprint<any>> = [
|
|||
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<ZeppelinGuildPluginBlueprint<any>> = [
|
|||
GuildInfoSaverPlugin,
|
||||
MessageSaverPlugin,
|
||||
NameHistoryPlugin,
|
||||
GuildMemberCachePlugin,
|
||||
// GuildMemberCachePlugin, // FIXME: New caching thing, or fix deadlocks with this plugin
|
||||
CasesPlugin,
|
||||
MutesPlugin,
|
||||
TimeAndDatePlugin,
|
||||
|
|
|
@ -522,7 +522,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);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"172950000412655616": 50 # Example mod
|
||||
|
||||
plugins:
|
||||
mod_plugin:
|
||||
mod_actions:
|
||||
config:
|
||||
kick_message: 'You have been kicked'
|
||||
can_kick: false
|
||||
|
|
156
dashboard/src/components/docs/Moderation.vue
Normal file
156
dashboard/src/components/docs/Moderation.vue
Normal file
|
@ -0,0 +1,156 @@
|
|||
<template>
|
||||
<div>
|
||||
<header>
|
||||
<h1>Moderation</h1>
|
||||
<p>
|
||||
Moderation in Zeppelin is multi-layered. On top of typical actions such
|
||||
as warning, muting, kicking, and banning, Zeppelin allows moderators to
|
||||
utilise flags; create alerts; set thresholds; and act as others.
|
||||
</p>
|
||||
<p>
|
||||
This guide explains the options available in the
|
||||
<router-link to="/docs/plugins/modactions"> Mod actions</router-link>
|
||||
plugin. To best use this guide, read the default configuration of the
|
||||
Mod actions plugin alongside this. This plugin does
|
||||
<strong>not</strong> cover muting members, please see the
|
||||
<router-link to="/docs/plugins/mutes">Mutes</router-link>
|
||||
plugin for that.
|
||||
</p>
|
||||
<p>
|
||||
Please ensure you understand how
|
||||
<router-link to="/docs/plugins/plugin-configuration">plugin
|
||||
configuration</router-link> and
|
||||
<router-link to="/docs/configuration/permissions">plugin
|
||||
permissions</router-link> work before reading this guide since
|
||||
the configs defined here rely on these concepts.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<h2>Moderation Commands</h2>
|
||||
<p>
|
||||
So that your moderators may use Zeppelin moderation, you must define the
|
||||
moderator role id in the config, assign it a level (50), and enable the
|
||||
Mod actions plugin.
|
||||
<CodeBlock code-lang="yaml" trim="start">
|
||||
levels:
|
||||
"PRETEND-ROLE-ID": 50 # Mod
|
||||
|
||||
plugins:
|
||||
mod_actions: {}
|
||||
</CodeBlock>
|
||||
</p>
|
||||
<p>
|
||||
Each moderation command has a permission attached to it, so if your
|
||||
server has a hierarchical structure then you will be able to scope
|
||||
these permissions by referencing the plugins permissions page.
|
||||
</p>
|
||||
|
||||
<h2>Sanction Notifications</h2>
|
||||
<p>These config options define how Zeppelin will interact with the
|
||||
members it sanctions (warns, kicks, bans).</p>
|
||||
|
||||
<h3>DM Values</h3>
|
||||
<p>
|
||||
The values <code>dm_on_warn</code>, <code>dm_on_kick</code>, and
|
||||
<code>dm_on_ban</code> determine whether a member will be notified of
|
||||
their sanctions through DMs. Ignoring privacy settings, setting these to
|
||||
<code>true</code> will notify the member. Temporary banning uses the
|
||||
ban configuration.
|
||||
</p>
|
||||
|
||||
<h3>Channel Values</h3>
|
||||
<p>
|
||||
An alternative way to notify members about sanctions is through
|
||||
mentioning them in a message sent in a channel. To enable this feature,
|
||||
set <code>message_on_warn</code>, <code>message_on_kick</code>, and
|
||||
and <code>message_on_ban</code> to true, then assign a
|
||||
<code>message_channel</code>.
|
||||
</p>
|
||||
|
||||
<h3>Notifying messages</h3>
|
||||
<p>
|
||||
This is how you control the exact wording the member receives. You can
|
||||
adjust the wording per sanction type. These variables are
|
||||
<code>warn_message</code>, <code>kick_message</code>, and
|
||||
<code>ban_message</code>. Please remember that YAML supports mutli-line
|
||||
strings, this is how you can write newlines in your messages. Notably,
|
||||
temporarily banning a member permits the inclusion of the
|
||||
<code>banTime</code> variable through <code>tempban_message</code>.
|
||||
</p>
|
||||
|
||||
<h3>Summary Example</h3>
|
||||
<p>
|
||||
Employing what we have learnt so far, we can write a configuration that:
|
||||
<ul>
|
||||
<li>Alerts members of their warns in a channel, instead of DMs.</li>
|
||||
<li>Alerts members of kicks and bans in their DMs.</li>
|
||||
<li>Makes use of multi-line strings to prepare a tidy message.</li>
|
||||
<li>Includes the remaining ban time if a ban was temporary.</li>
|
||||
</ul>
|
||||
<CodeBlock code-lang="yaml" trim="start">
|
||||
plugins:
|
||||
mod_actions:
|
||||
config:
|
||||
dm_on_warn: false
|
||||
message_on_warn: true
|
||||
message_channel: "PRETEND-CHANNEL-ID"
|
||||
|
||||
dm_on_kick: true
|
||||
|
||||
dm_on_ban: true
|
||||
tempban_message: |-
|
||||
Dear {user.username},
|
||||
|
||||
As a result of {reason}, you have been banned from {guildName}
|
||||
for {banTime}. We welcome you back provided you do not do this
|
||||
again.
|
||||
</CodeBlock>
|
||||
</p>
|
||||
|
||||
<h2>Alerts</h2>
|
||||
<p>
|
||||
Alerts are a nifty way for moderators to be notified of members trying to
|
||||
evade sanctions by promptly leaving and rejoining your server. To enable
|
||||
this feature, assign a channel in <code>alert_channel</code> and enable
|
||||
<code>alert_on_rejoin</code>.
|
||||
</p>
|
||||
<CodeBlock code-lang="yaml" trim="start">
|
||||
plugins:
|
||||
mod_actions:
|
||||
config:
|
||||
alert_on_rejoin: true
|
||||
alert_channel: "PRETEND-CHANNEL-ID"
|
||||
</CodeBlock>
|
||||
|
||||
<h2>Thresholds</h2>
|
||||
<p>
|
||||
Thresholds alert moderators if a member is about to exceed a
|
||||
predetermined number of cases, prompting moderators to consider whether
|
||||
alternative (harsher) action could be taken. To enable thresholds,
|
||||
assign the threshold as <code>warn_notify_threshold</code>, adjust the
|
||||
message under <code>warn_notify_message</code>, and enable
|
||||
<code>warn_notify_enabled</code>.
|
||||
</p>
|
||||
<p>
|
||||
Write your config cleverly, check the default values for
|
||||
<code>warn_notify_threshold</code> and <code>warn_notify_message</code>,
|
||||
if these are acceptable then all you need to do is enable
|
||||
<code>warn_notify_enabled</code>.
|
||||
</p>
|
||||
|
||||
<h2>Ban Message Deletion</h2>
|
||||
<p>
|
||||
When a member is banned, Zeppelin automatically deletes the last day of
|
||||
message history. You can extend this through the
|
||||
<code>ban_delete_message_days</code> option.
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import CodeBlock from "./CodeBlock.vue";
|
||||
|
||||
export default {
|
||||
components: { CodeBlock },
|
||||
};
|
||||
</script>
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo Updating Zeppelin...
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue