mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-08 08:05:03 +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
|
@ -2,8 +2,7 @@ import { commandTypeHelpers as ct } from "../../../../commandTypes";
|
|||
import { CaseTypes } from "../../../../data/CaseTypes";
|
||||
import { hasPermission } from "../../../../pluginUtils";
|
||||
import { resolveUser } from "../../../../utils";
|
||||
import { CommonPlugin } from "../../../Common/CommonPlugin";
|
||||
import { actualAddCaseCmd } from "../../functions/actualCommands/actualAddCaseCmd";
|
||||
import { actualAddCaseCmd } from "./actualAddCaseCmd";
|
||||
import { modActionsMsgCmd } from "../../types";
|
||||
|
||||
const opts = {
|
||||
|
@ -28,7 +27,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user.id) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
|
||||
pluginData.state.common.sendErrorMessage(msg, `User not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -36,7 +35,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
|
|||
let mod = msg.member;
|
||||
if (args.mod) {
|
||||
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
|
||||
pluginData.state.common.sendErrorMessage(msg, "You don't have permission to use -mod");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -46,7 +45,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
|
|||
// Verify the case type is valid
|
||||
const type: string = args.type[0].toUpperCase() + args.type.slice(1).toLowerCase();
|
||||
if (!CaseTypes[type]) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot add case: invalid case type");
|
||||
pluginData.state.common.sendErrorMessage(msg, "Cannot add case: invalid case type");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@ import { CaseTypes } from "../../../../data/CaseTypes";
|
|||
import { hasPermission } from "../../../../pluginUtils";
|
||||
import { resolveMember } from "../../../../utils";
|
||||
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
|
||||
import { CommonPlugin } from "../../../Common/CommonPlugin";
|
||||
import { actualAddCaseCmd } from "../../functions/actualCommands/actualAddCaseCmd";
|
||||
import { actualAddCaseCmd } from "./actualAddCaseCmd";
|
||||
import { modActionsSlashCmd } from "../../types";
|
||||
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
|
||||
|
||||
|
@ -49,9 +48,10 @@ export const AddCaseSlashCmd = modActionsSlashCmd({
|
|||
|
||||
if (options.mod) {
|
||||
if (!canActAsOther) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
|
||||
pluginData.state.common.sendErrorMessage(
|
||||
interaction,
|
||||
"You don't have permission to act as another moderator"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { CaseTypes } from "../../../../data/CaseTypes";
|
||||
import { Case } from "../../../../data/entities/Case";
|
||||
import { canActOn } from "../../../../pluginUtils";
|
||||
import { UnknownUser, renderUsername, resolveMember } from "../../../../utils";
|
||||
import { CasesPlugin } from "../../../Cases/CasesPlugin";
|
||||
import { LogsPlugin } from "../../../Logs/LogsPlugin";
|
||||
import { ModActionsPluginType } from "../../types";
|
||||
import { handleAttachmentLinkDetectionAndGetRestriction } from "../../functions/attachmentLinkReaction";
|
||||
import { formatReasonWithMessageLinkForAttachments } from "../../functions/formatReasonForAttachments";
|
||||
|
||||
export async function actualAddCaseCmd(
|
||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
context: Message | ChatInputCommandInteraction,
|
||||
author: GuildMember,
|
||||
mod: GuildMember,
|
||||
attachments: Array<Attachment>,
|
||||
user: User | UnknownUser,
|
||||
type: keyof CaseTypes,
|
||||
reason: string,
|
||||
) {
|
||||
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the user exists as a guild member, make sure we can act on them first
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
if (member && !canActOn(pluginData, author, member)) {
|
||||
pluginData.state.common.sendErrorMessage(
|
||||
context,
|
||||
"Cannot add case on this user: insufficient permissions"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
|
||||
|
||||
// Create the case
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const theCase: Case = await casesPlugin.createCase({
|
||||
userId: user.id,
|
||||
modId: mod.id,
|
||||
type: CaseTypes[type],
|
||||
reason: formattedReason,
|
||||
ppId: mod.id !== author.id ? author.id : undefined,
|
||||
});
|
||||
|
||||
if (user) {
|
||||
pluginData.state.common.sendSuccessMessage(
|
||||
context,
|
||||
`Case #${theCase.case_number} created for **${renderUsername(user)}**`
|
||||
);
|
||||
} else {
|
||||
pluginData.state.common.sendSuccessMessage(context, `Case #${theCase.case_number} created`);
|
||||
}
|
||||
|
||||
// Log the action
|
||||
pluginData.getPlugin(LogsPlugin).logCaseCreate({
|
||||
mod: mod.user,
|
||||
userId: user.id,
|
||||
caseNum: theCase.case_number,
|
||||
caseType: type.toUpperCase(),
|
||||
reason: formattedReason,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue