rename bot directory to src, add chatwidget

This commit is contained in:
2025-07-09 16:50:16 +02:00
parent 8fd889856b
commit 3e025a586a
59 changed files with 417 additions and 1 deletions

38
src/db/dbAuth.ts Normal file
View File

@@ -0,0 +1,38 @@
import type { AccessToken } from "@twurple/auth";
import pocketbase, { type authRecord } from "./connection";
const pb = pocketbase.collection('auth');
export async function createAuthRecord(token: AccessToken, userId: string) {
try {
const data: authRecord = {
accesstoken: token,
id: userId
};
await pb.create(data);
} catch (err) { };
};
export async function getAuthRecord(userId: string, requiredIntents: string[]) {
try {
const data = await pb.getOne(userId);
if (!requiredIntents.every(intent => data.accesstoken.scope.includes(intent))) return undefined;
return { accesstoken: data.accesstoken };
} catch (err) {
return undefined;
};
};
export async function updateAuthRecord(userId: string, newtoken: AccessToken) {
try {
const newrecord = {
accesstoken: newtoken,
};
await pb.update(userId, newrecord);
} catch (err) { };
};
export async function deleteAuthRecord(userId: string): Promise<void> {
try {
await pb.delete(userId);
} catch (err) { };
};