Skip to content

Commit

Permalink
Award presents on birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Jan 21, 2025
1 parent 83dbc13 commit fe74bfb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/service/birthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
],
);
}
}

0 comments on commit fe74bfb

Please sign in to comment.