mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 08:24:16 +02:00
Merge pull request #13 from smyalygames/main
feat(arabot): add sus slash command to have subcommands and to view sus notes
This commit is contained in:
commit
770f4309e3
@ -65,11 +65,13 @@ model Verify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Sus {
|
model Sus {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
user User @relation("susUser", fields: [userId], references: [id])
|
user User @relation("susUser", fields: [userId], references: [id])
|
||||||
userId String
|
userId String
|
||||||
mod User @relation("susMod", fields: [modId], references: [id])
|
mod User @relation("susMod", fields: [modId], references: [id])
|
||||||
modId String
|
modId String
|
||||||
|
time DateTime @default(now())
|
||||||
|
active Boolean @default(true)
|
||||||
note String
|
note String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,36 +17,72 @@
|
|||||||
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 { Command } from '@sapphire/framework';
|
import { Command, RegisterBehavior } from '@sapphire/framework';
|
||||||
import type { Message } from 'discord.js';
|
import { Message, MessageEmbed } from 'discord.js';
|
||||||
import { addExistingUser, userExists } from '../../utils/dbExistingUser';
|
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
import { addExistingUser, userExists } from '../../utils/dbExistingUser';
|
||||||
|
|
||||||
export class SusCommand extends Command {
|
export class SusCommand extends Command {
|
||||||
public constructor(context: Command.Context) {
|
public constructor(context: Command.Context) {
|
||||||
super(context, {
|
super(context, {
|
||||||
name: 'sus',
|
name: 'sus',
|
||||||
description: 'Adds a sus note about a user.',
|
description: 'Notes about users that are sus',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers that this is a slash command
|
// Registers that this is a slash command
|
||||||
public override registerApplicationCommands(registry: Command.Registry) {
|
public override registerApplicationCommands(registry: Command.Registry) {
|
||||||
registry.registerChatInputCommand((builder) => builder
|
registry.registerChatInputCommand(
|
||||||
.setName(this.name)
|
(builder) => builder
|
||||||
.setDescription(this.description)
|
.setName(this.name)
|
||||||
.addUserOption((option) =>
|
.setDescription(this.description)
|
||||||
option.setName('user')
|
// Subcommand to add a sus note
|
||||||
.setDescription('User to add the note')
|
.addSubcommand((command) => command.setName('add')
|
||||||
.setRequired(true))
|
.setDescription('Add a sus note about a user')
|
||||||
.addStringOption((option) =>
|
.addUserOption((option) => option.setName('user')
|
||||||
option.setName('note')
|
.setDescription('User to add the note')
|
||||||
.setDescription('Note about the user')
|
.setRequired(true))
|
||||||
.setRequired(true)));
|
.addStringOption((option) => option.setName('note')
|
||||||
|
.setDescription('Note about the user')
|
||||||
|
.setRequired(true)))
|
||||||
|
// Subcommand to list sus notes
|
||||||
|
.addSubcommand((command) => command.setName('view')
|
||||||
|
.setDescription('View a sus note for a user')
|
||||||
|
.addUserOption((option) => option.setName('user')
|
||||||
|
.setDescription('User to add the note')
|
||||||
|
.setRequired(true))),
|
||||||
|
{
|
||||||
|
behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command run
|
// Command run
|
||||||
public async chatInputRun(interaction: Command.ChatInputInteraction) {
|
public async chatInputRun(interaction: Command.ChatInputInteraction) {
|
||||||
|
const subcommand = interaction.options.getSubcommand(true);
|
||||||
|
|
||||||
|
// Checks what subcommand was run
|
||||||
|
switch (subcommand) {
|
||||||
|
case 'add': {
|
||||||
|
return await this.addNote(interaction);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'view': {
|
||||||
|
return await this.listNote(interaction);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If subcommand is invalid
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Invalid sub command!',
|
||||||
|
ephemeral: true,
|
||||||
|
fetchReply: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subcommand to add sus note
|
||||||
|
public async addNote(interaction: Command.ChatInputInteraction) {
|
||||||
// Get the arguments
|
// Get the arguments
|
||||||
const user = interaction.options.getUser('user')!;
|
const user = interaction.options.getUser('user')!;
|
||||||
const mod = interaction.member!.user;
|
const mod = interaction.member!.user;
|
||||||
@ -62,6 +98,31 @@ export class SusCommand extends Command {
|
|||||||
fetchReply: true,
|
fetchReply: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async listNote(interaction: Command.ChatInputInteraction) {
|
||||||
|
const user = interaction.options.getUser('user')!;
|
||||||
|
|
||||||
|
// Gets the sus notes from the database
|
||||||
|
const notes = await findNote(user.id, true);
|
||||||
|
// Gets the username of the mod
|
||||||
|
const modId = notes[notes.length - 1].modId;
|
||||||
|
const mod = interaction.guild!.members.cache.get(modId)!.user.username;
|
||||||
|
|
||||||
|
// Creates the embed to display the sus note
|
||||||
|
const noteEmbed = new MessageEmbed()
|
||||||
|
.setColor('#0099ff')
|
||||||
|
.setTitle(`Sus notes for ${user.username}`)
|
||||||
|
// .setThumbnail(user.avatar!)
|
||||||
|
.addField(`Moderator: ${mod} Date: ${notes[notes.length - 1].time}`, notes[notes.length - 1].note);
|
||||||
|
|
||||||
|
// Sends the notes to the user
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [noteEmbed],
|
||||||
|
ephemeral: true,
|
||||||
|
fetchReply: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async messageRun(message: Message) {
|
public async messageRun(message: Message) {
|
||||||
const msg = await message.channel.send('Ping?');
|
const msg = await message.channel.send('Ping?');
|
||||||
|
|
||||||
@ -109,3 +170,21 @@ async function addToDatabase(userId: string, modId: string, message: string) {
|
|||||||
// Close the database connection
|
// Close the database connection
|
||||||
await prisma.$disconnect();
|
await prisma.$disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a list of sus notes from the user
|
||||||
|
async function findNote(userId: string, active: boolean) {
|
||||||
|
// Initialise the database connection
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
// Query to get the specific user's sus notes
|
||||||
|
const getNote = await prisma.sus.findMany({
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
active,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Close the database connection
|
||||||
|
await prisma.$disconnect();
|
||||||
|
return getNote;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user