getloot results are now stored in the database, use lootbox triggers getloot

This commit is contained in:
2025-09-15 13:40:05 +02:00
parent f8fb2c0317
commit 8284d79c5f
4 changed files with 31 additions and 0 deletions

View File

@@ -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()
]);
}

View File

@@ -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); };

View File

@@ -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<authRecord>;
collection(idOrName: 'users'): RecordService<userRecord>;
@@ -62,6 +69,7 @@ interface TypedPocketBase extends PocketBase {
collection(idOrName: 'cheerEvents'): RecordService<cheerEventRecord>;
collection(idOrName: 'cheers'): RecordService<cheerRecord>;
collection(idOrName: 'anivTimeouts'): RecordService<anivTimeoutRecord>;
collection(idOrName: 'getLoots'): RecordService<getLootRecord>;
};
export default new PocketBase(pocketbaseurl).autoCancellation(false) as TypedPocketBase;

19
src/db/dbGetLoot.ts Normal file
View File

@@ -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);
};
};