UNPKG

koishi-plugin-steam-family-bot

Version:

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

70 lines 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DBService = void 0; const interface_1 = require("../../interface"); const koishi_1 = require("koishi"); const steamFamilyLibDAO_1 = require("./steamFamilyLibDAO"); const subscriptionDAO_1 = require("./subscriptionDAO"); const steamAccountDAO_1 = require("./steamAccountDAO"); class DBService extends interface_1.IDBService { db; constructor(ctx) { const FamilyLib = new steamFamilyLibDAO_1.SteamFamilyLibDAO(ctx.database); const Subscription = new subscriptionDAO_1.SubscriptionDAO(ctx.database); const Account = new steamAccountDAO_1.SteamAccountDAO(ctx.database); super(Account, FamilyLib, Subscription); this.db = ctx.database; } async invalidAccount(id, subId) { await this.db.withTransaction(async (db) => { // await this.Subscription.inactiveSubscription(subId) await this.Account.invalidAccount(id); }); } async clearAccountInfo(account) { const res = await this.db .join(['SteamFamilyLibSubscribe', 'SteamRelateChannelInfo'], (sub, channel) => koishi_1.$.and(koishi_1.$.eq(sub.id, channel.refId), koishi_1.$.eq(channel.type, 'sub'))) .where((row) => { return koishi_1.$.and(koishi_1.$.eq(row.SteamRelateChannelInfo.refId, row.SteamFamilyLibSubscribe.id), koishi_1.$.eq(row.SteamFamilyLibSubscribe.accountId, account.id)); }) .execute(); await this.db.withTransaction(async (database) => { await database.remove('SteamFamilyLib', { familyId: res?.[0]?.SteamFamilyLibSubscribe.steamFamilyId, }); await database.remove('SteamAccountFamilyRel', { familyId: res?.[0]?.SteamFamilyLibSubscribe.steamFamilyId, }); await database.remove('SteamRelateChannelInfo', { refId: res .map((it) => it.SteamRelateChannelInfo.refId) .concat([account.id]), }); await database.remove('SteamFamilyLibSubscribe', { accountId: account.id, }); await database.remove('SteamAccount', { id: account.id, }); }); } async getAllSubscription() { const selection = this.db.join([ 'SteamAccount', 'SteamAccountFamilyRel', 'SteamFamilyLibSubscribe', 'SteamRelateChannelInfo', ], (account, rel, sub, channel) => koishi_1.$.and(koishi_1.$.eq(account.steamId, rel.steamId), koishi_1.$.eq(sub.steamFamilyId, rel.familyId), koishi_1.$.eq(sub.accountId, account.id), koishi_1.$.eq(sub.id, channel.refId), koishi_1.$.eq(channel.type, 'sub'))); const subscribe = await selection .where((row) => koishi_1.$.and(koishi_1.$.eq(row.SteamFamilyLibSubscribe.accountId, row.SteamAccount.id), koishi_1.$.eq(row.SteamFamilyLibSubscribe.active, true), koishi_1.$.eq(row.SteamAccount.status, 'valid'))) .execute(); return subscribe.map((item) => ({ subscription: item.SteamFamilyLibSubscribe, account: item.SteamAccount, steamAndFamilyRel: item.SteamAccountFamilyRel, channel: item.SteamRelateChannelInfo, })); } } exports.DBService = DBService; //# sourceMappingURL=index.js.map