From fe74bfba1cfb5068030fde4444267ffce597ef4a Mon Sep 17 00:00:00 2001 From: holzmaster Date: Tue, 21 Jan 2025 19:02:49 +0100 Subject: [PATCH] Award presents on birthday --- src/service/birthday.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/service/birthday.ts b/src/service/birthday.ts index 2ba20a75..923d2842 100644 --- a/src/service/birthday.ts +++ b/src/service/birthday.ts @@ -3,6 +3,8 @@ import * as sentry from "@sentry/bun"; import log from "@log"; import * as birthday from "@/storage/birthday.js"; +import * as lootService from "@/service/loot.js"; +import * as lootDataService from "@/service/lootData.js"; import type { BotContext } from "@/context.js"; @@ -30,7 +32,7 @@ export async function checkBirthdays(context: BotContext) { let presentsGiven = false; try { - await awardBirthdayPresents(context, todaysBirthdaysAsMembers); + await awardBirthdayPresents(todaysBirthdaysAsMembers); presentsGiven = true; } catch (e) { sentry.captureException(e); @@ -99,3 +101,23 @@ ${userString} ${gotPresents ? "Zum Geurtstag habt ihr ein Geschenk erhalten" : " const message = users.length === 1 ? singularMessage : pluralMessage; await context.textChannels.hauptchat.send(message.replaceAll(/\n\s+/g, "\n")); } + +async function awardBirthdayPresents(users: GuildMember[]) { + const present = lootDataService.resolveLootTemplate(lootDataService.LootKindId.GESCHENK); + if (!present) { + throw new Error("Could not resolve loot template"); + } + + for (const member of users) { + await lootService.createLoot( + present, + member.user, + null, + "drop", + null, + lootDataService.lootAttributeTemplates[ + lootDataService.LootAttributeKindId.RARITY_NORMAL + ], + ); + } +}