mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 13:54:12 +02:00
feat(arabot): completed warn command
This commit is contained in:
parent
bb6ac8aef0
commit
02298f2089
@ -17,26 +17,81 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Args, Command } from '@sapphire/framework';
|
||||
import type { User, Message, Snowflake, Guild } from 'discord.js';
|
||||
import { addExistingUser, updateUser } from '#utils/database/dbExistingUser';
|
||||
import {
|
||||
Args,
|
||||
Command,
|
||||
container,
|
||||
RegisterBehavior,
|
||||
} from '@sapphire/framework';
|
||||
import type { User, Message, Snowflake, Guild, TextChannel } from 'discord.js';
|
||||
import { updateUser } from '#utils/database/dbExistingUser';
|
||||
import { addWarn } from '#utils/database/warnings';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
|
||||
/*
|
||||
This command is not intended to be functional for now, this is purely to log
|
||||
warnings onto a database, so if we were to switch purely to ARA Bot, it would
|
||||
mean we would have a lot of the warns already in the database.
|
||||
*/
|
||||
export class WarnCommand extends Command {
|
||||
public constructor(context: Command.LoaderContext, options: Command.Options) {
|
||||
super(context, {
|
||||
...options,
|
||||
name: 'warn',
|
||||
description: 'Warns a user (only used for logging to a database for now)',
|
||||
description: 'Warns a user',
|
||||
preconditions: [['CoordinatorOnly', 'ModOnly']],
|
||||
});
|
||||
}
|
||||
|
||||
// Registers that this is a slash command
|
||||
public override registerApplicationCommands(registry: Command.Registry) {
|
||||
registry.registerChatInputCommand(
|
||||
(builder) =>
|
||||
builder
|
||||
.setName(this.name)
|
||||
.setDescription(this.description)
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('user')
|
||||
.setDescription('User to warn')
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('reason')
|
||||
.setDescription('Reason for the warning')
|
||||
.setRequired(true),
|
||||
),
|
||||
{
|
||||
behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Command run
|
||||
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
|
||||
// Get the arguments
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const reason = interaction.options.getString('reason', true);
|
||||
const mod = interaction.user;
|
||||
const { guild } = interaction;
|
||||
|
||||
// Checks if all the variables are of the right type
|
||||
if (guild === null) {
|
||||
await interaction.reply({
|
||||
content: 'Error fetching guild!',
|
||||
ephemeral: true,
|
||||
fetchReply: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const info = await this.warn(user.id, mod.id, reason, guild);
|
||||
|
||||
await interaction.editReply({
|
||||
content: info.message,
|
||||
});
|
||||
}
|
||||
|
||||
// Non Application Command method for warning a user
|
||||
public async messageRun(message: Message, args: Args) {
|
||||
// Get arguments
|
||||
let user: User;
|
||||
@ -76,9 +131,10 @@ export class WarnCommand extends Command {
|
||||
|
||||
if (!warn.success) {
|
||||
await message.react('❌');
|
||||
return;
|
||||
}
|
||||
|
||||
// await message.react('✅');
|
||||
await message.react('✅');
|
||||
}
|
||||
|
||||
private async warn(
|
||||
@ -104,24 +160,67 @@ export class WarnCommand extends Command {
|
||||
// Check if mod is in database
|
||||
await updateUser(mod);
|
||||
|
||||
// Gets guildMember
|
||||
let member = guild.members.cache.get(userId);
|
||||
// Gets User for person being restricted
|
||||
let user = guild.client.users.cache.get(userId);
|
||||
|
||||
if (member === undefined) {
|
||||
member = await guild.members.fetch(userId).catch(() => undefined);
|
||||
if (user === undefined) {
|
||||
user = await guild.client.users.fetch(userId);
|
||||
if (user === undefined) {
|
||||
info.message = 'Error fetching user';
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
if (member === undefined) {
|
||||
info.message = 'User is not on this server';
|
||||
return info;
|
||||
}
|
||||
|
||||
await addExistingUser(member);
|
||||
|
||||
await addWarn(userId, modId, reason);
|
||||
|
||||
info.message = `Warned ${member}`;
|
||||
info.message = `Warned ${user}`;
|
||||
info.success = true;
|
||||
|
||||
// DM the reason
|
||||
|
||||
const dmEmbed = new EmbedBuilder()
|
||||
.setColor('#FF6700')
|
||||
.setAuthor({
|
||||
name: "You've been warned!",
|
||||
iconURL: `${user.displayAvatarURL()}`,
|
||||
})
|
||||
.addFields({ name: 'Reason', value: reason })
|
||||
.setTimestamp();
|
||||
|
||||
await user.send({ embeds: [dmEmbed] }).catch(() => {});
|
||||
|
||||
// Log the ban
|
||||
let logChannel = guild.channels.cache.get(IDs.channels.logs.sus) as
|
||||
| TextChannel
|
||||
| undefined;
|
||||
|
||||
if (logChannel === undefined) {
|
||||
logChannel = (await guild.channels.fetch(
|
||||
IDs.channels.logs.restricted,
|
||||
)) as TextChannel | undefined;
|
||||
if (logChannel === undefined) {
|
||||
container.logger.error('Warn Error: Could not fetch log channel');
|
||||
info.message = `Warned ${user} but could not find the log channel. This has been logged to the database.`;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
const message = new EmbedBuilder()
|
||||
.setColor('#FF6700')
|
||||
.setAuthor({
|
||||
name: `Warned ${user.tag}`,
|
||||
iconURL: `${user.displayAvatarURL()}`,
|
||||
})
|
||||
.addFields(
|
||||
{ name: 'User', value: `${user}`, inline: true },
|
||||
{ name: 'Moderator', value: `${mod}`, inline: true },
|
||||
{ name: 'Reason', value: reason },
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter({ text: `ID: ${userId}` });
|
||||
|
||||
await logChannel.send({ embeds: [message] });
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,13 @@ export async function addWarn(
|
||||
await container.database.warning.create({
|
||||
data: {
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
create: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
mod: {
|
||||
|
@ -122,6 +122,7 @@ const devIDs = {
|
||||
logs: {
|
||||
restricted: '999431681217937513',
|
||||
economy: '999431681599623198',
|
||||
sus: '999431681599623199',
|
||||
},
|
||||
},
|
||||
categories: {
|
||||
|
@ -124,6 +124,7 @@ let IDs = {
|
||||
logs: {
|
||||
restricted: '920993034462715925',
|
||||
economy: '932050015034159174',
|
||||
sus: '872884989950324826',
|
||||
},
|
||||
},
|
||||
categories: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user