onebots
Version:
基于icqq的多例oneBot实现
136 lines (135 loc) • 4.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonAction = void 0;
const onebot_1 = require("../../../onebot");
class CommonAction {
/**
* 获取登录信息
*/
getLoginInfo() {
return {
user_id: this.oneBot.uin,
nickname: this.adapter.getSelfInfo(this.oneBot.uin, "V11").nickname,
};
}
/**
* 撤回消息
* @param message_id {string} 消息id
*/
async deleteMsg(message_id) {
if (message_id == 0)
throw new Error("getMsg: message_id[0] is invalid");
const msg_id = this.getStrByInt("message_id", message_id);
return this.adapter.call(this.oneBot.uin, "V11", "deleteMessage", [
this.oneBot.uin,
msg_id,
]);
}
/**
* 获取消息
* @param message_id {string} 消息id
* @param onebot_id {number}
*/
async getMsg(message_id) {
const msg_id = this.getStrByInt("message_id", message_id);
let msg = await this.adapter.call(this.oneBot.uin, "V11", "getMessage", [
msg_id,
]);
msg.message_id = message_id; // nonebot v11 要求 message_id 是 number 类型
msg["real_id"] = msg.message_id; // nonebot 的reply类型会检测real_id是否存在,虽然它从未使用
return msg;
}
/**
* 获取合并消息
* @param id {string} 合并id
*/
getForwardMsg(id) {
return this.adapter.call(this.oneBot.uin, "V11", "getForwardMsg", [id]);
}
/**
* 获取 Cookies
* @param domain {string} 域名
*/
getCookies(domain) {
return this.adapter.call["getCookies"]([domain]);
}
/**
* 获取 CSRF Token
*/
getCsrfToken() {
return this.adapter.call(this.oneBot.uin, "V11", "getCsrfToken");
}
/**
* 获取 QQ 相关接口凭证
* @param domain
*/
getCredentials(domain) {
return {
cookies: this.adapter.call(this.oneBot.uin, "V11", "getCookies", [domain]),
csrf_token: this.adapter.call(this.oneBot.uin, "V11", "getCsrfToken"),
};
}
/**
* 获取版本信息
*/
getVersion() {
return {
app_name: "icqq",
app_version: "2.x",
protocol_version: "v11",
};
}
/**
* 重启OneBot实现
* @param delay {number} 要延迟的毫秒数
*/
setRestart(delay) {
return this.emit("restart", delay);
}
getStatus() {
return {
online: this.oneBot.status === onebot_1.OneBotStatus.Online,
good: this.oneBot.app.isStarted,
};
}
async submitSlider(ticket) {
return this.adapter.call(this.oneBot.uin, "V11", "callLogin", ["submitSlider", ticket]);
}
async submitSmsCode(code) {
return this.adapter.call(this.oneBot.uin, "V11", "callLogin", ["submitSmsCode", code]);
}
callApi(name, args) {
return this.adapter.call(this.oneBot.uin, "V11", "callApi", [name, args]);
}
login(password) {
return this.adapter.call(this.oneBot.uin, "V11", "callLogin", ["login", password]);
}
logout(keepalive) {
return this.adapter.call(this.oneBot.uin, "V11", "logout", [keepalive]);
}
/**
* 上传富媒体
* @param this
* @param target_id 目标id
* @param target_type {group|user} 目标类型
* @param file_data 文件base64或文件网络url
* @param file_type {1|2|3} 文件类型 1:图片 2:视频 3:音频
*/
async uploadMedia(target_id, target_type, file_data, file_type) {
const real_id = this.getStrByInt(`${target_type}_id`, target_id);
return this.adapter.call(this.oneBot.uin, "V11", "uploadMedia", [
real_id,
target_type,
file_data,
file_type,
]);
}
getForumUrl(guild_id, channel_id, forum_id) {
return this.adapter.call(this.oneBot.uin, "V12", "getForumUrl", [
guild_id,
channel_id,
forum_id,
]);
}
}
exports.CommonAction = CommonAction;