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

Added Discord attachment link reaction, fixed emoji configuration and moved util functions

This commit is contained in:
Lily Bergonzat 2024-02-16 11:51:58 +01:00
parent a4c4b17a14
commit 592d037148
173 changed files with 1540 additions and 1170 deletions

View file

@ -1,7 +1,7 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { canActOn } from "../../../../pluginUtils";
import {
DAYS,
SECONDS,
@ -10,15 +10,17 @@ import {
renderUserUsername,
resolveMember,
} from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { ignoreEvent } from "../ignoreEvent";
import { isBanned } from "../isBanned";
import { kickMember } from "../kickMember";
export async function actualKickCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: GuildMember,
user: User | UnknownUser,
reason: string,
@ -27,14 +29,18 @@ export async function actualKickCmd(
contactMethods?: UserNotificationMethod[],
clean?: boolean,
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const memberToKick = await resolveMember(pluginData.client, pluginData.guild, user.id);
if (!memberToKick) {
const banned = await isBanned(pluginData, user.id);
if (banned) {
sendErrorMessage(pluginData, context, `User is banned`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User is banned`);
} else {
sendErrorMessage(pluginData, context, `User not found on the server`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User not found on the server`);
}
return;
@ -42,13 +48,14 @@ export async function actualKickCmd(
// Make sure we're allowed to kick this member
if (!canActOn(pluginData, author, memberToKick)) {
sendErrorMessage(pluginData, context, "Cannot kick: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cannot kick: insufficient permissions");
return;
}
const formattedReason = formatReasonWithAttachments(reason, attachments);
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
const formattedReasonWithAttachments = formatReasonWithAttachments(reason, attachments);
const kickResult = await kickMember(pluginData, memberToKick, formattedReason, {
const kickResult = await kickMember(pluginData, memberToKick, formattedReason, formattedReasonWithAttachments, {
contactMethods,
caseArgs: {
modId: mod.id,
@ -63,7 +70,7 @@ export async function actualKickCmd(
try {
await memberToKick.ban({ deleteMessageSeconds: (1 * DAYS) / SECONDS, reason: "kick -clean" });
} catch {
sendErrorMessage(pluginData, context, "Failed to ban the user to clean messages (-clean)");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Failed to ban the user to clean messages (-clean)");
}
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id);
@ -72,12 +79,14 @@ export async function actualKickCmd(
try {
await pluginData.guild.bans.remove(memberToKick.id, "kick -clean");
} catch {
sendErrorMessage(pluginData, context, "Failed to unban the user after banning them (-clean)");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Failed to unban the user after banning them (-clean)");
}
}
if (kickResult.status === "failed") {
sendErrorMessage(pluginData, context, `Failed to kick user`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `Failed to kick user`);
return;
}
@ -85,5 +94,5 @@ export async function actualKickCmd(
let response = `Kicked **${renderUserUsername(memberToKick.user)}** (Case #${kickResult.case.case_number})`;
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
sendSuccessMessage(pluginData, context, response);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, response);
}