mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 20:55:01 +00:00
Fixes, refactoring and PR feedback
This commit is contained in:
parent
0be54912c4
commit
893a77d562
202 changed files with 1037 additions and 1069 deletions
|
@ -0,0 +1,60 @@
|
|||
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 { MutesPlugin } from "../../../Mutes/MutesPlugin";
|
||||
import { ModActionsPluginType } from "../../types";
|
||||
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction";
|
||||
import { formatReasonWithMessageLinkForAttachments } from "../../functions/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.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})
|
||||
`),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue