mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 18:25:03 +00:00
Update warnMember.ts
This commit is contained in:
parent
0e574e3d6c
commit
ba9b3176db
1 changed files with 10 additions and 28 deletions
|
@ -1,16 +1,10 @@
|
||||||
import { GuildMember, Snowflake, User } from "discord.js";
|
import { GuildMember, Snowflake } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||||
import { CaseTypes } from "../../../data/CaseTypes";
|
import { CaseTypes } from "../../../data/CaseTypes";
|
||||||
|
import { LogType } from "../../../data/LogType";
|
||||||
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
|
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
|
||||||
import {
|
import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils";
|
||||||
createUserNotificationError,
|
|
||||||
notifyUser,
|
|
||||||
resolveUser,
|
|
||||||
ucfirst,
|
|
||||||
UnknownUser,
|
|
||||||
UserNotificationResult,
|
|
||||||
} from "../../../utils";
|
|
||||||
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
||||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||||
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
|
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
|
||||||
|
@ -19,24 +13,13 @@ import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
|
|
||||||
export async function warnMember(
|
export async function warnMember(
|
||||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||||
|
member: GuildMember,
|
||||||
reason: string,
|
reason: string,
|
||||||
member: GuildMember | null,
|
|
||||||
user?: User | null,
|
|
||||||
warnOptions: WarnOptions = {},
|
warnOptions: WarnOptions = {},
|
||||||
): Promise<WarnResult> {
|
): Promise<WarnResult> {
|
||||||
if (!member && !user) {
|
|
||||||
return {
|
|
||||||
status: "failed",
|
|
||||||
error: "No member or user passed",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
user = member?.user ?? user;
|
|
||||||
|
|
||||||
const config = pluginData.config.get();
|
const config = pluginData.config.get();
|
||||||
reason = parseReason(config, reason);
|
|
||||||
let notifyResult: UserNotificationResult;
|
|
||||||
|
|
||||||
|
let notifyResult: UserNotificationResult;
|
||||||
if (config.warn_message) {
|
if (config.warn_message) {
|
||||||
const warnMessage = await renderTemplate(
|
const warnMessage = await renderTemplate(
|
||||||
config.warn_message,
|
config.warn_message,
|
||||||
|
@ -51,7 +34,7 @@ export async function warnMember(
|
||||||
const contactMethods = warnOptions?.contactMethods
|
const contactMethods = warnOptions?.contactMethods
|
||||||
? warnOptions.contactMethods
|
? warnOptions.contactMethods
|
||||||
: getDefaultContactMethods(pluginData, "warn");
|
: getDefaultContactMethods(pluginData, "warn");
|
||||||
notifyResult = await notifyUser(user as User, warnMessage, contactMethods);
|
notifyResult = await notifyUser(member.user, warnMessage, contactMethods);
|
||||||
} else {
|
} else {
|
||||||
notifyResult = createUserNotificationError("No warn message specified in config");
|
notifyResult = createUserNotificationError("No warn message specified in config");
|
||||||
}
|
}
|
||||||
|
@ -70,7 +53,7 @@ export async function warnMember(
|
||||||
error: "Failed to message user",
|
error: "Failed to message user",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if (!warnOptions.silentErrors) {
|
} else {
|
||||||
return {
|
return {
|
||||||
status: "failed",
|
status: "failed",
|
||||||
error: "Failed to message user",
|
error: "Failed to message user",
|
||||||
|
@ -83,7 +66,7 @@ export async function warnMember(
|
||||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||||
const createdCase = await casesPlugin.createCase({
|
const createdCase = await casesPlugin.createCase({
|
||||||
...(warnOptions.caseArgs || {}),
|
...(warnOptions.caseArgs || {}),
|
||||||
userId: user!.id,
|
userId: member.id,
|
||||||
modId,
|
modId,
|
||||||
type: CaseTypes.Warn,
|
type: CaseTypes.Warn,
|
||||||
reason,
|
reason,
|
||||||
|
@ -94,12 +77,11 @@ export async function warnMember(
|
||||||
pluginData.getPlugin(LogsPlugin).logMemberWarn({
|
pluginData.getPlugin(LogsPlugin).logMemberWarn({
|
||||||
mod,
|
mod,
|
||||||
member,
|
member,
|
||||||
user,
|
|
||||||
caseNumber: createdCase.case_number,
|
caseNumber: createdCase.case_number,
|
||||||
reason: reason ?? "",
|
reason: reason ?? "",
|
||||||
});
|
});
|
||||||
|
|
||||||
pluginData.state.events.emit("warn", user!.id, reason, warnOptions.isAutomodAction);
|
pluginData.state.events.emit("warn", member.id, reason, warnOptions.isAutomodAction);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue