3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

feat: timeout support

This commit is contained in:
Dragory 2023-04-01 18:33:09 +03:00 committed by Miikka
parent 06877e90cc
commit 39e0dfa27f
23 changed files with 532 additions and 92 deletions

View file

@ -35,6 +35,7 @@ import { UnhideCaseCmd } from "./commands/UnhideCaseCmd";
import { UnmuteCmd } from "./commands/UnmuteCmd";
import { UpdateCmd } from "./commands/UpdateCmd";
import { WarnCmd } from "./commands/WarnCmd";
import { AuditLogEvents } from "./events/AuditLogEvents";
import { CreateBanCaseOnManualBanEvt } from "./events/CreateBanCaseOnManualBanEvt";
import { CreateUnbanCaseOnManualUnbanEvt } from "./events/CreateUnbanCaseOnManualUnbanEvt";
import { PostAlertOnMemberJoinEvt } from "./events/PostAlertOnMemberJoinEvt";
@ -127,7 +128,7 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
configParser: makeIoTsConfigParser(ConfigSchema),
defaultOptions,
events: [CreateBanCaseOnManualBanEvt, CreateUnbanCaseOnManualUnbanEvt, PostAlertOnMemberJoinEvt],
events: [CreateBanCaseOnManualBanEvt, CreateUnbanCaseOnManualUnbanEvt, PostAlertOnMemberJoinEvt, AuditLogEvents],
messageCommands: [
UpdateCmd,

View file

@ -44,7 +44,11 @@ export const UnmuteCmd = modActionsCmd({
const hasMuteRole = memberToUnmute && mutesPlugin.hasMutedRole(memberToUnmute);
// Check if they're muted in the first place
if (!(await pluginData.state.mutes.isMuted(args.user)) && !hasMuteRole) {
if (
!(await pluginData.state.mutes.isMuted(user.id)) &&
!hasMuteRole &&
!memberToUnmute?.communicationDisabledUntilTimestamp
) {
sendErrorMessage(pluginData, msg.channel, "Cannot unmute: member is not muted");
return;
}

View file

@ -0,0 +1,71 @@
import { AuditLogChange, AuditLogEvent } from "discord.js";
import moment from "moment-timezone";
import { CaseTypes } from "../../../data/CaseTypes";
import { resolveUser } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { modActionsEvt } from "../types";
export const AuditLogEvents = modActionsEvt({
event: "guildAuditLogEntryCreate",
async listener({ pluginData, args: { auditLogEntry } }) {
// Ignore the bot's own audit log events
if (auditLogEntry.executorId === pluginData.client.user?.id) {
return;
}
const config = pluginData.config.get();
const casesPlugin = pluginData.getPlugin(CasesPlugin);
// Create mute/unmute cases for manual timeouts
if (auditLogEntry.action === AuditLogEvent.MemberUpdate && config.create_cases_for_manual_actions) {
const target = await resolveUser(pluginData.client, auditLogEntry.targetId!);
// Only act based on the last changes in this log
let muteChange: AuditLogChange | null = null;
let unmuteChange: AuditLogChange | null = null;
for (const change of auditLogEntry.changes) {
if (change.key === "communication_disabled_until") {
if (change.new == null) {
unmuteChange = change;
} else {
muteChange = change;
unmuteChange = null;
}
}
}
if (muteChange) {
const existingMute = await pluginData.state.mutes.findExistingMuteForUserId(target.id);
const existingCaseId = existingMute?.case_id;
if (existingCaseId) {
await casesPlugin.createCaseNote({
caseId: existingCaseId,
modId: auditLogEntry.executor?.id || "0",
body: auditLogEntry.reason || "",
noteDetails: [`Timeout set to expire on <t:${moment.utc(muteChange.new as string).valueOf()}>`],
});
} else {
await casesPlugin.createCase({
userId: target.id,
modId: auditLogEntry.executor?.id || "0",
type: CaseTypes.Mute,
auditLogId: auditLogEntry.id,
reason: auditLogEntry.reason || "",
automatic: true,
});
}
}
if (unmuteChange) {
await casesPlugin.createCase({
userId: target.id,
modId: auditLogEntry.executor?.id || "0",
type: CaseTypes.Unmute,
auditLogId: auditLogEntry.id,
reason: auditLogEntry.reason || "",
automatic: true,
});
}
}
},
});