3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-13 21:35:02 +00:00

Fixes, refactoring and PR feedback

This commit is contained in:
Lily Bergonzat 2024-04-15 15:51:45 +02:00
parent 0be54912c4
commit 893a77d562
202 changed files with 1037 additions and 1069 deletions

View file

@ -1,61 +0,0 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { UnknownUser, asSingleLine, renderUsername } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { ModActionsPluginType } from "../../types";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
export async function actualUnmuteCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: Message | ChatInputCommandInteraction,
user: User | UnknownUser,
attachments: Array<Attachment>,
mod: GuildMember,
ppId?: string,
time?: number,
reason?: string | null,
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const formattedReason =
reason || attachments.length > 0
? await formatReasonWithMessageLinkForAttachments(pluginData, reason ?? "", context, attachments)
: undefined;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
const result = await mutesPlugin.unmuteUser(user.id, time, {
modId: mod.id,
ppId: ppId ?? undefined,
reason: formattedReason,
});
if (!result) {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "User is not muted!");
return;
}
// Confirm the action to the moderator
if (time) {
const timeUntilUnmute = time && humanizeDuration(time);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(
context,
asSingleLine(`
Unmuting **${renderUsername(user)}**
in ${timeUntilUnmute} (Case #${result.case.case_number})
`),
);
} else {
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(
context,
asSingleLine(`
Unmuted **${renderUsername(user)}**
(Case #${result.case.case_number})
`),
);
}
}