feat(arabot): add basic group creation

This commit is contained in:
smyalygames 2023-02-27 18:03:38 +00:00
parent b859e4b617
commit 7a1cf06715
2 changed files with 97 additions and 4 deletions

View File

@ -20,7 +20,12 @@
import { Subcommand } from '@sapphire/plugin-subcommands';
import { RegisterBehavior } from '@sapphire/framework';
import { updateUser } from '#utils/database/dbExistingUser';
import { createEvent } from '#utils/database/outreach';
import {
checkActiveEvent,
createEvent,
createStat,
getCurrentEvent,
} from '#utils/database/outreach';
export class OutreachCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
@ -109,7 +114,6 @@ export class OutreachCommand extends Subcommand {
if (modInteraction === null || guild === null) {
await interaction.reply({
content: 'Mod or guild was not found!',
fetchReply: true,
ephemeral: true,
});
return;
@ -120,7 +124,14 @@ export class OutreachCommand extends Subcommand {
if (mod === undefined) {
await interaction.reply({
content: 'Mod was not found!',
fetchReply: true,
ephemeral: true,
});
return;
}
if (await checkActiveEvent()) {
await interaction.reply({
content: 'There is already an active event!',
ephemeral: true,
});
return;
@ -130,4 +141,25 @@ export class OutreachCommand extends Subcommand {
await createEvent(modInteraction.user.id);
}
public async groupCreate(interaction: Subcommand.ChatInputCommandInteraction) {
const leader = interaction.options.getUser('leader', true);
const event = await getCurrentEvent();
if (event === null) {
await interaction.reply({
content: 'There is no current event!',
ephemeral: true,
});
return;
}
await createStat(event.id, leader.id);
await interaction.reply({
content: `Created a group with the leader being ${leader}`,
ephemeral: true,
});
}
}

View File

@ -1,11 +1,12 @@
import { container } from '@sapphire/framework';
import type { Snowflake } from 'discord.js';
// Events
export async function createEvent(
modId: Snowflake,
) {
// Add the user to the database
await container.database.event.create({
const event = await container.database.event.create({
data: {
leader: {
connect: {
@ -19,8 +20,68 @@ export async function createEvent(
},
},
});
return event.id;
}
export async function checkActiveEvent() {
const event = await container.database.event.findFirst({
where: {
endTime: null,
},
});
return event !== null;
}
export async function getCurrentEvent() {
const event = await container.database.event.findFirst({
where: {
endTime: null,
},
});
return event;
}
// Stats
export async function addStatUser(statId: number, userId: Snowflake) {
await container.database.participantStat.create({
data: {
stat: {
connect: {
id: statId,
},
},
user: {
connect: {
id: userId,
},
},
},
});
}
export async function createStat(eventId: number, leaderId: Snowflake) {
const stat = await container.database.stat.create({
data: {
event: {
connect: {
id: eventId,
},
},
leader: {
connect: {
id: leaderId,
},
},
},
});
await addStatUser(stat.id, leaderId);
}
// Misc
export async function countTypes() {
const count = await container.database.eventType.count();
return count;