mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 10:34:16 +02:00
feat(arabot): add basic group creation
This commit is contained in:
parent
b859e4b617
commit
7a1cf06715
@ -20,7 +20,12 @@
|
|||||||
import { Subcommand } from '@sapphire/plugin-subcommands';
|
import { Subcommand } from '@sapphire/plugin-subcommands';
|
||||||
import { RegisterBehavior } from '@sapphire/framework';
|
import { RegisterBehavior } from '@sapphire/framework';
|
||||||
import { updateUser } from '#utils/database/dbExistingUser';
|
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 {
|
export class OutreachCommand extends Subcommand {
|
||||||
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
|
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
|
||||||
@ -109,7 +114,6 @@ export class OutreachCommand extends Subcommand {
|
|||||||
if (modInteraction === null || guild === null) {
|
if (modInteraction === null || guild === null) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: 'Mod or guild was not found!',
|
content: 'Mod or guild was not found!',
|
||||||
fetchReply: true,
|
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -120,7 +124,14 @@ export class OutreachCommand extends Subcommand {
|
|||||||
if (mod === undefined) {
|
if (mod === undefined) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: 'Mod was not found!',
|
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,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -130,4 +141,25 @@ export class OutreachCommand extends Subcommand {
|
|||||||
|
|
||||||
await createEvent(modInteraction.user.id);
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { container } from '@sapphire/framework';
|
import { container } from '@sapphire/framework';
|
||||||
import type { Snowflake } from 'discord.js';
|
import type { Snowflake } from 'discord.js';
|
||||||
|
|
||||||
|
// Events
|
||||||
export async function createEvent(
|
export async function createEvent(
|
||||||
modId: Snowflake,
|
modId: Snowflake,
|
||||||
) {
|
) {
|
||||||
// Add the user to the database
|
// Add the user to the database
|
||||||
await container.database.event.create({
|
const event = await container.database.event.create({
|
||||||
data: {
|
data: {
|
||||||
leader: {
|
leader: {
|
||||||
connect: {
|
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() {
|
export async function countTypes() {
|
||||||
const count = await container.database.eventType.count();
|
const count = await container.database.eventType.count();
|
||||||
return count;
|
return count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user