node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1029 -0
- package/default/comment/config.json +34 -0
- package/default/comment/friendDirect.json +10 -0
- package/default/comment/groupGuild.json +11 -0
- package/default/comment/server.json +17 -0
- package/default/config/adapter.json +28 -0
- package/default/config/config.json +47 -0
- package/default/config/groups.json +47 -0
- package/default/config/groups.yaml +70 -0
- package/default/config/pm2.json +16 -0
- package/default/config/privates.json +23 -0
- package/default/config/privates.yaml +31 -0
- package/default/config/redis.json +10 -0
- package/default/config/render.json +19 -0
- package/default/view/group.yaml +73 -0
- package/dist/index.d.ts +9869 -0
- package/dist/index.js +12643 -0
- package/dist/module/art-template.cjs +11 -0
- package/dist/module/art-template.d.ts +1 -0
- package/dist/module/axios.cjs +22 -0
- package/dist/module/axios.d.ts +2 -0
- package/dist/module/chalk.cjs +22 -0
- package/dist/module/chalk.d.ts +2 -0
- package/dist/module/chokidar.cjs +22 -0
- package/dist/module/chokidar.d.ts +2 -0
- package/dist/module/commander.cjs +35 -0
- package/dist/module/commander.d.ts +3 -0
- package/dist/module/commander.js +3 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/module/express.cjs +112 -0
- package/dist/module/express.d.ts +1 -0
- package/dist/module/express.js +1 -0
- package/dist/module/level.cjs +22 -0
- package/dist/module/level.d.ts +2 -0
- package/dist/module/lodash.cjs +11 -0
- package/dist/module/lodash.d.ts +1 -0
- package/dist/module/log4js.cjs +22 -0
- package/dist/module/log4js.d.ts +2 -0
- package/dist/module/moment.cjs +11 -0
- package/dist/module/moment.d.ts +1 -0
- package/dist/module/node-schedule.cjs +22 -0
- package/dist/module/node-schedule.d.ts +2 -0
- package/dist/module/redis.cjs +22 -0
- package/dist/module/redis.d.ts +2 -0
- package/dist/module/ws.cjs +28 -0
- package/dist/module/ws.d.ts +1 -0
- package/dist/module/ws.js +1 -0
- package/dist/module/yaml.cjs +22 -0
- package/dist/module/yaml.d.ts +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +142 -128
- package/LICENSE +0 -674
- package/README.md +0 -56
- package/config/defSet/App.yaml +0 -42
- package/config/defSet/config.yaml +0 -65
- package/config/defSet/group.yaml +0 -56
- package/config/defSet/pm2.yaml +0 -21
- package/config/defSet/redis.yaml +0 -18
- package/config/defSet/server.yaml +0 -42
- package/config/view/group.yaml +0 -92
- package/lib/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.d.ts +0 -78
- package/lib/adapter/input/index.js +0 -205
- package/lib/adapter/onebot/11/convert.d.ts +0 -12
- package/lib/adapter/onebot/11/convert.js +0 -167
- package/lib/adapter/onebot/11/event.d.ts +0 -25
- package/lib/adapter/onebot/11/event.js +0 -442
- package/lib/adapter/onebot/11/index.d.ts +0 -508
- package/lib/adapter/onebot/11/index.js +0 -1047
- package/lib/cli/index.d.ts +0 -92
- package/lib/cli/index.js +0 -307
- package/lib/cli/init.d.ts +0 -2
- package/lib/cli/init.js +0 -22
- package/lib/cli/karin.d.ts +0 -2
- package/lib/cli/karin.js +0 -16
- package/lib/cli/pkg.d.ts +0 -4
- package/lib/cli/pkg.js +0 -14
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +0 -8
- package/lib/core/index.d.ts +0 -10
- package/lib/core/index.js +0 -10
- package/lib/core/init/config.d.ts +0 -43
- package/lib/core/init/config.js +0 -201
- package/lib/core/init/dir.d.ts +0 -4
- package/lib/core/init/dir.js +0 -7
- package/lib/core/init/init.d.ts +0 -1
- package/lib/core/init/init.js +0 -47
- package/lib/core/karin/karin.d.ts +0 -198
- package/lib/core/karin/karin.js +0 -226
- package/lib/core/listener/listener.d.ts +0 -145
- package/lib/core/listener/listener.js +0 -235
- package/lib/core/plugin/base.d.ts +0 -156
- package/lib/core/plugin/base.js +0 -131
- package/lib/core/plugin/loader.d.ts +0 -141
- package/lib/core/plugin/loader.js +0 -618
- package/lib/core/process/process.d.ts +0 -18
- package/lib/core/process/process.js +0 -96
- package/lib/core/server/server.d.ts +0 -25
- package/lib/core/server/server.js +0 -295
- package/lib/db/index.d.ts +0 -2
- package/lib/db/index.js +0 -2
- package/lib/db/level/level.d.ts +0 -19
- package/lib/db/level/level.js +0 -36
- package/lib/db/redis/redis.d.ts +0 -2
- package/lib/db/redis/redis.js +0 -135
- package/lib/db/redis/redis_level.d.ts +0 -112
- package/lib/db/redis/redis_level.js +0 -281
- package/lib/event/handler/base.d.ts +0 -42
- package/lib/event/handler/base.js +0 -200
- package/lib/event/handler/message.d.ts +0 -29
- package/lib/event/handler/message.js +0 -307
- package/lib/event/handler/notice.d.ts +0 -18
- package/lib/event/handler/notice.js +0 -214
- package/lib/event/handler/request.d.ts +0 -18
- package/lib/event/handler/request.js +0 -115
- package/lib/event/handler/review.d.ts +0 -55
- package/lib/event/handler/review.js +0 -386
- package/lib/event/index.d.ts +0 -5
- package/lib/event/index.js +0 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -8
- package/lib/modules/art-template.d.ts +0 -1
- package/lib/modules/axios.d.ts +0 -2
- package/lib/modules/chalk.d.ts +0 -2
- package/lib/modules/chokidar.d.ts +0 -2
- package/lib/modules/commander.d.ts +0 -2
- package/lib/modules/commander.js +0 -2
- package/lib/modules/express.d.ts +0 -3
- package/lib/modules/express.js +0 -3
- package/lib/modules/level.d.ts +0 -2
- package/lib/modules/lodash.d.ts +0 -1
- package/lib/modules/log4js.d.ts +0 -2
- package/lib/modules/moment.d.ts +0 -1
- package/lib/modules/node-schedule.d.ts +0 -2
- package/lib/modules/redis.d.ts +0 -2
- package/lib/modules/ws.d.ts +0 -3
- package/lib/modules/ws.js +0 -3
- package/lib/modules/yaml.d.ts +0 -2
- package/lib/modules.d.ts +0 -15
- package/lib/modules.js +0 -15
- package/lib/render/app.d.ts +0 -56
- package/lib/render/app.js +0 -120
- package/lib/render/base.d.ts +0 -30
- package/lib/render/base.js +0 -69
- package/lib/render/client.d.ts +0 -41
- package/lib/render/client.js +0 -238
- package/lib/render/http.d.ts +0 -19
- package/lib/render/http.js +0 -50
- package/lib/render/index.d.ts +0 -6
- package/lib/render/index.js +0 -6
- package/lib/render/server.d.ts +0 -25
- package/lib/render/server.js +0 -101
- package/lib/render/wormhole.d.ts +0 -1
- package/lib/render/wormhole.js +0 -156
- package/lib/types/adapter/api.d.ts +0 -399
- package/lib/types/adapter/api.js +0 -1
- package/lib/types/adapter/base.d.ts +0 -560
- package/lib/types/adapter/base.js +0 -1
- package/lib/types/config/config.d.ts +0 -379
- package/lib/types/config/config.js +0 -1
- package/lib/types/element/element.d.ts +0 -565
- package/lib/types/element/element.js +0 -1
- package/lib/types/element/qqbot.d.ts +0 -123
- package/lib/types/element/qqbot.js +0 -1
- package/lib/types/event/contact.d.ts +0 -28
- package/lib/types/event/contact.js +0 -1
- package/lib/types/event/event.d.ts +0 -305
- package/lib/types/event/event.js +0 -1
- package/lib/types/event/index.d.ts +0 -12
- package/lib/types/event/index.js +0 -7
- package/lib/types/event/message.d.ts +0 -109
- package/lib/types/event/message.js +0 -74
- package/lib/types/event/notice.d.ts +0 -513
- package/lib/types/event/notice.js +0 -52
- package/lib/types/event/reply.d.ts +0 -50
- package/lib/types/event/reply.js +0 -1
- package/lib/types/event/request.d.ts +0 -126
- package/lib/types/event/request.js +0 -52
- package/lib/types/event/sender.d.ts +0 -44
- package/lib/types/event/sender.js +0 -1
- package/lib/types/index.d.ts +0 -13
- package/lib/types/index.js +0 -13
- package/lib/types/logger/logger.d.ts +0 -110
- package/lib/types/logger/logger.js +0 -1
- package/lib/types/onebot11/api.d.ts +0 -53
- package/lib/types/onebot11/api.js +0 -1
- package/lib/types/onebot11/event.d.ts +0 -619
- package/lib/types/onebot11/event.js +0 -2
- package/lib/types/onebot11/index.d.ts +0 -6
- package/lib/types/onebot11/index.js +0 -6
- package/lib/types/onebot11/params.d.ts +0 -609
- package/lib/types/onebot11/params.js +0 -1
- package/lib/types/onebot11/response.d.ts +0 -516
- package/lib/types/onebot11/response.js +0 -1
- package/lib/types/onebot11/segment.d.ts +0 -269
- package/lib/types/onebot11/segment.js +0 -1
- package/lib/types/onebot11/sender.d.ts +0 -59
- package/lib/types/onebot11/sender.js +0 -1
- package/lib/types/plugin/app.d.ts +0 -71
- package/lib/types/plugin/app.js +0 -1
- package/lib/types/plugin/plugin.d.ts +0 -473
- package/lib/types/plugin/plugin.js +0 -1
- package/lib/types/render/render.d.ts +0 -118
- package/lib/types/render/render.js +0 -1
- package/lib/types/type/global.d.ts +0 -25
- package/lib/types/type/global.js +0 -1
- package/lib/utils/common/common.d.ts +0 -236
- package/lib/utils/common/common.js +0 -708
- package/lib/utils/config/config.d.ts +0 -193
- package/lib/utils/config/config.js +0 -328
- package/lib/utils/config/updateVersion.d.ts +0 -33
- package/lib/utils/config/updateVersion.js +0 -145
- package/lib/utils/config/yamlEditor.d.ts +0 -101
- package/lib/utils/config/yamlEditor.js +0 -330
- package/lib/utils/core/handler.d.ts +0 -18
- package/lib/utils/core/handler.js +0 -46
- package/lib/utils/core/logger.d.ts +0 -3
- package/lib/utils/core/logger.js +0 -105
- package/lib/utils/core/segment.d.ts +0 -279
- package/lib/utils/core/segment.js +0 -451
- package/lib/utils/index.d.ts +0 -13
- package/lib/utils/index.js +0 -13
- package/lib/utils/tools/button.d.ts +0 -2
- package/lib/utils/tools/button.js +0 -27
- package/lib/utils/tools/exec.d.ts +0 -20
- package/lib/utils/tools/exec.js +0 -54
- package/lib/utils/tools/ffmpeg.d.ts +0 -12
- package/lib/utils/tools/ffmpeg.js +0 -25
- package/lib/utils/tools/restart.d.ts +0 -15
- package/lib/utils/tools/restart.js +0 -39
- package/lib/utils/tools/stop.d.ts +0 -7
- package/lib/utils/tools/stop.js +0 -13
- package/lib/utils/tools/update.d.ts +0 -67
- package/lib/utils/tools/update.js +0 -151
- /package/{config → default}/view/App.yaml +0 -0
- /package/{config → default}/view/config.yaml +0 -0
- /package/{config → default}/view/pm2.yaml +0 -0
- /package/{config → default}/view/redis.yaml +0 -0
- /package/{config → default}/view/server.yaml +0 -0
- /package/{lib/modules → dist/module}/art-template.js +0 -0
- /package/{lib/modules → dist/module}/axios.js +0 -0
- /package/{lib/modules → dist/module}/chalk.js +0 -0
- /package/{lib/modules → dist/module}/chokidar.js +0 -0
- /package/{lib/modules → dist/module}/level.js +0 -0
- /package/{lib/modules → dist/module}/lodash.js +0 -0
- /package/{lib/modules → dist/module}/log4js.js +0 -0
- /package/{lib/modules → dist/module}/moment.js +0 -0
- /package/{lib/modules → dist/module}/node-schedule.js +0 -0
- /package/{lib/modules → dist/module}/redis.js +0 -0
- /package/{lib/modules → dist/module}/yaml.js +0 -0
|
@@ -1,1047 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { randomUUID } from 'crypto';
|
|
3
|
-
import { karin } from '../../../core/karin/karin.js';
|
|
4
|
-
import { common, config, logger, segment } from '../../../utils/index.js';
|
|
5
|
-
import { OB11Event } from './event.js';
|
|
6
|
-
import { AdapterConvertKarin, KarinConvertAdapter } from './convert.js';
|
|
7
|
-
/**
|
|
8
|
-
* @class OneBot11
|
|
9
|
-
* @extends KarinAdapter
|
|
10
|
-
*/
|
|
11
|
-
export class AdapterOneBot11 {
|
|
12
|
-
/**
|
|
13
|
-
* - 重连次数 仅正向ws使用
|
|
14
|
-
*/
|
|
15
|
-
index;
|
|
16
|
-
socket;
|
|
17
|
-
account;
|
|
18
|
-
adapter;
|
|
19
|
-
version;
|
|
20
|
-
constructor() {
|
|
21
|
-
this.index = 0;
|
|
22
|
-
this.account = { uid: '', uin: '', name: '' };
|
|
23
|
-
this.adapter = { id: 'QQ', name: 'OneBot11', type: 'ws', sub_type: 'internal', start_time: Date.now(), connect: '', index: 0 };
|
|
24
|
-
this.version = { name: '', app_name: '', version: '' };
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 反向ws初始化
|
|
28
|
-
*/
|
|
29
|
-
async server(socket, request) {
|
|
30
|
-
this.socket = socket;
|
|
31
|
-
const self_id = String(request.headers['x-self-id']);
|
|
32
|
-
const connect = 'ws://' + request.headers.host + request.url;
|
|
33
|
-
this.account.uin = self_id;
|
|
34
|
-
this.account.uid = self_id;
|
|
35
|
-
this.adapter.connect = connect;
|
|
36
|
-
this.adapter.sub_type = 'server';
|
|
37
|
-
this.logger('info', `[反向WS][onebot11-${request.headers.upgrade}][${self_id}] ` + logger.green(connect));
|
|
38
|
-
await this.#initListener(connect);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* 正向ws初始化
|
|
42
|
-
* @param connect - WebSocket连接地址
|
|
43
|
-
*/
|
|
44
|
-
async client(connect) {
|
|
45
|
-
/** 创建连接 */
|
|
46
|
-
this.socket = new WebSocket(connect);
|
|
47
|
-
this.socket.on('open', async () => {
|
|
48
|
-
this.adapter.sub_type = 'client';
|
|
49
|
-
this.adapter.connect = connect;
|
|
50
|
-
logger.info('[正向WS][连接成功][onebot11] ' + logger.green(connect));
|
|
51
|
-
this.index = 0;
|
|
52
|
-
this.#initListener(connect);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
init(data) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 初始化监听事件
|
|
60
|
-
* @param connect - WebSocket连接地址
|
|
61
|
-
*/
|
|
62
|
-
async #initListener(connect) {
|
|
63
|
-
/** 监听事件 */
|
|
64
|
-
this.socket.on('message', data => {
|
|
65
|
-
this.logger('debug', `[收到事件]:${data}`);
|
|
66
|
-
const event = data.toString().trim() || '{"post_type":"error","error":"空事件"}';
|
|
67
|
-
const json = JSON.parse(event);
|
|
68
|
-
if (json.echo)
|
|
69
|
-
return this.socket.emit(json.echo, json);
|
|
70
|
-
return this.init(json);
|
|
71
|
-
});
|
|
72
|
-
/** 监听错误 */
|
|
73
|
-
this.socket.on('error', error => {
|
|
74
|
-
this.logger('debug', '[正向WS] 发生错误', error);
|
|
75
|
-
});
|
|
76
|
-
/** 监听断开 */
|
|
77
|
-
this.socket.once('close', async () => {
|
|
78
|
-
const type = this.adapter.sub_type === 'server' ? '反向WS' : '正向WS';
|
|
79
|
-
this.logger('warn', `[${type}] 连接断开:${connect}`);
|
|
80
|
-
/** 停止全部监听 */
|
|
81
|
-
this.socket.removeAllListeners();
|
|
82
|
-
/** 注销bot */
|
|
83
|
-
this.adapter.index && karin.delBot(this.adapter.index);
|
|
84
|
-
/** 正向ws需要重连 */
|
|
85
|
-
if (this.adapter.sub_type === 'client') {
|
|
86
|
-
this.index++;
|
|
87
|
-
this.logger('warn', `[正向WS][重连次数:${this.index}] 连接断开,将在5秒后重连:${connect}`);
|
|
88
|
-
await common.sleep(5000);
|
|
89
|
-
this.client(connect);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
await this.getSelf();
|
|
93
|
-
this.init = (data) => {
|
|
94
|
-
new OB11Event(this).event(data);
|
|
95
|
-
return true;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
get self_id() {
|
|
99
|
-
return this.account.uid || this.account.uin;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 获取当前登录号信息
|
|
103
|
-
*/
|
|
104
|
-
async getSelf() {
|
|
105
|
-
const data = await this.GetCurrentAccount();
|
|
106
|
-
try {
|
|
107
|
-
const { app_name, version } = await this.GetVersion();
|
|
108
|
-
this.version.name = app_name;
|
|
109
|
-
this.version.app_name = app_name;
|
|
110
|
-
this.version.version = version;
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
/** 兼容onebots */
|
|
114
|
-
const { app_name, version } = await this.SendApi("get_version" /* OB11Api['get_version'] */);
|
|
115
|
-
this.version.name = app_name;
|
|
116
|
-
this.version.app_name = app_name;
|
|
117
|
-
this.version.version = version;
|
|
118
|
-
}
|
|
119
|
-
this.account.uid = data.account_uid;
|
|
120
|
-
this.account.uin = data.account_uin;
|
|
121
|
-
this.account.name = data.account_name;
|
|
122
|
-
this.logger('info', `[加载完成][app_name:${this.version.name}][version:${this.version.version}] ` + logger.green(this.adapter.connect));
|
|
123
|
-
/** 注册bot */
|
|
124
|
-
const index = karin.addBot({ type: this.adapter.type, bot: this });
|
|
125
|
-
if (index)
|
|
126
|
-
this.adapter.index = index;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* onebot11转karin
|
|
130
|
-
* @return karin格式消息
|
|
131
|
-
*/
|
|
132
|
-
AdapterConvertKarin(data) {
|
|
133
|
-
return AdapterConvertKarin(data);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* karin转onebot11
|
|
137
|
-
* @param data karin格式消息
|
|
138
|
-
*/
|
|
139
|
-
KarinConvertAdapter(data) {
|
|
140
|
-
return KarinConvertAdapter(data, this);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* 专属当前Bot的日志打印方法
|
|
144
|
-
*/
|
|
145
|
-
logger(level, ...args) {
|
|
146
|
-
logger.bot(level, this.account.uid || this.account.uin, ...args);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 获取头像url
|
|
150
|
-
* @param 头像大小,默认`0`
|
|
151
|
-
* @param 用户qq,默认为机器人QQ
|
|
152
|
-
* @returns 头像的url地址
|
|
153
|
-
*/
|
|
154
|
-
getAvatarUrl(uid = this.account.uid || this.account.uin, size = 0) {
|
|
155
|
-
return Number(uid) ? `https://q1.qlogo.cn/g?b=qq&s=${size}&nk=${uid}` : `https://q.qlogo.cn/qqapp/${uid}/${uid}/${size}`;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 获取群头像
|
|
159
|
-
* @param group_id - 群号
|
|
160
|
-
* @param size - 头像大小,默认`0`
|
|
161
|
-
* @param history - 历史头像记录,默认`0`,若要获取历史群头像则填写1,2,3...
|
|
162
|
-
* @returns - 群头像的url地址
|
|
163
|
-
*/
|
|
164
|
-
getGroupAvatarUrl(group_id, size = 0, history = 0) {
|
|
165
|
-
return `https://p.qlogo.cn/gh/${group_id}/${group_id}${history ? '_' + history : ''}/` + size;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* 发送消息
|
|
169
|
-
*
|
|
170
|
-
* @param contact
|
|
171
|
-
* @param elements
|
|
172
|
-
* @returns - 消息ID
|
|
173
|
-
*/
|
|
174
|
-
async SendMessage(contact, elements) {
|
|
175
|
-
const { scene, peer } = contact;
|
|
176
|
-
let res;
|
|
177
|
-
if (scene === "group" /* Scene.Group */) {
|
|
178
|
-
res = await this.SendApi("send_msg" /* OB11Api['send_msg'] */, {
|
|
179
|
-
message_type: "group" /* MessageType.Group */,
|
|
180
|
-
group_id: Number(peer),
|
|
181
|
-
message: this.KarinConvertAdapter(elements),
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
res = await this.SendApi("send_msg" /* OB11Api['send_msg'] */, {
|
|
186
|
-
message_type: "private" /* MessageType.Private */,
|
|
187
|
-
user_id: Number(peer),
|
|
188
|
-
message: this.KarinConvertAdapter(elements),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return { message_id: String(res.message_id), message_time: Date.now() };
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* 上传合并转发消息
|
|
195
|
-
* @param contact - 联系人信息
|
|
196
|
-
* @param elements - nodes
|
|
197
|
-
* @returns - 资源id
|
|
198
|
-
*/
|
|
199
|
-
async UploadForwardMessage(contact, elements) {
|
|
200
|
-
if (!Array.isArray(elements))
|
|
201
|
-
elements = [elements];
|
|
202
|
-
if (elements.some((element) => element.type !== 'node')) {
|
|
203
|
-
throw new Error('elements should be all node type');
|
|
204
|
-
}
|
|
205
|
-
const { scene, peer } = contact;
|
|
206
|
-
const message_type = scene === 'group' ? 'group_id' : 'user_id';
|
|
207
|
-
const messages = [];
|
|
208
|
-
const selfUin = this.account.uin;
|
|
209
|
-
const selfNick = this.account.name;
|
|
210
|
-
for (const i of elements) {
|
|
211
|
-
const type = 'node';
|
|
212
|
-
if (i.id) {
|
|
213
|
-
messages.push({ type, data: { id: i.id } });
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
const content = this.KarinConvertAdapter(i.content);
|
|
217
|
-
const user_id = String(i.user_id || selfUin);
|
|
218
|
-
const nickname = String(i.nickname || selfNick);
|
|
219
|
-
messages.push({ type, data: { user_id, nickname, content } });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const params = { [message_type]: String(peer), messages };
|
|
223
|
-
return await this.SendApi("send_forward_msg" /* OB11Api['send_forward_msg'] */, params);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* 通过资源id发送转发消息
|
|
227
|
-
* @param contact - 联系人信息
|
|
228
|
-
* @param id - 资源id
|
|
229
|
-
*/
|
|
230
|
-
async SendMessageByResId(contact, id) {
|
|
231
|
-
let res;
|
|
232
|
-
const { scene, peer } = contact;
|
|
233
|
-
if (scene === "group" /* Scene.Group */) {
|
|
234
|
-
res = await this.SendApi("send_msg" /* OB11Api['send_msg'] */, {
|
|
235
|
-
message_type: "group" /* MessageType.Group */,
|
|
236
|
-
group_id: Number(peer),
|
|
237
|
-
message: [{ type: "forward" /* OB11SegmentType.Forward */, data: { id } }],
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
res = await this.SendApi("send_msg" /* OB11Api['send_msg'] */, {
|
|
242
|
-
message_type: "private" /* MessageType.Private */,
|
|
243
|
-
user_id: Number(peer),
|
|
244
|
-
message: [{ type: "forward" /* OB11SegmentType.Forward */, data: { id } }],
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
return { message_id: String(res.message_id), message_time: Date.now() };
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* 撤回消息
|
|
251
|
-
* @param _contact - ob11无需提供contact参数
|
|
252
|
-
* @param message_id - 消息ID
|
|
253
|
-
*/
|
|
254
|
-
async RecallMessage(_contact, message_id) {
|
|
255
|
-
try {
|
|
256
|
-
await this.SendApi("delete_msg" /* OB11Api['delete_msg'] */, { message_id: Number(message_id) });
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* 获取消息
|
|
265
|
-
* @param contact - 联系人信息
|
|
266
|
-
* @param message_id - 消息ID
|
|
267
|
-
*/
|
|
268
|
-
async GetMessage(contact, message_id) {
|
|
269
|
-
const res = await this.SendApi("get_msg" /* OB11Api['get_msg'] */, { message_id: Number(message_id) });
|
|
270
|
-
return {
|
|
271
|
-
time: res.time,
|
|
272
|
-
message_id: res.message_id + '',
|
|
273
|
-
message_seq: res.message_id,
|
|
274
|
-
contact: {
|
|
275
|
-
scene: res.message_type === 'group' ? "group" /* Scene.Group */ : "friend" /* Scene.Private */,
|
|
276
|
-
peer: contact.peer, // 这里可能不准确 传入是什么就返回什么
|
|
277
|
-
},
|
|
278
|
-
sender: {
|
|
279
|
-
uid: res.sender.user_id,
|
|
280
|
-
uin: res.sender.user_id,
|
|
281
|
-
nick: res.sender.nickname,
|
|
282
|
-
role: "unknown" /* Role.Unknown */,
|
|
283
|
-
},
|
|
284
|
-
elements: this.AdapterConvertKarin(res.message),
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* 获取msg_id获取历史消息
|
|
289
|
-
* @description 此api各平台实现不同
|
|
290
|
-
*/
|
|
291
|
-
async GetHistoryMessage(contact, start_message_id, count = 1) {
|
|
292
|
-
const message_seq = (await this.GetMessage(contact, start_message_id)).message_seq;
|
|
293
|
-
// 先拿到消息的seq
|
|
294
|
-
let options;
|
|
295
|
-
if (this.version.name === 'Lagrange.OneBot') {
|
|
296
|
-
options = { message_id: Number(start_message_id), message_count: count };
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
options = { message_seq, message_count: count };
|
|
300
|
-
}
|
|
301
|
-
let res;
|
|
302
|
-
if (contact.scene === 'group') {
|
|
303
|
-
options.group_id = Number(contact.peer);
|
|
304
|
-
res = await this.SendApi("get_group_msg_history" /* OB11Api['get_group_msg_history'] */, options);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
options.user_id = Number(contact.peer);
|
|
308
|
-
res = await this.SendApi("get_friend_msg_history" /* OB11Api['get_friend_msg_history'] */, options);
|
|
309
|
-
}
|
|
310
|
-
const all = [];
|
|
311
|
-
const elements = this.AdapterConvertKarin(res);
|
|
312
|
-
const scene = contact.scene === 'group' ? "group" /* Scene.Group */ : "friend" /* Scene.Private */;
|
|
313
|
-
for (const v of elements) {
|
|
314
|
-
all.push({
|
|
315
|
-
time: Date.now(),
|
|
316
|
-
message_id: '',
|
|
317
|
-
message_seq: 0,
|
|
318
|
-
contact: {
|
|
319
|
-
scene,
|
|
320
|
-
peer: '',
|
|
321
|
-
sub_peer: '',
|
|
322
|
-
},
|
|
323
|
-
sender: {
|
|
324
|
-
uid: '',
|
|
325
|
-
uin: '',
|
|
326
|
-
nick: '',
|
|
327
|
-
role: "unknown" /* Role.Unknown */,
|
|
328
|
-
},
|
|
329
|
-
elements: [v],
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
return all;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* 发送好友赞
|
|
336
|
-
* @param target_uid_or_uin - 用户ID
|
|
337
|
-
* @param vote_count - 赞的次数,默认为`10`
|
|
338
|
-
*/
|
|
339
|
-
async VoteUser(target_uid_or_uin, vote_count = 10) {
|
|
340
|
-
const user_id = Number(target_uid_or_uin);
|
|
341
|
-
try {
|
|
342
|
-
await this.SendApi("send_like" /* OB11Api['send_like'] */, { user_id, times: vote_count });
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
catch {
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* 群组踢人
|
|
351
|
-
*/
|
|
352
|
-
async KickMember(group_id, target_uid_or_uin, reject_add_request = false, kick_reason = '') {
|
|
353
|
-
const user_id = Number(target_uid_or_uin);
|
|
354
|
-
try {
|
|
355
|
-
await this.SendApi("set_group_kick" /* OB11Api['set_group_kick'] */, { group_id: Number(group_id), user_id, reject_add_request });
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
catch {
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* 禁言用户
|
|
364
|
-
* @param group_id - 群号
|
|
365
|
-
* @param target_uid_or_uin - 用户ID
|
|
366
|
-
* @param duration - 禁言时长,单位秒,0 表示取消禁言
|
|
367
|
-
*/
|
|
368
|
-
async BanMember(group_id, target_uid_or_uin, duration) {
|
|
369
|
-
const user_id = Number(target_uid_or_uin);
|
|
370
|
-
try {
|
|
371
|
-
await this.SendApi("set_group_ban" /* OB11Api['set_group_ban'] */, { group_id: Number(group_id), user_id, duration });
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
catch {
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* 群组全员禁言
|
|
380
|
-
* @param group_id - 群号
|
|
381
|
-
* @param is_ban - 是否全员禁言
|
|
382
|
-
*/
|
|
383
|
-
async SetGroupWholeBan(group_id, is_ban = true) {
|
|
384
|
-
try {
|
|
385
|
-
await this.SendApi("set_group_whole_ban" /* OB11Api['set_group_whole_ban'] */, { group_id: Number(group_id), enable: is_ban });
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
catch {
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* 设置群管理员
|
|
394
|
-
* @param group_id - 群号
|
|
395
|
-
* @param target_uid_or_uin - 目标用户ID
|
|
396
|
-
* @param is_admin - 是否设置为管理员
|
|
397
|
-
*/
|
|
398
|
-
async SetGroupAdmin(group_id, target_uid_or_uin, is_admin) {
|
|
399
|
-
try {
|
|
400
|
-
const user_id = Number(target_uid_or_uin);
|
|
401
|
-
await this.SendApi("set_group_admin" /* OB11Api['set_group_admin'] */, { group_id: Number(group_id), user_id, enable: is_admin });
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
catch {
|
|
405
|
-
return false;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* 修改群名片
|
|
410
|
-
* @param group_id - 群号
|
|
411
|
-
* @param target_uid_or_uin - 目标用户ID
|
|
412
|
-
* @param card - 新名片
|
|
413
|
-
*/
|
|
414
|
-
async ModifyMemberCard(group_id, target_uid_or_uin, card) {
|
|
415
|
-
try {
|
|
416
|
-
const user_id = Number(target_uid_or_uin);
|
|
417
|
-
await this.SendApi("set_group_card" /* OB11Api['set_group_card'] */, { group_id: Number(group_id), user_id, card });
|
|
418
|
-
return true;
|
|
419
|
-
}
|
|
420
|
-
catch {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* 设置群名
|
|
426
|
-
* @param group_id - 群号
|
|
427
|
-
* @param group_name - 新群名
|
|
428
|
-
*/
|
|
429
|
-
async ModifyGroupName(group_id, group_name) {
|
|
430
|
-
try {
|
|
431
|
-
await this.SendApi("set_group_name" /* OB11Api['set_group_name'] */, { group_id: Number(group_id), group_name });
|
|
432
|
-
return true;
|
|
433
|
-
}
|
|
434
|
-
catch {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* 退出群组
|
|
440
|
-
* @param group_id - 群号
|
|
441
|
-
* @param is_dismiss - 是否解散,如果登录号是群主,则仅在此项为 true 时能够解散
|
|
442
|
-
*/
|
|
443
|
-
async LeaveGroup(group_id, is_dismiss = false) {
|
|
444
|
-
try {
|
|
445
|
-
await this.SendApi("set_group_leave" /* OB11Api['set_group_leave'] */, { group_id: Number(group_id), is_dismiss });
|
|
446
|
-
}
|
|
447
|
-
catch {
|
|
448
|
-
return false;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* 设置群专属头衔
|
|
453
|
-
* @param group_id - 群号
|
|
454
|
-
* @param target_uid_or_uin - 目标用户ID
|
|
455
|
-
* @param special_title - 专属头衔
|
|
456
|
-
*/
|
|
457
|
-
async SetGroupUniqueTitle(group_id, target_uid_or_uin, unique_title) {
|
|
458
|
-
const user_id = Number(target_uid_or_uin);
|
|
459
|
-
const special_title = unique_title;
|
|
460
|
-
const duration = -1;
|
|
461
|
-
try {
|
|
462
|
-
await this.SendApi("set_group_special_title" /* OB11Api['set_group_special_title'] */, { group_id: Number(group_id), user_id, special_title, duration });
|
|
463
|
-
}
|
|
464
|
-
catch {
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* 获取登录号信息
|
|
470
|
-
*/
|
|
471
|
-
async GetCurrentAccount() {
|
|
472
|
-
const res = await this.SendApi("get_login_info" /* OB11Api['get_login_info'] */);
|
|
473
|
-
return {
|
|
474
|
-
account_uid: res.user_id + '',
|
|
475
|
-
account_uin: res.user_id + '',
|
|
476
|
-
account_name: res.nickname,
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* 获取陌生人信息 不支持批量获取 只支持一个
|
|
481
|
-
* @param target_uid_or_uin - 目标用户ID
|
|
482
|
-
*/
|
|
483
|
-
async GetStrangerProfileCard(target_uid_or_uin) {
|
|
484
|
-
const user_id = Number(target_uid_or_uin[0]);
|
|
485
|
-
const res = await this.SendApi("get_stranger_info" /* OB11Api['get_stranger_info'] */, { user_id, no_cache: true });
|
|
486
|
-
return [
|
|
487
|
-
{
|
|
488
|
-
/**
|
|
489
|
-
* - 用户UID
|
|
490
|
-
*/
|
|
491
|
-
uid: res.user_id + '',
|
|
492
|
-
/**
|
|
493
|
-
* - 用户UIN
|
|
494
|
-
*/
|
|
495
|
-
uin: res.user_id + '',
|
|
496
|
-
/**
|
|
497
|
-
* - qid
|
|
498
|
-
*/
|
|
499
|
-
qid: '',
|
|
500
|
-
/**
|
|
501
|
-
* - 名称
|
|
502
|
-
*/
|
|
503
|
-
nick: res.nickname,
|
|
504
|
-
/**
|
|
505
|
-
* - 备注
|
|
506
|
-
*/
|
|
507
|
-
remark: '',
|
|
508
|
-
/**
|
|
509
|
-
* - 用户等级
|
|
510
|
-
*/
|
|
511
|
-
level: 0,
|
|
512
|
-
/**
|
|
513
|
-
* - 生日
|
|
514
|
-
*/
|
|
515
|
-
birthday: '',
|
|
516
|
-
/**
|
|
517
|
-
* - 登录天数
|
|
518
|
-
*/
|
|
519
|
-
login_day: 0,
|
|
520
|
-
/**
|
|
521
|
-
* - 点赞数
|
|
522
|
-
*/
|
|
523
|
-
vote_cnt: 0,
|
|
524
|
-
/**
|
|
525
|
-
* - 学校是否已核实
|
|
526
|
-
*/
|
|
527
|
-
is_school_verified: undefined,
|
|
528
|
-
/**
|
|
529
|
-
* - 年龄
|
|
530
|
-
* - 拓展字段
|
|
531
|
-
*/
|
|
532
|
-
age: res.age,
|
|
533
|
-
/**
|
|
534
|
-
* - 性别
|
|
535
|
-
* - 拓展字段
|
|
536
|
-
*/
|
|
537
|
-
sex: res.sex,
|
|
538
|
-
ext: {
|
|
539
|
-
/**
|
|
540
|
-
* 大会员
|
|
541
|
-
*/
|
|
542
|
-
big_vip: undefined,
|
|
543
|
-
/**
|
|
544
|
-
* 好莱坞/腾讯视频会员
|
|
545
|
-
*/
|
|
546
|
-
hollywood_vip: undefined,
|
|
547
|
-
/**
|
|
548
|
-
* QQ会员
|
|
549
|
-
*/
|
|
550
|
-
qq_vip: undefined,
|
|
551
|
-
/**
|
|
552
|
-
* QQ超级会员
|
|
553
|
-
*/
|
|
554
|
-
super_vip: undefined,
|
|
555
|
-
/**
|
|
556
|
-
* 是否已经赞过
|
|
557
|
-
*/
|
|
558
|
-
voted: undefined,
|
|
559
|
-
},
|
|
560
|
-
},
|
|
561
|
-
];
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* 获取好友列表
|
|
565
|
-
*/
|
|
566
|
-
async GetFriendList() {
|
|
567
|
-
const friendList = await this.SendApi("get_friend_list" /* OB11Api['get_friend_list'] */);
|
|
568
|
-
return friendList.map(v => {
|
|
569
|
-
const user_id = v.user_id + '';
|
|
570
|
-
return {
|
|
571
|
-
/**
|
|
572
|
-
* - 用户UID
|
|
573
|
-
*/
|
|
574
|
-
uid: user_id,
|
|
575
|
-
/**
|
|
576
|
-
* - 用户UIN
|
|
577
|
-
*/
|
|
578
|
-
uin: user_id,
|
|
579
|
-
/**
|
|
580
|
-
* - qid
|
|
581
|
-
*/
|
|
582
|
-
qid: '',
|
|
583
|
-
/**
|
|
584
|
-
* - 名称
|
|
585
|
-
*/
|
|
586
|
-
nick: v.nickname,
|
|
587
|
-
/**
|
|
588
|
-
* - 备注
|
|
589
|
-
*/
|
|
590
|
-
remark: '',
|
|
591
|
-
/**
|
|
592
|
-
* - 用户等级
|
|
593
|
-
*/
|
|
594
|
-
level: 0,
|
|
595
|
-
/**
|
|
596
|
-
* - 生日
|
|
597
|
-
*/
|
|
598
|
-
birthday: '',
|
|
599
|
-
/**
|
|
600
|
-
* - 登录天数
|
|
601
|
-
*/
|
|
602
|
-
login_day: 0,
|
|
603
|
-
/**
|
|
604
|
-
* - 点赞数
|
|
605
|
-
*/
|
|
606
|
-
vote_cnt: 0,
|
|
607
|
-
/**
|
|
608
|
-
* - 学校是否已核实
|
|
609
|
-
*/
|
|
610
|
-
is_school_verified: undefined,
|
|
611
|
-
/**
|
|
612
|
-
* - 年龄
|
|
613
|
-
* - 拓展字段
|
|
614
|
-
*/
|
|
615
|
-
age: v.age,
|
|
616
|
-
/**
|
|
617
|
-
* - 性别
|
|
618
|
-
* - 拓展字段
|
|
619
|
-
*/
|
|
620
|
-
sex: v.sex,
|
|
621
|
-
ext: {
|
|
622
|
-
/**
|
|
623
|
-
* 大会员
|
|
624
|
-
*/
|
|
625
|
-
big_vip: undefined,
|
|
626
|
-
/**
|
|
627
|
-
* 好莱坞/腾讯视频会员
|
|
628
|
-
*/
|
|
629
|
-
hollywood_vip: undefined,
|
|
630
|
-
/**
|
|
631
|
-
* QQ会员
|
|
632
|
-
*/
|
|
633
|
-
qq_vip: undefined,
|
|
634
|
-
/**
|
|
635
|
-
* QQ超级会员
|
|
636
|
-
*/
|
|
637
|
-
super_vip: undefined,
|
|
638
|
-
/**
|
|
639
|
-
* 是否已经赞过
|
|
640
|
-
*/
|
|
641
|
-
voted: undefined,
|
|
642
|
-
},
|
|
643
|
-
};
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* 获取群信息
|
|
648
|
-
* @param group_id - 群号
|
|
649
|
-
* @param no_cache - 是否不使用缓存
|
|
650
|
-
*/
|
|
651
|
-
async GetGroupInfo(group_id, no_cache = false) {
|
|
652
|
-
const info = await this.SendApi("get_group_info" /* OB11Api['get_group_info'] */, { group_id: Number(group_id), no_cache });
|
|
653
|
-
const groupId = info.group_id + '';
|
|
654
|
-
const groupName = info.group_name;
|
|
655
|
-
// todo 可以走群成员列表获取群主
|
|
656
|
-
return {
|
|
657
|
-
group_id: groupId,
|
|
658
|
-
group_name: groupName,
|
|
659
|
-
group_remark: groupName,
|
|
660
|
-
max_member_count: info.max_member_count,
|
|
661
|
-
member_count: info.member_count,
|
|
662
|
-
group_uin: groupId,
|
|
663
|
-
admins: [],
|
|
664
|
-
owner: '',
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* 获取群列表
|
|
669
|
-
*/
|
|
670
|
-
async GetGroupList() {
|
|
671
|
-
const groupList = await this.SendApi("get_group_list" /* OB11Api['get_group_list'] */);
|
|
672
|
-
return groupList.map(v => {
|
|
673
|
-
const groupId = v.group_id + '';
|
|
674
|
-
const groupName = v.group_name;
|
|
675
|
-
return {
|
|
676
|
-
group_id: groupId,
|
|
677
|
-
group_name: groupName,
|
|
678
|
-
group_remark: groupName,
|
|
679
|
-
max_member_count: v.max_member_count,
|
|
680
|
-
member_count: v.member_count,
|
|
681
|
-
group_uin: groupId,
|
|
682
|
-
admins: [],
|
|
683
|
-
owner: '',
|
|
684
|
-
};
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* 获取群成员信息
|
|
689
|
-
* @param group_id - 群号
|
|
690
|
-
* @param target_uid_or_uin - 目标用户ID
|
|
691
|
-
* @param refresh - 是否刷新缓存,默认为 false
|
|
692
|
-
*/
|
|
693
|
-
async GetGroupMemberInfo(group_id, target_uid_or_uin, refresh = false) {
|
|
694
|
-
const user_id = Number(target_uid_or_uin);
|
|
695
|
-
const info = await this.SendApi("get_group_member_info" /* OB11Api['get_group_member_info'] */, { group_id: Number(group_id), user_id, no_cache: refresh });
|
|
696
|
-
return {
|
|
697
|
-
uid: target_uid_or_uin,
|
|
698
|
-
uin: target_uid_or_uin,
|
|
699
|
-
nick: info.nickname,
|
|
700
|
-
role: info.role,
|
|
701
|
-
age: info.age,
|
|
702
|
-
unique_title: info.title,
|
|
703
|
-
unique_title_expire_time: info.title_expire_time,
|
|
704
|
-
card: info.card,
|
|
705
|
-
join_time: info.join_time,
|
|
706
|
-
last_active_time: info.last_sent_time,
|
|
707
|
-
level: Number(info.level) || 0,
|
|
708
|
-
shut_up_time: 0,
|
|
709
|
-
distance: undefined,
|
|
710
|
-
honors: [],
|
|
711
|
-
unfriendly: info.unfriendly,
|
|
712
|
-
card_changeable: info.card_changeable,
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* 获取群成员列表
|
|
717
|
-
* @param group_id - 群号
|
|
718
|
-
* @param refresh - 是否刷新缓存,默认为 false
|
|
719
|
-
*/
|
|
720
|
-
async GetGroupMemberList(group_id, refresh = false) {
|
|
721
|
-
const gl = await this.SendApi("get_group_member_list" /* OB11Api['get_group_member_list'] */, { group_id: Number(group_id), no_cache: refresh });
|
|
722
|
-
return gl.map(v => {
|
|
723
|
-
const user_id = v.user_id + '';
|
|
724
|
-
return {
|
|
725
|
-
uid: user_id,
|
|
726
|
-
uin: user_id,
|
|
727
|
-
nick: v.nickname,
|
|
728
|
-
role: v.role,
|
|
729
|
-
age: v.age,
|
|
730
|
-
unique_title: v.title,
|
|
731
|
-
unique_title_expire_time: v.title_expire_time,
|
|
732
|
-
card: v.card,
|
|
733
|
-
join_time: v.join_time,
|
|
734
|
-
last_active_time: v.last_sent_time,
|
|
735
|
-
level: Number(v.level) || 0,
|
|
736
|
-
shut_up_time: 0,
|
|
737
|
-
distance: undefined,
|
|
738
|
-
honors: [],
|
|
739
|
-
unfriendly: v.unfriendly,
|
|
740
|
-
card_changeable: v.card_changeable,
|
|
741
|
-
};
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* 获取群荣誉信息
|
|
746
|
-
*/
|
|
747
|
-
async GetGroupHonor(group_id, refresh = false) {
|
|
748
|
-
const groupHonor = await this.SendApi("get_group_honor_info" /* OB11Api['get_group_honor_info'] */, { group_id: Number(group_id), type: 'all' });
|
|
749
|
-
const result = [];
|
|
750
|
-
groupHonor.talkative_list.forEach(honor => {
|
|
751
|
-
const user_id = honor.user_id + '';
|
|
752
|
-
result.push({
|
|
753
|
-
uin: user_id,
|
|
754
|
-
uid: user_id,
|
|
755
|
-
nick: honor.nickname,
|
|
756
|
-
honor_name: '历史龙王',
|
|
757
|
-
id: 0,
|
|
758
|
-
avatar: honor.avatar,
|
|
759
|
-
description: honor.description,
|
|
760
|
-
});
|
|
761
|
-
});
|
|
762
|
-
groupHonor.performer_list.forEach(honor => {
|
|
763
|
-
const user_id = honor.user_id + '';
|
|
764
|
-
result.push({
|
|
765
|
-
uin: user_id,
|
|
766
|
-
uid: user_id,
|
|
767
|
-
nick: honor.nickname,
|
|
768
|
-
honor_name: '群聊之火',
|
|
769
|
-
avatar: honor.avatar,
|
|
770
|
-
id: 0,
|
|
771
|
-
description: honor.description,
|
|
772
|
-
});
|
|
773
|
-
});
|
|
774
|
-
groupHonor.legend_list.forEach(honor => {
|
|
775
|
-
const user_id = honor.user_id + '';
|
|
776
|
-
result.push({
|
|
777
|
-
uin: user_id,
|
|
778
|
-
uid: user_id,
|
|
779
|
-
nick: honor.nickname,
|
|
780
|
-
honor_name: '群聊炽焰',
|
|
781
|
-
avatar: honor.avatar,
|
|
782
|
-
id: 0,
|
|
783
|
-
description: honor.description,
|
|
784
|
-
});
|
|
785
|
-
});
|
|
786
|
-
groupHonor.strong_newbie_list.forEach(honor => {
|
|
787
|
-
const user_id = honor.user_id + '';
|
|
788
|
-
result.push({
|
|
789
|
-
uin: user_id,
|
|
790
|
-
uid: user_id,
|
|
791
|
-
nick: honor.nickname,
|
|
792
|
-
honor_name: '冒尖小春笋',
|
|
793
|
-
avatar: honor.avatar,
|
|
794
|
-
id: 0,
|
|
795
|
-
description: honor.description,
|
|
796
|
-
});
|
|
797
|
-
});
|
|
798
|
-
groupHonor.emotion_list.forEach(honor => {
|
|
799
|
-
const user_id = honor.user_id + '';
|
|
800
|
-
result.push({
|
|
801
|
-
uin: user_id,
|
|
802
|
-
uid: user_id,
|
|
803
|
-
nick: honor.nickname,
|
|
804
|
-
honor_name: '快乐之源',
|
|
805
|
-
avatar: honor.avatar,
|
|
806
|
-
id: 0,
|
|
807
|
-
description: honor.description,
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
return result;
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* 对消息进行表情回应
|
|
814
|
-
* @param contact - 联系人信息
|
|
815
|
-
* @param message_id - 消息ID
|
|
816
|
-
* @param face_id - 表情ID
|
|
817
|
-
*/
|
|
818
|
-
async ReactMessageWithEmoji(contact, message_id, face_id, is_set = true) {
|
|
819
|
-
try {
|
|
820
|
-
await this.SendApi("set_msg_emoji_like" /* OB11Api['set_msg_emoji_like'] */, { message_id, emoji_id: face_id, is_set });
|
|
821
|
-
return true;
|
|
822
|
-
}
|
|
823
|
-
catch {
|
|
824
|
-
return false;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* 获取版本信息
|
|
829
|
-
*/
|
|
830
|
-
async GetVersion() {
|
|
831
|
-
const res = await this.SendApi("get_version_info" /* OB11Api['get_version_info'] */);
|
|
832
|
-
return {
|
|
833
|
-
name: res.app_name,
|
|
834
|
-
app_name: res.app_name,
|
|
835
|
-
version: res.app_version,
|
|
836
|
-
protocol: res.protocol_version,
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
async DownloadForwardMessage(res_id) {
|
|
840
|
-
throw new Error('Method not implemented.');
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
|
-
* 精华消息
|
|
844
|
-
*/
|
|
845
|
-
async GetEssenceMessageList(group_id, page, page_size) {
|
|
846
|
-
const list = [];
|
|
847
|
-
const res = await this.SendApi("get_essence_msg_list" /* OB11Api['get_essence_msg_list'] */, { group_id: Number(group_id) });
|
|
848
|
-
for (const v of res) {
|
|
849
|
-
const { message_seq, elements } = await this.GetMessage({ scene: "group" /* Scene.Group */, peer: group_id }, v.message_id + '');
|
|
850
|
-
list.push({
|
|
851
|
-
/**
|
|
852
|
-
* - 群ID
|
|
853
|
-
*/
|
|
854
|
-
group_id,
|
|
855
|
-
/**
|
|
856
|
-
* - 发送者uid
|
|
857
|
-
*/
|
|
858
|
-
sender_uid: v.sender_id + '',
|
|
859
|
-
/**
|
|
860
|
-
* - 发送者uin
|
|
861
|
-
*/
|
|
862
|
-
sender_uin: v.sender_id + '',
|
|
863
|
-
/**
|
|
864
|
-
* - 发送者昵称
|
|
865
|
-
*/
|
|
866
|
-
sender_nick: v.sender_nick,
|
|
867
|
-
/**
|
|
868
|
-
* - 操作者uid
|
|
869
|
-
*/
|
|
870
|
-
operator_uid: v.operator_id + '',
|
|
871
|
-
/**
|
|
872
|
-
* - 操作者uin
|
|
873
|
-
*/
|
|
874
|
-
operator_uin: v.operator_id + '',
|
|
875
|
-
/**
|
|
876
|
-
* - 操作者昵称
|
|
877
|
-
*/
|
|
878
|
-
operator_nick: v.operator_nick,
|
|
879
|
-
/**
|
|
880
|
-
* - 操作时间
|
|
881
|
-
*/
|
|
882
|
-
operation_time: v.operator_time,
|
|
883
|
-
/**
|
|
884
|
-
* - 消息时间
|
|
885
|
-
*/
|
|
886
|
-
message_time: v.sender_time,
|
|
887
|
-
/**
|
|
888
|
-
* - 消息ID
|
|
889
|
-
*/
|
|
890
|
-
message_id: v.message_id + '',
|
|
891
|
-
/**
|
|
892
|
-
* - 消息序列号
|
|
893
|
-
*/
|
|
894
|
-
message_seq,
|
|
895
|
-
/**
|
|
896
|
-
* - 被设置的精华消息元素文本
|
|
897
|
-
*/
|
|
898
|
-
json_elements: JSON.stringify(elements),
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
return list;
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* 上传群文件
|
|
905
|
-
* @param group_id - 群号
|
|
906
|
-
* @param file - 本地文件绝对路径
|
|
907
|
-
* @param name - 文件名称 必须提供
|
|
908
|
-
* @param folder - 父目录ID 不提供则上传到根目录
|
|
909
|
-
*/
|
|
910
|
-
async UploadGroupFile(group_id, file, name, folder) {
|
|
911
|
-
try {
|
|
912
|
-
await this.SendApi("upload_group_file" /* OB11Api['upload_group_file'] */, { group_id: Number(group_id), file, name, folder });
|
|
913
|
-
return true;
|
|
914
|
-
}
|
|
915
|
-
catch {
|
|
916
|
-
return false;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* 上传私聊文件
|
|
921
|
-
* @param user_id - 用户ID
|
|
922
|
-
* @param file - 本地文件绝对路径
|
|
923
|
-
* @param name - 文件名称 必须提供
|
|
924
|
-
*/
|
|
925
|
-
async UploadPrivateFile(user_id, file, name) {
|
|
926
|
-
try {
|
|
927
|
-
await this.SendApi("upload_private_file" /* OB11Api['upload_private_file'] */, { user_id: Number(user_id), file, name });
|
|
928
|
-
return true;
|
|
929
|
-
}
|
|
930
|
-
catch {
|
|
931
|
-
return false;
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* 设置精华消息
|
|
936
|
-
* @param _group_id - 群号
|
|
937
|
-
* @param message_id - 消息ID
|
|
938
|
-
*/
|
|
939
|
-
async SetEssenceMessage(_group_id, message_id) {
|
|
940
|
-
try {
|
|
941
|
-
await this.SendApi("set_essence_msg" /* OB11Api['set_essence_msg'] */, { message_id: Number(message_id) });
|
|
942
|
-
return true;
|
|
943
|
-
}
|
|
944
|
-
catch {
|
|
945
|
-
return false;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* 移除精华消息
|
|
950
|
-
* @param _group_id - 群号
|
|
951
|
-
* @param message_id - 消息ID
|
|
952
|
-
*/
|
|
953
|
-
async DeleteEssenceMessage(_group_id, message_id) {
|
|
954
|
-
try {
|
|
955
|
-
await this.SendApi("delete_essence_msg" /* OB11Api['delete_essence_msg'] */, { message_id: Number(message_id) });
|
|
956
|
-
return true;
|
|
957
|
-
}
|
|
958
|
-
catch {
|
|
959
|
-
return false;
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
async PokeMember(group_id, target_uid_or_uin) {
|
|
963
|
-
// 这个接口比较特殊 暂时先搁置 lgl单独接口 shamrock单独接口 gocq字段不一样 llob貌似没实现?
|
|
964
|
-
throw new Error('Method not implemented.');
|
|
965
|
-
}
|
|
966
|
-
async SetFriendApplyResult(request_id, is_approve, remark) {
|
|
967
|
-
try {
|
|
968
|
-
await this.SendApi("set_friend_add_request" /* OB11Api['set_friend_add_request'] */, { flag: request_id, approve: is_approve, remark });
|
|
969
|
-
return true;
|
|
970
|
-
}
|
|
971
|
-
catch {
|
|
972
|
-
return false;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
async SetGroupApplyResult(request_id, is_approve, deny_reason) {
|
|
976
|
-
try {
|
|
977
|
-
await this.SendApi("set_group_add_request" /* OB11Api['set_group_add_request'] */, { flag: request_id, approve: is_approve, sub_type: 'add', reason: deny_reason });
|
|
978
|
-
return true;
|
|
979
|
-
}
|
|
980
|
-
catch {
|
|
981
|
-
return false;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
async SetInvitedJoinGroupResult(request_id, is_approve, deny_reason) {
|
|
985
|
-
try {
|
|
986
|
-
await this.SendApi("set_group_add_request" /* OB11Api['set_group_add_request'] */, { flag: request_id, approve: is_approve, sub_type: 'invite', reason: deny_reason });
|
|
987
|
-
return true;
|
|
988
|
-
}
|
|
989
|
-
catch {
|
|
990
|
-
return false;
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
DownloadFile() { throw new Error('Method not implemented.'); }
|
|
994
|
-
CreateFolder() { throw new Error('Method not implemented.'); }
|
|
995
|
-
RenameFolder() { throw new Error('Method not implemented.'); }
|
|
996
|
-
DeleteFolder() { throw new Error('Method not implemented.'); }
|
|
997
|
-
DeleteFile() { throw new Error('Method not implemented.'); }
|
|
998
|
-
GetFileList() { throw new Error('Method not implemented.'); }
|
|
999
|
-
UploadFile() { throw new Error('Method not implemented.'); }
|
|
1000
|
-
GetFileSystemInfo() { throw new Error('Method not implemented.'); }
|
|
1001
|
-
ModifyGroupRemark() { throw new Error('Method not implemented.'); }
|
|
1002
|
-
GetRemainCountAtAll() { throw new Error('Method not implemented.'); }
|
|
1003
|
-
GetProhibitedUserList() { throw new Error('Method not implemented.'); }
|
|
1004
|
-
SetMessageReaded() { throw new Error('Method not implemented.'); }
|
|
1005
|
-
async sendForwardMessage(contact, elements) {
|
|
1006
|
-
let message_id = await this.UploadForwardMessage(contact, elements);
|
|
1007
|
-
if (this.version.name === 'Lagrange.OneBot') {
|
|
1008
|
-
message_id = (await this.SendMessage(contact, [segment.forward(message_id)])).message_id;
|
|
1009
|
-
}
|
|
1010
|
-
return { message_id };
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* 发送API请求
|
|
1014
|
-
* @param action - API断点
|
|
1015
|
-
* @param {object} params - API参数
|
|
1016
|
-
* @returns {Promise<any>} - API返回
|
|
1017
|
-
*/
|
|
1018
|
-
async SendApi(action, params = {}, time = 0) {
|
|
1019
|
-
if (!time)
|
|
1020
|
-
time = config.timeout('ws');
|
|
1021
|
-
const echo = randomUUID();
|
|
1022
|
-
const request = JSON.stringify({ echo, action, params });
|
|
1023
|
-
logger.debug(`[API请求] ${action}: ${request}`);
|
|
1024
|
-
return new Promise((resolve, reject) => {
|
|
1025
|
-
const timeoutId = setTimeout(() => {
|
|
1026
|
-
reject(new Error('API请求超时'));
|
|
1027
|
-
}, time * 1000);
|
|
1028
|
-
this.socket.send(request);
|
|
1029
|
-
this.socket.once(echo, data => {
|
|
1030
|
-
/** 停止监听器 */
|
|
1031
|
-
clearTimeout(timeoutId);
|
|
1032
|
-
if (data.status === 'ok') {
|
|
1033
|
-
resolve(data.data);
|
|
1034
|
-
}
|
|
1035
|
-
else {
|
|
1036
|
-
this.logger('error', `[Api请求错误] ${action}: ${JSON.stringify(data, null, 2)}`);
|
|
1037
|
-
reject(data);
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
export default {
|
|
1044
|
-
type: 'websocket',
|
|
1045
|
-
path: '/onebot/v11/ws',
|
|
1046
|
-
adapter: AdapterOneBot11,
|
|
1047
|
-
};
|