koishi-plugin-steam-family-bot
Version:
一个用于新版 Steam 家庭的库存监控 koishi Bot 插件
88 lines • 4.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionDAO = void 0;
const koishi_1 = require("koishi");
class SubscriptionDAO {
db;
constructor(db) {
this.db = db;
}
async getSubscriptionBySessionUId(uid) {
const res = await this.db
.join(['SteamRelateChannelInfo', 'SteamFamilyLibSubscribe'], (channel, sub) => koishi_1.$.and(koishi_1.$.eq(channel.refId, sub.id), koishi_1.$.eq(channel.type, 'sub')))
.where((row) => {
return koishi_1.$.and(koishi_1.$.eq(row.SteamRelateChannelInfo.uid, uid), koishi_1.$.eq(row.SteamRelateChannelInfo.type, 'sub'), koishi_1.$.eq(row.SteamFamilyLibSubscribe.id, row.SteamRelateChannelInfo.refId));
})
.execute();
return res?.[0]?.SteamFamilyLibSubscribe;
}
async removeSubscriptionBySessionUId(uid) {
await this.db.withTransaction(async (db) => {
const res = await 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.uid, uid), koishi_1.$.eq(row.SteamRelateChannelInfo.type, 'sub'), koishi_1.$.eq(row.SteamFamilyLibSubscribe.id, row.SteamRelateChannelInfo.refId));
})
.execute();
await db.remove('SteamFamilyLibSubscribe', {
id: res.map((it) => it.SteamFamilyLibSubscribe.id),
});
await db.remove('SteamRelateChannelInfo', {
refId: res.map((it) => it.SteamFamilyLibSubscribe.id),
});
});
}
async removeSubscriptionBySteamId(steamId) {
await this.db.withTransaction(async (db) => {
const res = await db
.join(['SteamRelateChannelInfo', 'SteamFamilyLibSubscribe'], (channel, sub) => koishi_1.$.and(koishi_1.$.eq(channel.refId, sub.id), koishi_1.$.eq(channel.type, 'sub')))
.where((row) => {
return koishi_1.$.and(koishi_1.$.eq(row.SteamFamilyLibSubscribe.steamAccountId, steamId), koishi_1.$.eq(row.SteamRelateChannelInfo.type, 'sub'), koishi_1.$.eq(row.SteamFamilyLibSubscribe.id, row.SteamRelateChannelInfo.refId));
})
.execute();
await db.remove('SteamFamilyLibSubscribe', {
id: res.map((it) => it.SteamFamilyLibSubscribe.id),
});
await db.remove('SteamRelateChannelInfo', {
refId: res.map((it) => it.SteamFamilyLibSubscribe.id),
type: 'sub',
});
});
}
async updateSubscription(sub) {
await this.db.upsert('SteamFamilyLibSubscribe', [sub]);
}
async inactiveSubscription(subId) {
await this.db.set('SteamFamilyLibSubscribe', { id: subId }, { active: false });
}
async addSubscription(sub, channelInfo) {
await this.db.withTransaction(async (db) => {
const res = await db.upsert('SteamFamilyLibSubscribe', [sub]);
const inserted = await db.get('SteamFamilyLibSubscribe', {
...sub,
});
await db.upsert('SteamRelateChannelInfo', [
{
...channelInfo,
refId: inserted[0].id,
type: 'sub',
},
]);
});
}
async getSubscriptionByChannelInfoAndFamilyId(familyId, channel) {
const chan = channel;
const subscribe = 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.SteamFamilyLibSubscribe.steamFamilyId, familyId), koishi_1.$.eq(row.SteamRelateChannelInfo.channelId, chan.channelId));
})
.execute();
return subscribe?.[0]?.SteamFamilyLibSubscribe;
}
async addFamilyAccountRel(items) {
await this.db.upsert('SteamAccountFamilyRel', items);
}
}
exports.SubscriptionDAO = SubscriptionDAO;
//# sourceMappingURL=subscriptionDAO.js.map