koishi-plugin-beatsaber-bot
Version:
一个 用于 BeatSaber 的 koishi Bot 插件
81 lines (80 loc) • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScoreCmd = void 0;
const converter_1 = require("../utils/converter");
const db_1 = require("../service/db/db");
require("../utils/extendedMethod");
const types_1 = require("../types");
function ScoreCmd(ctx, cfg, render, api, logger) {
const scoreCmd = ctx
.command('bsbot.score')
.alias('bbscore')
.userFields(['id'])
.option('p', '<platform:string>')
.option('d', '<diffculty:string>')
.option('m', '<mode:string>')
.action(async ({ session, options }, input) => {
let platform = options.p == 'ss' ? types_1.Platform.SS : types_1.Platform.BL;
let reg = /^([0-9a-fA-F]{3,5})(<at id="([0-9a-zA-z_]+)"\/>)?$/;
let onStartRender = () => {
session.send(session.text('common.render.wait', { sec: cfg.rankWaitTimeout / 1000 }));
};
if (!reg.test(input)) {
if (/^[0-9]+$/.test(input)) {
const img = await render.renderScore(input, platform, onStartRender);
session.sendQueued(img);
}
else {
const res = await session.sendQuote(session.text('commands.bsbot.score.not-a-score-id'));
}
return;
}
const [full, mapId, at, uid, , ...rest] = reg.exec(input);
let accountId;
if (!uid) {
const { blAccount } = await (0, db_1.getUserBSAccountInfo)(ctx, session.user.id);
if (blAccount) {
accountId = blAccount.platformUid;
}
else {
session.sendQuote(session.text('commands.bsbot.score.not-bind'));
return;
}
}
else {
const res = await ctx.database.get('binding', {
platform: session.platform,
pid: uid
});
const userId = res[0]?.aid;
if (userId) {
const { blAccount } = await (0, db_1.getUserBSAccountInfo)(ctx, userId);
if (blAccount) {
accountId = blAccount.platformUid;
}
}
else {
session.sendQuote(session.text('commands.bsbot.score.who-not-bind'));
return;
}
}
let diffOption;
if (options.d || options.m) {
diffOption = {
difficulty: (0, converter_1.convertDiff)(options.d),
mode: options.m
};
}
const score = await api.BeatLeader.wrapperResult().getScoreByPlayerIdAndMapId(accountId, mapId, diffOption);
if (!score.isSuccess()) {
session.sendQuote(session.text('commands.bsbot.score.score-not-found', { user: accountId, id: mapId }));
}
const img = await render.renderScore(score.data.id.toString(), platform, onStartRender);
session.sendQueued(img);
});
return {
key: 'score',
cmd: scoreCmd
};
}
exports.ScoreCmd = ScoreCmd;