mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 13:54:12 +02:00
feat(arabot): add stat role to separate table
This commit is contained in:
parent
3baa0e2081
commit
da8088e157
@ -104,18 +104,25 @@ model EventType {
|
||||
}
|
||||
|
||||
model Stat {
|
||||
id Int @id @default(autoincrement())
|
||||
event Event @relation(fields: [eventId], references: [id])
|
||||
eventId Int
|
||||
leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay
|
||||
leaderId String
|
||||
vegan Int @default(0)
|
||||
considered Int @default(0)
|
||||
antivegan Int @default(0)
|
||||
thanked Int @default(0)
|
||||
documentary Int @default(0)
|
||||
educated Int @default(0)
|
||||
participationStats ParticipantStat[]
|
||||
id Int @id @default(autoincrement())
|
||||
event Event @relation(fields: [eventId], references: [id])
|
||||
eventId Int
|
||||
leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay
|
||||
leaderId String
|
||||
vegan Int @default(0)
|
||||
considered Int @default(0)
|
||||
antivegan Int @default(0)
|
||||
thanked Int @default(0)
|
||||
documentary Int @default(0)
|
||||
educated Int @default(0)
|
||||
participants ParticipantStat[]
|
||||
role StatRole[]
|
||||
}
|
||||
|
||||
model StatRole {
|
||||
stat Stat @relation(fields: [statId], references: [id])
|
||||
statId Int @id
|
||||
roleId String
|
||||
}
|
||||
|
||||
model ParticipantStat {
|
||||
|
@ -24,7 +24,7 @@ import {
|
||||
checkActiveEvent,
|
||||
createEvent,
|
||||
createStat,
|
||||
getCurrentEvent,
|
||||
getCurrentEvent, getStatGroups,
|
||||
} from '#utils/database/outreach';
|
||||
|
||||
export class OutreachCommand extends Subcommand {
|
||||
@ -144,18 +144,33 @@ export class OutreachCommand extends Subcommand {
|
||||
|
||||
public async groupCreate(interaction: Subcommand.ChatInputCommandInteraction) {
|
||||
const leader = interaction.options.getUser('leader', true);
|
||||
const { guild } = interaction;
|
||||
|
||||
const event = await getCurrentEvent();
|
||||
|
||||
if (event === null) {
|
||||
if (guild === null) {
|
||||
await interaction.reply({
|
||||
content: 'There is no current event!',
|
||||
content: 'Guild not found!',
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await createStat(event.id, leader.id);
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const event = await getCurrentEvent();
|
||||
|
||||
if (event === null) {
|
||||
await interaction.editReply({
|
||||
content: 'There is no current event!',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const statGroups = await getStatGroups(event.id);
|
||||
const groupNo = statGroups.length + 1;
|
||||
|
||||
const role = await guild.roles.create({ name: `Outreach Group ${groupNo}` });
|
||||
|
||||
await createStat(event.id, leader.id, role.id);
|
||||
|
||||
await interaction.reply({
|
||||
content: `Created a group with the leader being ${leader}`,
|
||||
|
@ -62,8 +62,8 @@ export async function addStatUser(statId: number, userId: Snowflake) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function createStat(eventId: number, leaderId: Snowflake) {
|
||||
const stat = await container.database.stat.create({
|
||||
export async function createStat(eventId: number, leaderId: Snowflake, roleId: Snowflake) {
|
||||
await container.database.stat.create({
|
||||
data: {
|
||||
event: {
|
||||
connect: {
|
||||
@ -75,10 +75,35 @@ export async function createStat(eventId: number, leaderId: Snowflake) {
|
||||
id: leaderId,
|
||||
},
|
||||
},
|
||||
participants: {
|
||||
create: {
|
||||
user: {
|
||||
connect: {
|
||||
id: leaderId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
role: {
|
||||
create: {
|
||||
roleId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getStatGroups(eventId: number) {
|
||||
const stats = await container.database.stat.findMany({
|
||||
where: {
|
||||
eventId,
|
||||
},
|
||||
orderBy: {
|
||||
id: 'asc',
|
||||
},
|
||||
});
|
||||
|
||||
await addStatUser(stat.id, leaderId);
|
||||
return stats;
|
||||
}
|
||||
|
||||
// Misc
|
||||
|
Loading…
x
Reference in New Issue
Block a user