mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 13:01:37 +01:00
add some documentation, add timeout and itemuses tracking system
This commit is contained in:
@@ -12,17 +12,32 @@ export type authRecord = {
|
||||
|
||||
export type userRecord = {
|
||||
id: string;
|
||||
username: string;
|
||||
username: string; // Don't use this, Use User.username or User.displayName. This is just to make the pocketbase data easier to read.
|
||||
balance: number;
|
||||
inventory: inventory;
|
||||
lastlootbox: string;
|
||||
};
|
||||
|
||||
export type usedItemRecord = {
|
||||
id?: string;
|
||||
user: string;
|
||||
item: string;
|
||||
created: string;
|
||||
};
|
||||
|
||||
export type timeoutRecord = {
|
||||
id?: string;
|
||||
user: string;
|
||||
target: string;
|
||||
item: string;
|
||||
created: string;
|
||||
};
|
||||
|
||||
interface TypedPocketBase extends PocketBase {
|
||||
collection(idOrName: 'auth'): RecordService<authRecord>;
|
||||
collection(idOrName: 'users'): RecordService<userRecord>;
|
||||
collection(idOrName: 'usedItems'): RecordService<usedItemRecord>;
|
||||
collection(idOrName: 'timeouts'): RecordService<timeoutRecord>;
|
||||
};
|
||||
|
||||
const pb = new PocketBase(pocketbaseurl) as TypedPocketBase;
|
||||
export default pb.autoCancellation(false);
|
||||
|
||||
export default new PocketBase(pocketbaseurl).autoCancellation(false) as TypedPocketBase;
|
||||
|
||||
12
bot/db/dbTimeouts.ts
Normal file
12
bot/db/dbTimeouts.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import pocketbase from "./connection";
|
||||
import { User } from "../user";
|
||||
const pb = pocketbase.collection('timeouts');
|
||||
|
||||
export async function createTimeoutRecord(user: User, target: User, item: string): Promise<void> {
|
||||
try {
|
||||
await pb.create({ user: user.id, target: target.id, item });
|
||||
} catch (err) {
|
||||
console.error(`Failed to create timeout record in database: user: ${user.id}, target: ${target.id}, item: ${item}`);
|
||||
console.error(err);
|
||||
};
|
||||
};
|
||||
12
bot/db/dbUsedItems.ts
Normal file
12
bot/db/dbUsedItems.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import pocketbase from "./connection";
|
||||
import { User } from "../user";
|
||||
const pb = pocketbase.collection('usedItems');
|
||||
|
||||
export async function createUsedItemRecord(user: User, item: string): Promise<void> {
|
||||
try {
|
||||
await pb.create({ user: user.id, item });
|
||||
} catch (err) {
|
||||
console.error(`Failed to create usedItem record in database: user: ${user.id}, item: ${item}`);
|
||||
console.error(err);
|
||||
};
|
||||
};
|
||||
@@ -6,7 +6,7 @@ const pb = pocketbase.collection('users');
|
||||
/** Use this function to both ensure existance and to retreive data */
|
||||
export async function getUserRecord(user: User): Promise<userRecord> {
|
||||
try {
|
||||
const data = await pb.getOne<userRecord>(user.id);
|
||||
const data = await pb.getOne(user.id);
|
||||
|
||||
if (Object.keys(data.inventory).sort().toString() !== itemarray.sort().toString()) { // If the items in the user inventory are missing an item.
|
||||
itemarray.forEach(key => {
|
||||
@@ -22,7 +22,7 @@ export async function getUserRecord(user: User): Promise<userRecord> {
|
||||
};
|
||||
|
||||
async function createUserRecord(user: User): Promise<userRecord> {
|
||||
const data = await pb.create<userRecord>({
|
||||
const data = await pb.create({
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
balance: 0,
|
||||
|
||||
Reference in New Issue
Block a user