fix: make /ban ignore target input when targetting by reply

This commit is contained in:
JandereDev 2022-05-24 07:33:20 +02:00
parent 9b3eaa6752
commit 96a0d2b7c8
Signed by: Lea
GPG key ID: 5D5E18ACB990F57A
2 changed files with 14 additions and 15 deletions

View file

@ -31,7 +31,7 @@ export default {
] });
}
const userInput = args.shift() || '';
const userInput = !message.reply_ids?.length ? args.shift() || '' : undefined;
if (!userInput && !message.reply_ids?.length) return message.reply({ embeds: [
embed(
`Please specify one or more users by replying to their message while running this command or ` +
@ -78,25 +78,19 @@ export default {
const targetUsers: User|{ _id: string }[] = [];
const targetInput = dedupeArray(
// Replied messages
(await Promise.allSettled(
(message.reply_ids ?? []).map(msg => message.channel?.fetchMessage(msg))
message.reply_ids?.length
? (await Promise.allSettled(
message.reply_ids.map(msg => message.channel?.fetchMessage(msg))
))
.filter(m => m.status == 'fulfilled').map(m => (m as any).value.author_id),
// Provided users
userInput.split(','),
.filter(m => m.status == 'fulfilled').map(m => (m as any).value.author_id)
: userInput!.split(','),
);
for (const userStr of targetInput) {
try {
let user = await parseUserOrId(userStr);
if (!user) {
if (message.reply_ids?.length && userStr == userInput) {
reason = reason ? `${userInput} ${reason}` : userInput;
}
else {
embeds.push(embed(`I can't resolve \`${sanitizeMessageContent(userStr).trim()}\` to a user.`, null, '#ff785d'));
}
continue;
}
@ -175,6 +169,7 @@ export default {
colour: EmbedColor.Success,
description: `This is ${userWarnCount == 1 ? '**the first infraction**' : `infraction number **${userWarnCount}**`}` +
` for ${await fetchUsername(user._id)}.\n` +
`**User ID:** \`${user._id}\`\n` +
`**Infraction ID:** \`${infraction._id}\`\n` +
`**Reason:** \`${infraction.reason}\``
});
@ -222,7 +217,8 @@ export default {
colour: EmbedColor.Success,
description: `This is ${userWarnCount == 1 ? '**the first infraction**' : `infraction number **${userWarnCount}**`}` +
` for ${await fetchUsername(user._id)}.\n` +
`**Ban duration:** ` +
`**Ban duration:** ${banDurationFancy}\n` +
`**User ID:** \`${user._id}\`\n` +
`**Infraction ID:** \`${infraction._id}\`\n` +
`**Reason:** \`${infraction.reason}\``
});

View file

@ -7,6 +7,9 @@ class Infraction {
user: string;
createdBy: string|null;
server: string;
channel?: string;
message?: string;
targetMessages?: string[];
reason: string;
date: number;
}