UNPKG

koishi-plugin-beatsaber-bot

Version:

一个 用于 BeatSaber 的 koishi Bot 插件

71 lines (70 loc) 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MeCmd = void 0; const converter_1 = require("../utils/converter"); const db_1 = require("../service/db/db"); const types_1 = require("../types"); function MeCmd(ctx, cfg, render, api, logger) { const meCmd = ctx .command('bsbot.me [mapId:string]') .userFields(['id']) .alias('bbme') .alias('bbmess', { options: { p: "ss" } }) .alias('bbmebl', { options: { p: "bl" } }) .alias('ssme', { options: { p: "ss" } }) .alias('blme', { options: { p: "bl" } }) .alias('!ws', { options: { p: "ss" } }) .alias('!wb', { options: { p: "bl" } }) .alias('iws', { options: { p: "ss" } }) .alias('iwb', { options: { p: "bl" } }) .alias('!wss', { options: { p: "ss" } }) .alias('!wbl', { options: { p: "bl" } }) .alias('iwss', { options: { p: "ss" } }) .alias('iwbl', { options: { p: "bl" } }) .option('p', '[platform:string]') .option('d', '[diffculty:string]') .option('m', '[mode:string]') .action(async ({ session, options }, input) => { let rankPlatform = options.p == 'ss' ? types_1.Platform.SS : types_1.Platform.BL; const { blAccount, ssAccount } = await (0, db_1.getUserBSAccountInfo)(ctx, session.user.id); let accountId; if (rankPlatform == types_1.Platform.BL && blAccount) { accountId = blAccount.platformUid; } else if (rankPlatform == types_1.Platform.SS && ssAccount) { accountId = ssAccount.platformUid; } else { session.sendQuote(session.text('commands.bsbot.me.not-found')); return; } let onStartRender = () => { session.send(session.text('common.render.wait', { sec: cfg.rankWaitTimeout / 1000 })); }; if (input && input !== "") { // todo improve diff opts let diffOption; if (options.d || options.m) { diffOption = { difficulty: (0, converter_1.convertDiff)(options.d), mode: options.m }; } const scoreReq = await api.BeatLeader.wrapperResult().getScoreByPlayerIdAndMapId(accountId, input, diffOption); if (!scoreReq.isSuccess()) { return session.text('commands.bsbot.me.score-not-found', { user: accountId, id: input }); } const img = await render.renderScore(scoreReq.data.id.toString(), rankPlatform, onStartRender); session.sendQueued(img); } else { const img = await render.renderRank(accountId, rankPlatform, onStartRender); session.sendQueued(img); } }); return { key: 'me', cmd: meCmd }; } exports.MeCmd = MeCmd;