3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35: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

@ -0,0 +1,52 @@
import { AuditLogChange, AuditLogEvent } from "discord.js";
import moment from "moment-timezone";
import { MuteTypes } from "../../../data/MuteTypes";
import { resolveUser } from "../../../utils";
import { mutesEvt } from "../types";
export const RegisterManualTimeoutsEvt = mutesEvt({
event: "guildAuditLogEntryCreate",
async listener({ pluginData, args: { auditLogEntry } }) {
// Ignore the bot's own audit log events
if (auditLogEntry.executorId === pluginData.client.user?.id) {
return;
}
if (auditLogEntry.action !== AuditLogEvent.MemberUpdate) {
return;
}
const target = await resolveUser(pluginData.client, auditLogEntry.targetId!);
// Only act based on the last changes in this log
let lastTimeoutChange: AuditLogChange | null = null;
for (const change of auditLogEntry.changes) {
if (change.key === "communication_disabled_until") {
lastTimeoutChange = change;
}
}
if (!lastTimeoutChange) {
return;
}
const existingMute = await pluginData.state.mutes.findExistingMuteForUserId(target.id);
if (lastTimeoutChange.new == null && existingMute) {
await pluginData.state.mutes.clear(target.id);
return;
}
if (lastTimeoutChange.new != null) {
const expiresAtTimestamp = moment.utc(lastTimeoutChange.new as string).valueOf();
if (existingMute) {
await pluginData.state.mutes.updateExpiresAt(target.id, expiresAtTimestamp);
} else {
await pluginData.state.mutes.addMute({
userId: target.id,
type: MuteTypes.Timeout,
expiresAt: expiresAtTimestamp,
timeoutExpiresAt: expiresAtTimestamp,
});
}
}
},
});