mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
60 lines
2 KiB
TypeScript
60 lines
2 KiB
TypeScript
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
|
|
import { GuildPluginData } from "knub";
|
|
import { humanizeDuration } from "../../../../humanizeDuration.js";
|
|
import { UnknownUser, asSingleLine, renderUsername } from "../../../../utils.js";
|
|
import { MutesPlugin } from "../../../Mutes/MutesPlugin.js";
|
|
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction.js";
|
|
import { formatReasonWithMessageLinkForAttachments } from "../../functions/formatReasonForAttachments.js";
|
|
import { ModActionsPluginType } from "../../types.js";
|
|
|
|
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.state.common.sendErrorMessage(context, "User is not muted!");
|
|
return;
|
|
}
|
|
|
|
// Confirm the action to the moderator
|
|
if (time) {
|
|
const timeUntilUnmute = time && humanizeDuration(time);
|
|
pluginData.state.common.sendSuccessMessage(
|
|
context,
|
|
asSingleLine(`
|
|
Unmuting **${renderUsername(user)}**
|
|
in ${timeUntilUnmute} (Case #${result.case.case_number})
|
|
`),
|
|
);
|
|
} else {
|
|
pluginData.state.common.sendSuccessMessage(
|
|
context,
|
|
asSingleLine(`
|
|
Unmuted **${renderUsername(user)}**
|
|
(Case #${result.case.case_number})
|
|
`),
|
|
);
|
|
}
|
|
}
|