3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 07:05:03 +00:00

Merge branch 'ZeppelinBot:master' into master

This commit is contained in:
iamshoXy 2023-12-29 00:50:37 +01:00 committed by GitHub
commit 158380ad7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 82 additions and 27 deletions

View file

@ -9,6 +9,8 @@ export enum ERRORS {
INVALID_USER, INVALID_USER,
INVALID_MUTE_ROLE_ID, INVALID_MUTE_ROLE_ID,
MUTE_ROLE_ABOVE_ZEP, MUTE_ROLE_ABOVE_ZEP,
USER_ABOVE_ZEP,
USER_NOT_MODERATABLE,
} }
export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = { export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = {
@ -20,6 +22,8 @@ export const RECOVERABLE_PLUGIN_ERROR_MESSAGES = {
[ERRORS.INVALID_USER]: "Invalid user", [ERRORS.INVALID_USER]: "Invalid user",
[ERRORS.INVALID_MUTE_ROLE_ID]: "Specified mute role is not valid", [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.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 { export class RecoverablePluginError extends Error {

View file

@ -126,7 +126,7 @@ export function initGuildsAPI(app: express.Express) {
if (type !== ApiPermissionTypes.User) { if (type !== ApiPermissionTypes.User) {
return clientError(res, "Invalid type"); return clientError(res, "Invalid type");
} }
if (!isSnowflake(targetId)) { if (!isSnowflake(targetId) || targetId === req.user!.userId) {
return clientError(res, "Invalid targetId"); return clientError(res, "Invalid targetId");
} }
const validPermissions = new Set(Object.values(ApiPermissions)); const validPermissions = new Set(Object.values(ApiPermissions));

View file

@ -285,7 +285,11 @@ export class GuildCounters extends BaseGuildRepository {
reverse_comparison_value: reverseComparisonValue, reverse_comparison_value: reverseComparisonValue,
}); });
return (await entityManager.findOne(CounterTrigger, insertResult.identifiers[0].id))!; return (await entityManager.findOne(CounterTrigger, {
where: {
id: insertResult.identifiers[0].id,
},
}))!;
}); });
} }

View file

@ -8,7 +8,7 @@ import { Mute } from "./entities/Mute";
const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS; 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 // 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; export const TIMEOUT_RENEWAL_THRESHOLD = 21 * DAYS;

View file

@ -6,7 +6,7 @@ import { automodAction } from "../helpers";
export const SetSlowmodeAction = automodAction({ export const SetSlowmodeAction = automodAction({
configType: t.type({ configType: t.type({
channels: t.array(t.string), channels: tNullable(t.array(t.string)),
duration: tNullable(tDelayString), duration: tNullable(tDelayString),
}), }),
@ -14,14 +14,17 @@ export const SetSlowmodeAction = automodAction({
duration: "10s", duration: "10s",
}, },
async apply({ pluginData, actionConfig }) { async apply({ pluginData, actionConfig, contexts }) {
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0); const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
const channels: Snowflake[] = actionConfig.channels ?? [];
for (const channelId of 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); const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
// Only text channels and text channels within categories support slowmodes // 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; continue;
} }

View file

@ -1,5 +1,6 @@
import { escapeInlineCode, Snowflake } from "discord.js"; import { escapeInlineCode, Snowflake } from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { extname } from "path";
import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils"; import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils";
import { automodTrigger } from "../helpers"; import { automodTrigger } from "../helpers";
import { extname } from "path"; import { extname } from "path";

View file

@ -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[] = []; 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}`); reactionCounts.push(`${info.count}x ${emoji}`);
} }
content += `\n-- Reactions: ${reactionCounts.join(", ")}`; content += `\n-- Reactions: ${reactionCounts.join(", ")}`;

View file

@ -8,6 +8,7 @@ import { GuildMutes } from "../../data/GuildMutes";
import { makeIoTsConfigParser, mapToPublicFn } from "../../pluginUtils"; import { makeIoTsConfigParser, mapToPublicFn } from "../../pluginUtils";
import { CasesPlugin } from "../Cases/CasesPlugin"; import { CasesPlugin } from "../Cases/CasesPlugin";
import { LogsPlugin } from "../Logs/LogsPlugin"; import { LogsPlugin } from "../Logs/LogsPlugin";
import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin.js";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint"; import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { ClearBannedMutesCmd } from "./commands/ClearBannedMutesCmd"; import { ClearBannedMutesCmd } from "./commands/ClearBannedMutesCmd";
import { ClearMutesCmd } from "./commands/ClearMutesCmd"; import { ClearMutesCmd } from "./commands/ClearMutesCmd";
@ -68,7 +69,7 @@ export const MutesPlugin = zeppelinGuildPlugin<MutesPluginType>()({
configSchema: ConfigSchema, configSchema: ConfigSchema,
}, },
dependencies: () => [CasesPlugin, LogsPlugin], dependencies: () => [CasesPlugin, LogsPlugin, RoleManagerPlugin],
configParser: makeIoTsConfigParser(ConfigSchema), configParser: makeIoTsConfigParser(ConfigSchema),
defaultOptions, defaultOptions,

View file

@ -1,5 +1,6 @@
import moment from "moment-timezone"; import moment from "moment-timezone";
import { MuteTypes } from "../../../data/MuteTypes"; import { MuteTypes } from "../../../data/MuteTypes";
import { noop } from "../../../utils.js";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin"; import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
import { getTimeoutExpiryTime } from "../functions/getTimeoutExpiryTime"; import { getTimeoutExpiryTime } from "../functions/getTimeoutExpiryTime";
@ -12,6 +13,7 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({
event: "guildMemberAdd", event: "guildMemberAdd",
async listener({ pluginData, args: { member } }) { async listener({ pluginData, args: { member } }) {
const mute = await pluginData.state.mutes.findExistingMuteForUserId(member.id); const mute = await pluginData.state.mutes.findExistingMuteForUserId(member.id);
const logs = pluginData.getPlugin(LogsPlugin);
if (!mute) { if (!mute) {
return; return;
} }
@ -25,11 +27,17 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({
if (!member.isCommunicationDisabled()) { if (!member.isCommunicationDisabled()) {
const expiresAt = mute.expires_at ? moment.utc(mute.expires_at).valueOf() : null; const expiresAt = mute.expires_at ? moment.utc(mute.expires_at).valueOf() : null;
const timeoutExpiresAt = getTimeoutExpiryTime(expiresAt); 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, member,
}); });
}, },

View file

@ -13,6 +13,7 @@ import { TemplateSafeValueContainer, renderTemplate } from "../../../templateFor
import { import {
UserNotificationMethod, UserNotificationMethod,
UserNotificationResult, UserNotificationResult,
noop,
notifyUser, notifyUser,
resolveMember, resolveMember,
resolveUser, resolveUser,
@ -108,7 +109,7 @@ export async function muteUser(
if (zepRoles.size === 0 || !zepRoles.some((zepRole) => zepRole.position > actualMuteRole.position)) { if (zepRoles.size === 0 || !zepRoles.some((zepRole) => zepRole.position > actualMuteRole.position)) {
lock.unlock(); lock.unlock();
logs.logBotAlert({ 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); 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!); pluginData.getPlugin(RoleManagerPlugin).addPriorityRole(member.id, muteRole!);
} }
} else { } 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) // If enabled, move the user to the mute voice channel (e.g. afk - just to apply the voice perms from the mute role)

View file

@ -3,7 +3,8 @@ import { GuildPluginData } from "knub";
import moment from "moment-timezone"; import moment from "moment-timezone";
import { MAX_TIMEOUT_DURATION } from "../../../data/Mutes"; import { MAX_TIMEOUT_DURATION } from "../../../data/Mutes";
import { Mute } from "../../../data/entities/Mute"; 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"; import { MutesPluginType } from "../types";
export async function renewTimeoutMute(pluginData: GuildPluginData<MutesPluginType>, mute: Mute) { 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(); 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); await pluginData.state.mutes.updateTimeoutExpiresAt(mute.user_id, expiryTimestamp);
} }

View file

@ -5,7 +5,7 @@ import { CaseTypes } from "../../../data/CaseTypes";
import { AddMuteParams } from "../../../data/GuildMutes"; import { AddMuteParams } from "../../../data/GuildMutes";
import { MuteTypes } from "../../../data/MuteTypes"; import { MuteTypes } from "../../../data/MuteTypes";
import { Mute } from "../../../data/entities/Mute"; import { Mute } from "../../../data/entities/Mute";
import { resolveMember, resolveUser } from "../../../utils"; import { noop, resolveMember, resolveUser } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseArgs } from "../../Cases/types"; import { CaseArgs } from "../../Cases/types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
@ -54,8 +54,10 @@ export async function unmuteUser(
} }
// Update timeout // Update timeout
if (existingMute?.type === MuteTypes.Timeout || createdMute?.type === MuteTypes.Timeout) { if (member && (existingMute?.type === MuteTypes.Timeout || createdMute?.type === MuteTypes.Timeout)) {
await member?.disableCommunicationUntil(timeoutExpiresAt); if (!member.moderatable) return null;
await member.disableCommunicationUntil(timeoutExpiresAt).catch(noop);
await pluginData.state.mutes.updateTimeoutExpiresAt(userId, timeoutExpiresAt); await pluginData.state.mutes.updateTimeoutExpiresAt(userId, timeoutExpiresAt);
} }
} else { } else {

View file

@ -205,9 +205,14 @@ export async function getServerInfoEmbed(
[GuildPremiumTier.Tier3]: 60, [GuildPremiumTier.Tier3]: 60,
}[restGuild.premiumTier] ?? 0; }[restGuild.premiumTier] ?? 0;
const availableEmojis = restGuild.emojis.cache.filter((e) => e.available);
otherStats.push( otherStats.push(
`Emojis: **${restGuild.emojis.cache.size}** / ${maxEmojis * 2}${ `Emojis: **${availableEmojis.size}** / ${maxEmojis * 2}${
roleLockedEmojis ? ` (__${roleLockedEmojis} role-locked__)` : "" 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}`); otherStats.push(`Stickers: **${restGuild.stickers.cache.size}** / ${maxStickers}`);

View file

@ -20,7 +20,7 @@
"172950000412655616": 50 # Example mod "172950000412655616": 50 # Example mod
plugins: plugins:
mod_plugin: mod_actions:
config: config:
kick_message: 'You have been kicked' kick_message: 'You have been kicked'
can_kick: false can_kick: false

View file

@ -21,7 +21,7 @@ services:
MYSQL_USER: zeppelin MYSQL_USER: zeppelin
MYSQL_PASSWORD: ${DOCKER_PROD_MYSQL_PASSWORD?:Missing DOCKER_PROD_MYSQL_PASSWORD} MYSQL_PASSWORD: ${DOCKER_PROD_MYSQL_PASSWORD?:Missing DOCKER_PROD_MYSQL_PASSWORD}
ports: 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: volumes:
- ./docker/production/data/mysql:/var/lib/mysql - ./docker/production/data/mysql:/var/lib/mysql
command: --authentication-policy=mysql_native_password command: --authentication-policy=mysql_native_password

View file

@ -4,9 +4,9 @@
"description": "", "description": "",
"private": true, "private": true,
"scripts": { "scripts": {
"format": "prettier --write './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}'", "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}'" "codestyle-check": "prettier --check \"./backend/src/**/*.{css,html,js,json,ts,tsx}\" \"./dashboard/src/**/*.{css,html,js,json,ts,tsx}\""
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.5", "@typescript-eslint/eslint-plugin": "^5.59.5",

View file

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -e
echo Updating Zeppelin... echo Updating Zeppelin...