Fix several locations that expected resolveUser() to return null
This commit is contained in:
parent
d35564eac8
commit
b9dde47a9e
13 changed files with 35 additions and 13 deletions
|
@ -33,7 +33,9 @@ export const BanCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const memberToBan = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
|
|
|
@ -36,7 +36,9 @@ export const CasesUserCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const cases = await pluginData.state.cases.with("notes").getByUserId(user.id);
|
||||
const normalCases = cases.filter(c => !c.is_hidden);
|
||||
|
|
|
@ -31,7 +31,9 @@ export const ForcebanCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -33,7 +33,9 @@ export const ForcemuteCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
|
|
|
@ -31,7 +31,9 @@ export const ForceUnmuteCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
// Check if they're muted in the first place
|
||||
if (!(await pluginData.state.mutes.isMuted(user.id))) {
|
||||
|
|
|
@ -43,7 +43,9 @@ export const MuteCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ export const NoteCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const userName = `${user.username}#${user.discriminator}`;
|
||||
const reason = formatReasonWithAttachments(args.note, msg.attachments);
|
||||
|
|
|
@ -28,7 +28,9 @@ export const UnbanCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||
let mod = msg.member;
|
||||
|
|
|
@ -33,7 +33,9 @@ export const UnmuteCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const memberToUnmute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
|
||||
|
|
|
@ -29,7 +29,9 @@ export const WarnCmd = modActionsCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const memberToWarn = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
|
|
|
@ -24,7 +24,9 @@ export async function actualKickMemberCmd(
|
|||
},
|
||||
) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
if (!user.id) {
|
||||
return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
}
|
||||
|
||||
const memberToKick = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ export async function banUserId(
|
|||
): Promise<BanResult> {
|
||||
const config = pluginData.config.get();
|
||||
const user = await resolveUser(pluginData.client, userId);
|
||||
if (!user) {
|
||||
if (!user.id) {
|
||||
return {
|
||||
status: "failed",
|
||||
error: "Invalid user",
|
||||
|
|
|
@ -42,7 +42,7 @@ export async function muteUser(
|
|||
}
|
||||
|
||||
const user = await resolveUser(pluginData.client, userId);
|
||||
if (!user) {
|
||||
if (!user.id) {
|
||||
lock.unlock();
|
||||
throw new RecoverablePluginError(ERRORS.INVALID_USER);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue