mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:14:15 +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 {
|
model Stat {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
event Event @relation(fields: [eventId], references: [id])
|
event Event @relation(fields: [eventId], references: [id])
|
||||||
eventId Int
|
eventId Int
|
||||||
leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay
|
leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay
|
||||||
leaderId String
|
leaderId String
|
||||||
vegan Int @default(0)
|
vegan Int @default(0)
|
||||||
considered Int @default(0)
|
considered Int @default(0)
|
||||||
antivegan Int @default(0)
|
antivegan Int @default(0)
|
||||||
thanked Int @default(0)
|
thanked Int @default(0)
|
||||||
documentary Int @default(0)
|
documentary Int @default(0)
|
||||||
educated Int @default(0)
|
educated Int @default(0)
|
||||||
participationStats ParticipantStat[]
|
participants ParticipantStat[]
|
||||||
|
role StatRole[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model StatRole {
|
||||||
|
stat Stat @relation(fields: [statId], references: [id])
|
||||||
|
statId Int @id
|
||||||
|
roleId String
|
||||||
}
|
}
|
||||||
|
|
||||||
model ParticipantStat {
|
model ParticipantStat {
|
||||||
|
@ -24,7 +24,7 @@ import {
|
|||||||
checkActiveEvent,
|
checkActiveEvent,
|
||||||
createEvent,
|
createEvent,
|
||||||
createStat,
|
createStat,
|
||||||
getCurrentEvent,
|
getCurrentEvent, getStatGroups,
|
||||||
} from '#utils/database/outreach';
|
} from '#utils/database/outreach';
|
||||||
|
|
||||||
export class OutreachCommand extends Subcommand {
|
export class OutreachCommand extends Subcommand {
|
||||||
@ -144,18 +144,33 @@ export class OutreachCommand extends Subcommand {
|
|||||||
|
|
||||||
public async groupCreate(interaction: Subcommand.ChatInputCommandInteraction) {
|
public async groupCreate(interaction: Subcommand.ChatInputCommandInteraction) {
|
||||||
const leader = interaction.options.getUser('leader', true);
|
const leader = interaction.options.getUser('leader', true);
|
||||||
|
const { guild } = interaction;
|
||||||
|
|
||||||
const event = await getCurrentEvent();
|
if (guild === null) {
|
||||||
|
|
||||||
if (event === null) {
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: 'There is no current event!',
|
content: 'Guild not found!',
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
return;
|
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({
|
await interaction.reply({
|
||||||
content: `Created a group with the leader being ${leader}`,
|
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) {
|
export async function createStat(eventId: number, leaderId: Snowflake, roleId: Snowflake) {
|
||||||
const stat = await container.database.stat.create({
|
await container.database.stat.create({
|
||||||
data: {
|
data: {
|
||||||
event: {
|
event: {
|
||||||
connect: {
|
connect: {
|
||||||
@ -75,10 +75,35 @@ export async function createStat(eventId: number, leaderId: Snowflake) {
|
|||||||
id: leaderId,
|
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
|
// Misc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user