UNPKG

@kokkoro/web

Version:

Create web serve for kokkoro.

64 lines (63 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@kokkoro/core"); const app_1 = require("../app"); class BotService { getBotList() { const botList = (0, core_1.getBotList)(); const infos = []; botList.forEach((bot) => { const { config, uin, nickname, sex, age, tiny_id, password } = bot; const element = { online: bot.isOnline(), uin, nickname, sex, age, tiny_id, config, password, }; infos.push(element); }); return infos; } getBot(uin) { const botList = (0, core_1.getBotList)(); const bot = botList.get(uin); if (!bot) { throw new app_1.SourceError(403, '不存在该实例'); } return bot; } async loginBot(uin) { const bot = this.getBot(uin); const result = await bot.linkStart(); return result; } logoutBot(uin) { const bot = this.getBot(uin); return bot.logout(); } queryQrcodeResult(uin) { const bot = this.getBot(uin); return bot.queryQrcodeResult(); } getFriendList(uin) { const bot = this.getBot(uin); return { list: bot.fl, }; } getGroupList(uin) { const bot = this.getBot(uin); return { list: bot.gl, }; } async sendPrivateMsg(uin, ...params) { const bot = this.getBot(uin); const result = await bot.sendPrivateMsg(...params); return result; } async sendGroupMsg(uin, ...params) { const bot = this.getBot(uin); const result = await bot.sendGroupMsg(...params); return result; } } exports.default = new BotService();