UNPKG

onebots

Version:

基于icqq的多例oneBot实现

147 lines (146 loc) 4.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommonAction = void 0; const utils_1 = require("../../../utils"); const utils_2 = require("../../../utils"); const crypto_1 = require("crypto"); const sha = data => (0, crypto_1.createHash)("sha1").update(data).digest(); class CommonAction { sendMessage() { } /** * 撤回消息 * @param message_id {string} 消息id */ deleteMessage(message_id) { return this.adapter.call(this.oneBot.uin, "V12", "deleteMsg", [message_id]); } /** * 获取消息详情 */ async getMessage(message_id) { const message = await this.adapter.call(this.oneBot.uin, "V12", "getMessage", [message_id]); if (!message) throw new Error("消息不存在"); return message; } getSelfInfo() { return { user_id: this.oneBot.uin + "", platform: "qq", nickname: this.adapter.getSelfInfo(this.oneBot.uin, "V12").nickname, user_displayname: "", }; } /** * 获取 Cookies * @param domain {string} 域名 */ async getCookies(domain) { return await this.adapter.call(this.oneBot.uin, "V12", "getCookies", [domain]); } getStatus() { return { good: this.oneBot.app.isStarted, bots: [ { self: this.action.getSelfInfo.apply(this), good: this.oneBot.app.isStarted, }, ], }; } getLatestEvents(limit = 0, timout = 0) { return new Promise(resolve => { if (!this.history.length && timout !== 0) { return setTimeout(() => resolve(this.action.getLatestEvents.apply(this, [limit, timout])), timout * 1000); } return resolve(this.history.reverse().filter((_, i) => (limit === 0 ? true : i < limit))); }); } getVersion() { return { impl: "onebots", platform: "qq", version: utils_1.version, onebot_version: "12", }; } async submitSlider(ticket) { return this.adapter.call(this.oneBot.uin, "V12", "callLogin", ["submitSlider", ticket]); } async submitSmsCode(code) { return this.action.callLogin.apply(this, ["submitSmsCode", code]); } login(password) { return this.adapter.call(this.oneBot.uin, "V12", "callLogin", ["login", password]); } getSupportedActions() { return [...new Set((0, utils_2.getProperties)(this.action))] .filter(key => { return key !== "constructor"; }) .map(utils_2.toLine); } uploadFile(type, name, url, path, data, sha256, headers) { const fileInfo = { name, url, type, path, data, sha256, headers, }; return this.saveFile(fileInfo); } uploadFileFragmented(stage, name, total_size, file_id, offset, data, sha256) { switch (stage) { case "prepare": { if (!name || !total_size) throw new Error("请输入name和total_size"); return this.saveFile({ name, type: "data", total_size, data: Buffer.alloc(0).toString("base64"), }); } case "transfer": { if (!file_id || !offset || !data) throw new Error("请输入file_id、offset和data"); const fileInfo = this.getFile(file_id); fileInfo.data = Buffer.concat([ Buffer.from(fileInfo.data), Buffer.from(data), ]).toString("base64"); return true; } case "finish": { if (!file_id || sha256) throw new Error("请输入file_id和sha256"); const fileInfo = this.getFile(file_id); if (sha(Buffer.from(fileInfo.data)).toString("hex") === sha256) return file_id; this.delFile(file_id); throw new Error("文件已被篡改"); } } } getFile(file_id) { return this.getFile(file_id); } sendLike(user_id, times = 1) { return this.adapter.call(this.oneBot.uin, "V12", "sendLike", [user_id, times]); } getForumUrl(guild_id, channel_id, forum_id) { return this.adapter.call(this.oneBot.uin, "V12", "getForumUrl", [ guild_id, channel_id, forum_id, ]); } imageOcr(file) { return this.adapter.call(this.oneBot.uin, "V12", "imageOcr", [file]); } } exports.CommonAction = CommonAction;