mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 18:55:28 +00:00
u p g r a d e /kick command
This commit is contained in:
parent
4eeaca64d7
commit
7cee4638a9
|
@ -1,4 +1,6 @@
|
||||||
|
import { User } from "@janderedev/revolt.js";
|
||||||
import { Member } from "@janderedev/revolt.js/dist/maps/Members";
|
import { Member } from "@janderedev/revolt.js/dist/maps/Members";
|
||||||
|
import { SendableEmbed } from "revolt-api";
|
||||||
import { ulid } from "ulid";
|
import { ulid } from "ulid";
|
||||||
import { client } from "../../../";
|
import { client } from "../../../";
|
||||||
import Infraction from "../../../struct/antispam/Infraction";
|
import Infraction from "../../../struct/antispam/Infraction";
|
||||||
|
@ -6,13 +8,13 @@ import InfractionType from "../../../struct/antispam/InfractionType";
|
||||||
import CommandCategory from "../../../struct/commands/CommandCategory";
|
import CommandCategory from "../../../struct/commands/CommandCategory";
|
||||||
import SimpleCommand from "../../../struct/commands/SimpleCommand";
|
import SimpleCommand from "../../../struct/commands/SimpleCommand";
|
||||||
import MessageCommandContext from "../../../struct/MessageCommandContext";
|
import MessageCommandContext from "../../../struct/MessageCommandContext";
|
||||||
import { logModAction } from "../../modules/mod_logs";
|
import { fetchUsername, logModAction } from "../../modules/mod_logs";
|
||||||
import { isModerator, NO_MANAGER_MSG, parseUser, storeInfraction } from "../../util";
|
import { dedupeArray, embed, EmbedColor, isModerator, NO_MANAGER_MSG, parseUser, parseUserOrId, sanitizeMessageContent, storeInfraction } from "../../util";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'kick',
|
name: 'kick',
|
||||||
aliases: [ 'yeet', 'vent' ],
|
aliases: [ 'yeet', 'vent' ],
|
||||||
description: 'Eject a member from the server',
|
description: 'Kick a member from the server',
|
||||||
syntax: '/kick @username [reason?]',
|
syntax: '/kick @username [reason?]',
|
||||||
removeEmptyArgs: true,
|
removeEmptyArgs: true,
|
||||||
category: CommandCategory.Moderation,
|
category: CommandCategory.Moderation,
|
||||||
|
@ -23,27 +25,78 @@ export default {
|
||||||
return await message.reply(`Sorry, I do not have \`KickMembers\` permission.`);
|
return await message.reply(`Sorry, I do not have \`KickMembers\` permission.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 0)
|
const userInput = !message.reply_ids?.length ? args.shift() || '' : undefined;
|
||||||
return message.reply(`You need to provide a target user!`);
|
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 ` +
|
||||||
|
`by specifying a comma-separated list of usernames.`,
|
||||||
|
'No target user specified',
|
||||||
|
EmbedColor.SoftError,
|
||||||
|
),
|
||||||
|
] });
|
||||||
|
|
||||||
let targetUser = await parseUser(args.shift()!);
|
let reason = args.join(' ')
|
||||||
if (!targetUser) return message.reply('Sorry, I can\'t find that user.');
|
?.replace(new RegExp('`', 'g'), '\'')
|
||||||
|
?.replace(new RegExp('\n', 'g'), ' ');
|
||||||
|
|
||||||
if (targetUser._id == message.author_id) {
|
if (reason.length > 200) return message.reply({
|
||||||
return message.reply('nah');
|
embeds: [ embed('Kick reason may not be longer than 200 characters.', null, EmbedColor.SoftError) ]
|
||||||
}
|
});
|
||||||
|
|
||||||
if (targetUser._id == client.user!._id) {
|
const embeds: SendableEmbed[] = [];
|
||||||
return message.reply('lol no');
|
const handledUsers: string[] = [];
|
||||||
}
|
const targetUsers: User|{ _id: string }[] = [];
|
||||||
|
|
||||||
let reason = args.join(' ') || 'No reason provided';
|
const targetInput = dedupeArray(
|
||||||
|
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)
|
||||||
|
: userInput!.split(','),
|
||||||
|
);
|
||||||
|
|
||||||
let targetMember: Member;
|
for (const userStr of targetInput) {
|
||||||
try {
|
try {
|
||||||
targetMember = await message.serverContext.fetchMember(targetUser._id);
|
let user = await parseUserOrId(userStr);
|
||||||
|
if (!user) {
|
||||||
|
embeds.push(embed(`I can't resolve \`${sanitizeMessageContent(userStr).trim()}\` to a user.`, null, '#ff785d'));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Silently ignore duplicates
|
||||||
|
if (handledUsers.includes(user._id)) continue;
|
||||||
|
handledUsers.push(user._id);
|
||||||
|
|
||||||
|
if (user._id == message.author_id) {
|
||||||
|
embeds.push(embed('You might want to avoid kicking yourself...', null, EmbedColor.Warning));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user._id == client.user!._id) {
|
||||||
|
embeds.push(embed('I won\'t allow you to get rid of me this easily :trol:', null, EmbedColor.Warning));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
targetUsers.push(user);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return message.reply(`Failed to fetch member: \`${e}\``);
|
console.error(e);
|
||||||
|
embeds.push(embed(
|
||||||
|
`Failed to kick target \`${sanitizeMessageContent(userStr).trim()}\`: ${e}`,
|
||||||
|
`Failed to kick: An error has occurred`,
|
||||||
|
EmbedColor.Error,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const members = await message.serverContext.fetchMembers();
|
||||||
|
|
||||||
|
for (const user of targetUsers) {
|
||||||
|
try {
|
||||||
|
const member = members.members.find(m => m._id.user == user._id);
|
||||||
|
if (!member) {
|
||||||
|
embeds.push(embed(''));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let infId = ulid();
|
let infId = ulid();
|
||||||
|
@ -54,21 +107,41 @@ export default {
|
||||||
reason: reason,
|
reason: reason,
|
||||||
server: message.serverContext._id,
|
server: message.serverContext._id,
|
||||||
type: InfractionType.Manual,
|
type: InfractionType.Manual,
|
||||||
user: targetUser._id,
|
user: user._id,
|
||||||
actionType: 'kick',
|
actionType: 'kick',
|
||||||
}
|
}
|
||||||
let { userWarnCount } = await storeInfraction(infraction);
|
|
||||||
|
|
||||||
try {
|
let [ { userWarnCount } ] = await Promise.all([
|
||||||
await targetMember.kick();
|
storeInfraction(infraction),
|
||||||
|
logModAction('kick', message.serverContext, message.member!, user._id, reason, infraction._id),
|
||||||
|
member.kick(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
embeds.push({
|
||||||
|
title: `User kicked`,
|
||||||
|
icon_url: user instanceof User ? user.generateAvatarURL() : undefined,
|
||||||
|
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}\``
|
||||||
|
});
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return message.reply(`Failed to kick user: \`${e}\``);
|
embeds.push(embed(`Failed to kick user ${await fetchUsername(user._id)}: ${e}`, 'Failed to kick user', EmbedColor.Error));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
let firstMsg = true;
|
||||||
message.reply(`### @${targetUser.username} has been ${Math.random() > 0.8 ? 'yeeted' : 'kicked'}.\n`
|
while (embeds.length > 0) {
|
||||||
+ `Infraction ID: \`${infId}\` (**#${userWarnCount}** for this user)`),
|
const targetEmbeds = embeds.splice(0, 10);
|
||||||
logModAction('kick', message.serverContext, message.member!, targetUser._id, reason, infraction._id),
|
|
||||||
]);
|
if (firstMsg) {
|
||||||
|
await message.reply({ embeds: targetEmbeds, content: 'Operation completed.' }, false);
|
||||||
|
} else {
|
||||||
|
await message.channel?.sendMessage({ embeds: targetEmbeds });
|
||||||
|
}
|
||||||
|
firstMsg = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} as SimpleCommand;
|
} as SimpleCommand;
|
||||||
|
|
Loading…
Reference in a new issue