mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
getloot results are now stored in the database, use lootbox triggers getloot
This commit is contained in:
@@ -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()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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); };
|
||||
|
||||
@@ -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
19
src/db/dbGetLoot.ts
Normal 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);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user