From 8284d79c5fd63e24c461b71759144b6ff413b7cd Mon Sep 17 00:00:00 2001 From: qwerinope Date: Mon, 15 Sep 2025 13:40:05 +0200 Subject: [PATCH] getloot results are now stored in the database, `use lootbox` triggers getloot --- src/commands/getloot.ts | 2 ++ src/commands/useitem.ts | 2 ++ src/db/connection.ts | 8 ++++++++ src/db/dbGetLoot.ts | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 src/db/dbGetLoot.ts diff --git a/src/commands/getloot.ts b/src/commands/getloot.ts index 5acffc0..1561a56 100644 --- a/src/commands/getloot.ts +++ b/src/commands/getloot.ts @@ -6,6 +6,7 @@ import { buildTimeString } from "lib/dateManager"; import { timeout } from "lib/timeout"; import { isInvuln, removeInvuln } from "lib/invuln"; import { streamerUsers } from "main"; +import { createGetLootRecord } from "db/dbGetLoot"; const COOLDOWN = 10 * 60 * 1000; // 10 mins (ms) @@ -79,6 +80,7 @@ export default new Command({ await Promise.all([ updateUserRecord(user, userData), sendMessage(message, msg.messageId), + createGetLootRecord(user, gainedqbucks, itemDiff), user.clearLock() ]); } diff --git a/src/commands/useitem.ts b/src/commands/useitem.ts index 9726f4c..c6674b7 100644 --- a/src/commands/useitem.ts +++ b/src/commands/useitem.ts @@ -3,6 +3,7 @@ import { Command, sendMessage } from "commands"; import items from "items"; import { isInvuln, removeInvuln } from "lib/invuln"; import { streamerUsers } from "main"; +import getloot from "./getloot"; export default new Command({ name: 'use', @@ -13,6 +14,7 @@ export default new Command({ const messagequery = msg.messageText.trim().split(' ').slice(1); if (!messagequery[0]) { await sendMessage('Please specify an item you would like to use', msg.messageId); return; }; const selection = items.get(messagequery[0].toLowerCase()); + if (messagequery[0].toLowerCase() === "lootbox") { await getloot.execute(msg, user); return; }; if (!selection) { await sendMessage(`'${messagequery[0]}' is not an item`, msg.messageId); return; }; if (await redis.sismember('disabledcommands', selection.name)) { await sendMessage(`The ${selection.prettyName} item is disabled`, msg.messageId); return; }; if (await isInvuln(msg.chatterId) && !streamerUsers.includes(msg.chatterId)) { await sendMessage(`You're no longer an invuln because you used an item.`, msg.messageId); await removeInvuln(msg.chatterId); }; diff --git a/src/db/connection.ts b/src/db/connection.ts index 3bd016a..ef6fd3f 100644 --- a/src/db/connection.ts +++ b/src/db/connection.ts @@ -54,6 +54,13 @@ export type anivTimeoutRecord = { duration: number; }; +export type getLootRecord = { + id?: string; + user: string; + qbucks: number; + items: inventory; +}; + interface TypedPocketBase extends PocketBase { collection(idOrName: 'auth'): RecordService; collection(idOrName: 'users'): RecordService; @@ -62,6 +69,7 @@ interface TypedPocketBase extends PocketBase { collection(idOrName: 'cheerEvents'): RecordService; collection(idOrName: 'cheers'): RecordService; collection(idOrName: 'anivTimeouts'): RecordService; + collection(idOrName: 'getLoots'): RecordService; }; export default new PocketBase(pocketbaseurl).autoCancellation(false) as TypedPocketBase; diff --git a/src/db/dbGetLoot.ts b/src/db/dbGetLoot.ts new file mode 100644 index 0000000..397032f --- /dev/null +++ b/src/db/dbGetLoot.ts @@ -0,0 +1,19 @@ +import pocketbase from "db/connection"; +import type { inventory } from "items"; +import logger from "lib/logger"; +import type User from "user"; + +const pb = pocketbase.collection('getLoots'); + +export async function createGetLootRecord(user: User, qbucks: number, inventory: inventory) { + try { + await pb.create({ + user: user.id, + qbucks, + items: inventory + }); + } catch (e) { + logger.err(`Failed to create getLoot record for ${user.displayName}: ${inventory}`); + logger.err(e as string); + }; +};