koishi-plugin-beatsaber-bot
Version:
一个 用于 BeatSaber 的 koishi Bot 插件
54 lines (53 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleScoreSaberBind = void 0;
const koishi_1 = require("koishi");
const db_1 = require("../../service/db/db");
const handleScoreSaberBind = async (ctx, api, { session, options }, input) => {
const scoreSaberUser = await api.ScoreSaber
.wrapperResult()
.withRetry(3)
.getScoreUserById(input);
if (!scoreSaberUser.isSuccess()) {
const text = session.text('commands.bsbot.bind.not-found', { id: input, platform: "ScoreSaber" });
session.send((0, koishi_1.h)('message', (0, koishi_1.h)('quote', { id: session.messageId }), text));
return;
}
const { ssAccount, blAccount } = await (0, db_1.getUserBSAccountInfo)(ctx, session.user.id);
let text = session.text('commands.bsbot.bind.ack-prompt', { user: `${scoreSaberUser.data.name}(${scoreSaberUser.data.id})` })
+ (ssAccount ? "," + session.text('commands.bsbot.bind.exist', { id: ssAccount.platformUid }) : "");
session.sendQuote(text);
const prompt = await session.prompt(30000);
if (!prompt || prompt != 'y' && prompt != 'yes') {
session.sendQuote(session.text(prompt ? 'commands.bsbot.bind.cancel' : 'commands.bsbot.bind.timeout'));
return;
}
let now = new Date();
let account = {
uid: session.user.id,
platform: 'scoresaber',
platformUid: scoreSaberUser.data.id,
lastModifiedAt: now,
lastRefreshAt: now,
platformUname: scoreSaberUser.data.name,
type: 'id',
};
if (!blAccount) {
let account = {
uid: session.user.id,
platform: 'beatleader',
platformUid: scoreSaberUser.data.id,
lastModifiedAt: now,
lastRefreshAt: now,
platformUname: scoreSaberUser.data.name,
type: 'id',
};
const res = await ctx.database.upsert('BSRelateOAuthAccount', [account]);
}
if (ssAccount) {
account.id = ssAccount.id;
}
const res = await ctx.database.upsert('BSRelateOAuthAccount', [account]);
session.sendQuote(session.text('commands.bsbot.bind.success', { user: `${scoreSaberUser.data.name}(${scoreSaberUser.data.id})` }));
};
exports.handleScoreSaberBind = handleScoreSaberBind;