3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

fix: don't attempt to message users off-server

Co-authored-by: metal0 <metal@i0.tf>
This commit is contained in:
Dragory 2023-04-01 21:45:12 +03:00
parent dd2eebd4a5
commit dd1afc4dab
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 10 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { DiscordAPIError, Snowflake, User } from "discord.js";
import { DiscordAPIError, Snowflake } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../data/CaseTypes";
@ -10,6 +10,7 @@ import {
createUserNotificationError,
DAYS,
notifyUser,
resolveMember,
resolveUser,
SECONDS,
ucfirst,
@ -42,8 +43,9 @@ export async function banUserId(
}
// Attempt to message the user *before* banning them, as doing it after may not be possible
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason && user instanceof User) {
if (reason && member) {
const contactMethods = banOptions?.contactMethods
? banOptions.contactMethods
: getDefaultContactMethods(pluginData, "ban");
@ -61,7 +63,7 @@ export async function banUserId(
}),
);
notifyResult = await notifyUser(user, banMessage, contactMethods);
notifyResult = await notifyUser(member.user, banMessage, contactMethods);
} else if (banTime && config.tempban_message) {
const banMessage = await renderTemplate(
config.tempban_message,
@ -75,7 +77,7 @@ export async function banUserId(
}),
);
notifyResult = await notifyUser(user, banMessage, contactMethods);
notifyResult = await notifyUser(member.user, banMessage, contactMethods);
} else {
notifyResult = createUserNotificationError("No ban/tempban message specified in config");
}

View file

@ -24,7 +24,7 @@ export async function kickMember(
// Attempt to message the user *before* kicking them, as doing it after may not be possible
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason) {
if (reason && member) {
const contactMethods = kickOptions?.contactMethods
? kickOptions.contactMethods
: getDefaultContactMethods(pluginData, "kick");

View file

@ -1,4 +1,4 @@
import { Snowflake, User } from "discord.js";
import { Snowflake } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../data/CaseTypes";
@ -191,7 +191,7 @@ export async function muteUser(
}),
));
if (muteMessage && user instanceof User) {
if (muteMessage && member) {
let contactMethods: UserNotificationMethod[] = [];
if (muteOptions?.contactMethods) {
@ -211,7 +211,7 @@ export async function muteUser(
}
}
notifyResult = await notifyUser(user, muteMessage, contactMethods);
notifyResult = await notifyUser(member.user, muteMessage, contactMethods);
}
// Create/update a case