mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-10-27 12:27:40 +01: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/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Args, Command } from '@sapphire/framework';
|
import {
|
||||||
import type { User, Message, Snowflake, Guild } from 'discord.js';
|
Args,
|
||||||
import { addExistingUser, updateUser } from '#utils/database/dbExistingUser';
|
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 { 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 {
|
export class WarnCommand extends Command {
|
||||||
public constructor(context: Command.LoaderContext, options: Command.Options) {
|
public constructor(context: Command.LoaderContext, options: Command.Options) {
|
||||||
super(context, {
|
super(context, {
|
||||||
...options,
|
...options,
|
||||||
name: 'warn',
|
name: 'warn',
|
||||||
description: 'Warns a user (only used for logging to a database for now)',
|
description: 'Warns a user',
|
||||||
preconditions: [['CoordinatorOnly', 'ModOnly']],
|
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) {
|
public async messageRun(message: Message, args: Args) {
|
||||||
// Get arguments
|
// Get arguments
|
||||||
let user: User;
|
let user: User;
|
||||||
@ -76,9 +131,10 @@ export class WarnCommand extends Command {
|
|||||||
|
|
||||||
if (!warn.success) {
|
if (!warn.success) {
|
||||||
await message.react('❌');
|
await message.react('❌');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// await message.react('✅');
|
await message.react('✅');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async warn(
|
private async warn(
|
||||||
@ -104,24 +160,67 @@ export class WarnCommand extends Command {
|
|||||||
// Check if mod is in database
|
// Check if mod is in database
|
||||||
await updateUser(mod);
|
await updateUser(mod);
|
||||||
|
|
||||||
// Gets guildMember
|
// Gets User for person being restricted
|
||||||
let member = guild.members.cache.get(userId);
|
let user = guild.client.users.cache.get(userId);
|
||||||
|
|
||||||
if (member === undefined) {
|
if (user === undefined) {
|
||||||
member = await guild.members.fetch(userId).catch(() => undefined);
|
user = await guild.client.users.fetch(userId);
|
||||||
}
|
if (user === undefined) {
|
||||||
|
info.message = 'Error fetching user';
|
||||||
if (member === undefined) {
|
|
||||||
info.message = 'User is not on this server';
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await addExistingUser(member);
|
|
||||||
|
|
||||||
await addWarn(userId, modId, reason);
|
await addWarn(userId, modId, reason);
|
||||||
|
|
||||||
info.message = `Warned ${member}`;
|
info.message = `Warned ${user}`;
|
||||||
info.success = true;
|
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;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,14 @@ export async function addWarn(
|
|||||||
await container.database.warning.create({
|
await container.database.warning.create({
|
||||||
data: {
|
data: {
|
||||||
user: {
|
user: {
|
||||||
connect: {
|
connectOrCreate: {
|
||||||
|
where: {
|
||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
|
create: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mod: {
|
mod: {
|
||||||
connect: {
|
connect: {
|
||||||
|
|||||||
@ -122,6 +122,7 @@ const devIDs = {
|
|||||||
logs: {
|
logs: {
|
||||||
restricted: '999431681217937513',
|
restricted: '999431681217937513',
|
||||||
economy: '999431681599623198',
|
economy: '999431681599623198',
|
||||||
|
sus: '999431681599623199',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
|
|||||||
@ -124,6 +124,7 @@ let IDs = {
|
|||||||
logs: {
|
logs: {
|
||||||
restricted: '920993034462715925',
|
restricted: '920993034462715925',
|
||||||
economy: '932050015034159174',
|
economy: '932050015034159174',
|
||||||
|
sus: '872884989950324826',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user