mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:04:15 +02:00
feat(arabot): add updating statistics for outreach groups
This commit is contained in:
parent
c55d5ffe93
commit
dec6de8398
10
prisma/migrations/20230228200640_stat_role/migration.sql
Normal file
10
prisma/migrations/20230228200640_stat_role/migration.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "StatRole" (
|
||||||
|
"statId" INTEGER NOT NULL,
|
||||||
|
"roleId" TEXT NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "StatRole_pkey" PRIMARY KEY ("statId")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "StatRole" ADD CONSTRAINT "StatRole_statId_fkey" FOREIGN KEY ("statId") REFERENCES "Stat"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -26,7 +26,12 @@ import {
|
|||||||
checkActiveEvent,
|
checkActiveEvent,
|
||||||
createEvent,
|
createEvent,
|
||||||
createStat,
|
createStat,
|
||||||
getCurrentEvent, getStatFromLeader, getStatFromRole, getStatGroups, userInStats,
|
getCurrentEvent,
|
||||||
|
getStatFromLeader,
|
||||||
|
getStatFromRole,
|
||||||
|
getStatGroups,
|
||||||
|
updateStats,
|
||||||
|
userInStats,
|
||||||
} from '#utils/database/outreach';
|
} from '#utils/database/outreach';
|
||||||
import IDs from '#utils/ids';
|
import IDs from '#utils/ids';
|
||||||
|
|
||||||
@ -96,6 +101,8 @@ export class OutreachCommand extends Subcommand {
|
|||||||
.setDescription('How many said would go vegan?'))
|
.setDescription('How many said would go vegan?'))
|
||||||
.addIntegerOption((option) => option.setName('considered')
|
.addIntegerOption((option) => option.setName('considered')
|
||||||
.setDescription('How many seriously considered being vegan?'))
|
.setDescription('How many seriously considered being vegan?'))
|
||||||
|
.addIntegerOption((option) => option.setName('anti-vegan')
|
||||||
|
.setDescription('How many people had anti-vegan viewpoints?'))
|
||||||
.addIntegerOption((option) => option.setName('thanked')
|
.addIntegerOption((option) => option.setName('thanked')
|
||||||
.setDescription('How many thanked you for the conversation?'))
|
.setDescription('How many thanked you for the conversation?'))
|
||||||
.addIntegerOption((option) => option.setName('documentary')
|
.addIntegerOption((option) => option.setName('documentary')
|
||||||
@ -280,4 +287,48 @@ export class OutreachCommand extends Subcommand {
|
|||||||
content: `Added ${user} to the group!`,
|
content: `Added ${user} to the group!`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async groupUpdate(interaction: Subcommand.ChatInputCommandInteraction) {
|
||||||
|
const vegan = interaction.options.getInteger('vegan');
|
||||||
|
const considered = interaction.options.getInteger('considered');
|
||||||
|
const antiVegan = interaction.options.getInteger('anti-vegan');
|
||||||
|
const thanked = interaction.options.getInteger('thanked');
|
||||||
|
const documentary = interaction.options.getInteger('documentary');
|
||||||
|
const educated = interaction.options.getInteger('educated');
|
||||||
|
const leader = interaction.user;
|
||||||
|
|
||||||
|
const stats = {
|
||||||
|
vegan: vegan !== null ? vegan : 0,
|
||||||
|
considered: considered !== null ? considered : 0,
|
||||||
|
antiVegan: antiVegan !== null ? antiVegan : 0,
|
||||||
|
thanked: thanked !== null ? thanked : 0,
|
||||||
|
documentary: documentary !== null ? documentary : 0,
|
||||||
|
educated: educated !== null ? educated : 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (leader === null) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Could not find your user!',
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.deferReply({ ephemeral: true });
|
||||||
|
|
||||||
|
const stat = await getStatFromLeader(leader.id);
|
||||||
|
|
||||||
|
if (stat === null) {
|
||||||
|
await interaction.editReply({
|
||||||
|
content: 'You\'re not the leader of a group!',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateStats(stat.id, stats);
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
content: 'Updated the database with the stats!',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,44 @@ export async function createStat(eventId: number, leaderId: Snowflake, roleId: S
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateStats(
|
||||||
|
statId: number,
|
||||||
|
stats: {
|
||||||
|
vegan: number,
|
||||||
|
considered: number,
|
||||||
|
antiVegan: number,
|
||||||
|
thanked: number,
|
||||||
|
documentary: number,
|
||||||
|
educated: number,
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
await container.database.stat.update({
|
||||||
|
where: {
|
||||||
|
id: statId,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
vegan: {
|
||||||
|
increment: stats.vegan,
|
||||||
|
},
|
||||||
|
considered: {
|
||||||
|
increment: stats.considered,
|
||||||
|
},
|
||||||
|
antivegan: {
|
||||||
|
increment: stats.antiVegan,
|
||||||
|
},
|
||||||
|
thanked: {
|
||||||
|
increment: stats.thanked,
|
||||||
|
},
|
||||||
|
documentary: {
|
||||||
|
increment: stats.documentary,
|
||||||
|
},
|
||||||
|
educated: {
|
||||||
|
increment: stats.educated,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function getStatGroups(eventId: number) {
|
export async function getStatGroups(eventId: number) {
|
||||||
const stats = await container.database.stat.findMany({
|
const stats = await container.database.stat.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user