UNPKG

koishi-plugin-steam-family-bot

Version:

一个用于新版 Steam 家庭的库存监控 koishi Bot 插件

122 lines 4.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SteamAccountDAO = void 0; const koishi_1 = require("koishi"); class SteamAccountDAO { db; constructor(db) { this.db = db; } async getSteamAccountBySessionUid(uid) { const res = await this.db .join(['SteamAccount', 'SteamRelateChannelInfo', 'SteamAccountFamilyRel'], (account, channel, rel) => koishi_1.$.and(koishi_1.$.eq(account.id, channel.refId), koishi_1.$.eq(channel.type, 'account'), koishi_1.$.eq(account.steamId, rel.steamId)), [false, false, true]) .where((row) => { return koishi_1.$.and(koishi_1.$.eq(row.SteamAccount.id, row.SteamRelateChannelInfo.refId), koishi_1.$.eq(row.SteamRelateChannelInfo.uid, uid), koishi_1.$.eq(row.SteamRelateChannelInfo.type, 'account')); }) .execute(); if (res[0]) { return { ...res[0].SteamAccount, familyId: res[0].SteamAccountFamilyRel?.familyId, channel: res[0].SteamRelateChannelInfo, }; } return undefined; } async getSteamAccountBySteamId(steamid) { const res = await this.db .join(['SteamAccount', 'SteamAccountFamilyRel'], (account, rel) => { return koishi_1.$.eq(account.steamId, rel.steamId); }, [false, true]) .where((row) => { return koishi_1.$.eq(row.SteamAccount.steamId, steamid); }) .execute(); if (res[0]) { return { ...res[0].SteamAccount, familyId: res[0].SteamAccountFamilyRel?.familyId, }; } return undefined; } async upsertSteamAccount(account, channelInfo) { await this.db.withTransaction(async (db) => { await this.db.upsert('SteamAccount', [account]); let id = account.id; if (!account.id) { const res = await this.db.get('SteamAccount', { ...account, }); id = res[0].id; } await this.db.upsert('SteamRelateChannelInfo', [ { refId: id, ...channelInfo, type: 'account', }, ]); }); return; } async getSteamAccountBySteamIdAndSessionId(steamid, uid) { const res = await this.db .join(['SteamAccount', 'SteamAccountFamilyRel', 'SteamRelateChannelInfo'], (account, ref, channel) => koishi_1.$.and(koishi_1.$.eq(account.id, channel.refId), koishi_1.$.eq(channel.type, 'account')), [false, true, false]) .where((row) => { return koishi_1.$.and(koishi_1.$.eq(row.SteamAccount.steamId, row.SteamAccountFamilyRel.steamId), koishi_1.$.eq(row.SteamAccount.steamId, steamid), koishi_1.$.eq(row.SteamAccount.id, row.SteamRelateChannelInfo.refId), koishi_1.$.eq(row.SteamRelateChannelInfo.uid, uid), koishi_1.$.eq(row.SteamRelateChannelInfo.type, 'account')); }) .execute(); if (res[0]) { return { ...res[0].SteamAccount, familyId: res[0].SteamAccountFamilyRel?.familyId, }; } return undefined; } async updateSteamAccountToken(accountId, account) { const res = await this.db.set('SteamAccount', { id: accountId }, { ...account, }); } async invalidAccount(id) { const res = await this.db.set('SteamAccount', { id: id }, { status: 'invalid', }); } async getAuthedSteamAccountByFamilyId(familyId) { const res = await this.db .join(['SteamAccount', 'SteamAccountFamilyRel'], (account, rel) => { return koishi_1.$.eq(account.steamId, rel.steamId); }, [true, false]) .where((row) => { return koishi_1.$.and(koishi_1.$.eq(row.SteamAccountFamilyRel.familyId, familyId), koishi_1.$.eq(row.SteamAccount.status, 'valid')); }) .execute(); if (res[0] && res[0].SteamAccount) { return { ...res[0].SteamAccount, familyId: res[0].SteamAccountFamilyRel?.familyId, }; } return undefined; } async removeUnAuthAccount(accountId) { await this.db.withTransaction(async (db) => { await db.remove('SteamAccount', { id: accountId, }); await db.remove('SteamRelateChannelInfo', { refId: accountId, type: 'account', }); }); } async getAllSteamAccount() { const res = await this.db.select('SteamAccount').execute(); return res; } } exports.SteamAccountDAO = SteamAccountDAO; //# sourceMappingURL=steamAccountDAO.js.map