UNPKG

koishi-plugin-beatsaber-bot

Version:

一个 用于 BeatSaber 的 koishi Bot 插件

147 lines (146 loc) 5.33 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.apply = exports.inject = exports.name = void 0; const koishi_1 = require("koishi"); const cmd_1 = __importStar(require("./cmd")); const schedules_1 = __importDefault(require("./schedules")); const ws_1 = require("./ws"); const renderImg_1 = require("./service/img-render/renderImg"); __exportStar(require("./config"), exports); exports.name = 'bs-bot'; exports.inject = ['database', 'puppeteer', 'cron']; function pluginInit(ctx, config) { const zhLocal = require('./locales/zh-CN'); ctx.i18n.define('zh-CN', zhLocal); ctx.model.extend('BSBotSubscribe', { id: 'unsigned', uid: 'string', channelId: 'string', selfId: 'string', platform: 'string', enable: 'boolean', type: 'string', data: 'json' }, { autoInc: true }); ctx.model.extend('BSRelateOAuthAccount', { id: 'unsigned', uid: 'unsigned', platform: 'string', platformUid: 'string', platformScope: 'string', platformUname: 'string', otherPlatformInfo: 'json', accessToken: 'string', refreshToken: 'string', lastModifiedAt: 'timestamp', lastRefreshAt: 'timestamp', type: 'string', valid: 'string' }, { autoInc: true }); ctx.model.extend('BSSubscribeMember', { id: 'unsigned', subscribeId: 'unsigned', memberUid: 'unsigned', subscribeData: 'json', joinedAt: 'date', }, { autoInc: true }); } function apply(ctx, config) { pluginInit(ctx, config); pluginCmd(ctx, config); // pluginWebSocket(ctx,config) ctx.on('reaction-added', async (session) => { console.log('recv'); }); ctx.on('friend-request', async (session) => { console.log("friend-request"); await session.bot.handleFriendRequest(session.messageId, true); session.send(session.text('common.hello')); console.log("finished"); }); ctx.on('guild-request', async (param) => { console.log(param); }); } exports.apply = apply; async function sendTmpHit(ctx, session) { const buf = await (0, renderImg_1.screenshotTmp)(ctx.puppeteer, 'https://aiobs.ktlab.io/tmp/lb/hitcnt', '#render-result', () => { session.sendQueued((0, koishi_1.h)('message', [ "开始渲染砍击榜了,请耐心等待 10s" ])); }, 8000); const hitmsg = koishi_1.h.image(buf, 'image/png'); session.sendQueued(hitmsg); } async function sendTmpScore(ctx, session) { const buf = await (0, renderImg_1.screenshotTmp)(ctx.puppeteer, 'https://aiobs.ktlab.io/tmp/lb/score', '#render-result', () => { session.sendQueued((0, koishi_1.h)('message', [ "开始渲染打分榜了,请耐心等待 10s" ])); }, 8000); const scoremsg = koishi_1.h.image(buf, 'image/png'); session.sendQueued(scoremsg); } function pluginCmd(ctx, config) { const cmd = new cmd_1.default(ctx, config); ctx.command('bsbot.tmplb') .alias('bblb') .action(async ({ session }) => { await Promise.all([sendTmpHit(ctx, session), sendTmpScore(ctx, session)]); }); ctx.command('bsbot <prompt:string>') .alias('bb') .action(async ({ session, options }, input) => { session.send(input); }); cmd .apply(cmd_1.KeySearchCmd) .apply(cmd_1.IdSearchCmd) .apply(cmd_1.LatestCmd) .apply(cmd_1.BindCmd) .apply(cmd_1.RankCmd) .apply(cmd_1.MeCmd) .apply(cmd_1.WhoisCmd) .apply(cmd_1.HelpCmd) .apply(cmd_1.CmpCmd) .apply(cmd_1.ScoreCmd) .apply(cmd_1.SubscribeCmd) .apply(cmd_1.UnSubscribeCmd) .apply(cmd_1.JoinSubscribeCmd) .apply(cmd_1.LeaveSubscribeCmd); (0, schedules_1.default)(ctx, config); (0, ws_1.pluginWS)(ctx, config); }