alemonjs 1.0.0
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/LICENSE +340 -0
- package/README.md +54 -0
- package/lib/alemon/app.js +38 -0
- package/lib/alemon/apps.js +121 -0
- package/lib/alemon/buffer.js +38 -0
- package/lib/alemon/dealmsg.js +423 -0
- package/lib/alemon/dialogue.js +61 -0
- package/lib/alemon/index.js +40 -0
- package/lib/alemon/message.js +27 -0
- package/lib/alemon/plugin.js +44 -0
- package/lib/alemon/puppeteer.js +226 -0
- package/lib/alemon/qrcode.js +66 -0
- package/lib/alemon/screenshot.js +126 -0
- package/lib/alemon/typings.js +96 -0
- package/lib/config.js +25 -0
- package/lib/discord/alemon/api.js +44 -0
- package/lib/discord/alemon/bot.js +11 -0
- package/lib/discord/alemon/conversation.js +7 -0
- package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +185 -0
- package/lib/discord/alemon/segment.js +62 -0
- package/lib/discord/index.js +50 -0
- package/lib/discord/login.js +99 -0
- package/lib/index.js +12 -0
- package/lib/kook/alemon/bot.js +11 -0
- package/lib/kook/alemon/conversation.js +56 -0
- package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +195 -0
- package/lib/kook/alemon/segment.js +90 -0
- package/lib/kook/index.js +39 -0
- package/lib/kook/login.js +53 -0
- package/lib/login.js +112 -0
- package/lib/main.js +106 -0
- package/lib/ntqq/alemon/bot.js +11 -0
- package/lib/ntqq/alemon/conversation.js +18 -0
- package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +142 -0
- package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +218 -0
- package/lib/ntqq/alemon/segment.js +29 -0
- package/lib/ntqq/alemon/types.js +1 -0
- package/lib/ntqq/index.js +77 -0
- package/lib/ntqq/login.js +74 -0
- package/lib/ntqq/sdk/api.js +158 -0
- package/lib/ntqq/sdk/config.js +46 -0
- package/lib/ntqq/sdk/index.js +5 -0
- package/lib/ntqq/sdk/intents.js +69 -0
- package/lib/ntqq/sdk/types.js +1 -0
- package/lib/ntqq/sdk/typings.js +9 -0
- package/lib/ntqq/sdk/web/client.js +89 -0
- package/lib/ntqq/sdk/web/img.js +76 -0
- package/lib/ntqq/sdk/web/index.js +4 -0
- package/lib/ntqq/sdk/web/ip.js +24 -0
- package/lib/ntqq/sdk/wss.js +178 -0
- package/lib/qq/alemon/apidoc.js +216 -0
- package/lib/qq/alemon/bot.js +11 -0
- package/lib/qq/alemon/console.js +13 -0
- package/lib/qq/alemon/conversation.js +139 -0
- package/lib/qq/alemon/doc.js +93 -0
- package/lib/qq/alemon/e.js +41 -0
- package/lib/qq/alemon/message/AUDIO_ACTION.js +57 -0
- package/lib/qq/alemon/message/DIRECT_MESSAGE.js +202 -0
- package/lib/qq/alemon/message/FORUMS_EVENT.js +66 -0
- package/lib/qq/alemon/message/GUILDS.js +65 -0
- package/lib/qq/alemon/message/GUILD_MEMBERS.js +153 -0
- package/lib/qq/alemon/message/GUILD_MESSAGES.js +50 -0
- package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +37 -0
- package/lib/qq/alemon/message/INTERACTION.js +36 -0
- package/lib/qq/alemon/message/MESSAGE.js +303 -0
- package/lib/qq/alemon/message/MESSAGE_AUDIT.js +41 -0
- package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +74 -0
- package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +52 -0
- package/lib/qq/alemon/permissions.js +43 -0
- package/lib/qq/alemon/privatechat.js +78 -0
- package/lib/qq/alemon/segment.js +25 -0
- package/lib/qq/alemon/types.js +25 -0
- package/lib/qq/index.js +44 -0
- package/lib/qq/login.js +151 -0
- package/lib/types.js +5 -0
- package/lib/villa/alemon/conversation.js +48 -0
- package/lib/villa/alemon/message/GUILDS.js +124 -0
- package/lib/villa/alemon/message/GUILD_MEMBERS.js +128 -0
- package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +127 -0
- package/lib/villa/alemon/message/MESSAGES.js +334 -0
- package/lib/villa/alemon/message/MESSAGE_AUDIT.js +128 -0
- package/lib/villa/alemon/message/e.js +41 -0
- package/lib/villa/alemon/segment.js +34 -0
- package/lib/villa/index.js +46 -0
- package/lib/villa/login.js +62 -0
- package/package.json +63 -0
- package/types/alemon/app.d.ts +22 -0
- package/types/alemon/apps.d.ts +41 -0
- package/types/alemon/buffer.d.ts +13 -0
- package/types/alemon/dealmsg.d.ts +41 -0
- package/types/alemon/dialogue.d.ts +55 -0
- package/types/alemon/index.d.ts +40 -0
- package/types/alemon/message.d.ts +17 -0
- package/types/alemon/plugin.d.ts +69 -0
- package/types/alemon/puppeteer.d.ts +53 -0
- package/types/alemon/qrcode.d.ts +20 -0
- package/types/alemon/screenshot.d.ts +23 -0
- package/types/alemon/typings.d.ts +525 -0
- package/types/config.d.ts +12 -0
- package/types/discord/alemon/api.d.ts +11 -0
- package/types/discord/alemon/bot.d.ts +6 -0
- package/types/discord/alemon/conversation.d.ts +6 -0
- package/types/discord/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +7 -0
- package/types/discord/alemon/segment.d.ts +46 -0
- package/types/discord/index.d.ts +1 -0
- package/types/discord/login.d.ts +7 -0
- package/types/index.d.ts +6 -0
- package/types/kook/alemon/bot.d.ts +8 -0
- package/types/kook/alemon/conversation.d.ts +7 -0
- package/types/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +6 -0
- package/types/kook/alemon/segment.d.ts +66 -0
- package/types/kook/index.d.ts +5 -0
- package/types/kook/login.d.ts +7 -0
- package/types/login.d.ts +18 -0
- package/types/main.d.ts +15 -0
- package/types/ntqq/alemon/bot.d.ts +8 -0
- package/types/ntqq/alemon/conversation.d.ts +8 -0
- package/types/ntqq/alemon/message/C2C_MESSAGE_CREATE.d.ts +2 -0
- package/types/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.d.ts +8 -0
- package/types/ntqq/alemon/segment.d.ts +20 -0
- package/types/ntqq/alemon/types.d.ts +11 -0
- package/types/ntqq/index.d.ts +1 -0
- package/types/ntqq/login.d.ts +6 -0
- package/types/ntqq/sdk/api.d.ts +44 -0
- package/types/ntqq/sdk/config.d.ts +23 -0
- package/types/ntqq/sdk/index.d.ts +5 -0
- package/types/ntqq/sdk/intents.d.ts +2 -0
- package/types/ntqq/sdk/types.d.ts +11 -0
- package/types/ntqq/sdk/typings.d.ts +17 -0
- package/types/ntqq/sdk/web/client.d.ts +8 -0
- package/types/ntqq/sdk/web/img.d.ts +20 -0
- package/types/ntqq/sdk/web/index.d.ts +4 -0
- package/types/ntqq/sdk/web/ip.d.ts +5 -0
- package/types/ntqq/sdk/wss.d.ts +35 -0
- package/types/qq/alemon/apidoc.d.ts +154 -0
- package/types/qq/alemon/bot.d.ts +8 -0
- package/types/qq/alemon/console.d.ts +1 -0
- package/types/qq/alemon/conversation.d.ts +5 -0
- package/types/qq/alemon/doc.d.ts +93 -0
- package/types/qq/alemon/e.d.ts +38 -0
- package/types/qq/alemon/message/AUDIO_ACTION.d.ts +15 -0
- package/types/qq/alemon/message/DIRECT_MESSAGE.d.ts +16 -0
- package/types/qq/alemon/message/FORUMS_EVENT.d.ts +25 -0
- package/types/qq/alemon/message/GUILDS.d.ts +19 -0
- package/types/qq/alemon/message/GUILD_MEMBERS.d.ts +11 -0
- package/types/qq/alemon/message/GUILD_MESSAGES.d.ts +12 -0
- package/types/qq/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +9 -0
- package/types/qq/alemon/message/INTERACTION.d.ts +8 -0
- package/types/qq/alemon/message/MESSAGE.d.ts +16 -0
- package/types/qq/alemon/message/MESSAGE_AUDIT.d.ts +9 -0
- package/types/qq/alemon/message/OPEN_FORUMS_EVENT.d.ts +28 -0
- package/types/qq/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +12 -0
- package/types/qq/alemon/permissions.d.ts +29 -0
- package/types/qq/alemon/privatechat.d.ts +14 -0
- package/types/qq/alemon/segment.d.ts +19 -0
- package/types/qq/alemon/types.d.ts +82 -0
- package/types/qq/index.d.ts +6 -0
- package/types/qq/login.d.ts +6 -0
- package/types/types.d.ts +85 -0
- package/types/villa/alemon/conversation.d.ts +7 -0
- package/types/villa/alemon/message/GUILDS.d.ts +10 -0
- package/types/villa/alemon/message/GUILD_MEMBERS.d.ts +14 -0
- package/types/villa/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +7 -0
- package/types/villa/alemon/message/MESSAGES.d.ts +7 -0
- package/types/villa/alemon/message/MESSAGE_AUDIT.d.ts +10 -0
- package/types/villa/alemon/message/e.d.ts +37 -0
- package/types/villa/alemon/segment.d.ts +26 -0
- package/types/villa/index.d.ts +1 -0
- package/types/villa/login.d.ts +7 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Koa from 'koa';
|
|
2
|
+
import Router from 'koa-router';
|
|
3
|
+
import bodyParser from 'koa-bodyparser';
|
|
4
|
+
import { mkdirSync } from 'fs';
|
|
5
|
+
import { getLocalImg } from './img.js';
|
|
6
|
+
import { setWebConfig } from '../config.js';
|
|
7
|
+
/**
|
|
8
|
+
* 创建客户端
|
|
9
|
+
* @param param0
|
|
10
|
+
* @param callBack
|
|
11
|
+
* @param logFnc
|
|
12
|
+
*/
|
|
13
|
+
export function createWeb({ callback_port = 9090, img_size = 9999999, http = 'http', img_url = '/api/mys/img', IMAGE_DIR = '/data/mys/img' }, logFnc) {
|
|
14
|
+
/**
|
|
15
|
+
* 创建 Koa 应用
|
|
16
|
+
*/
|
|
17
|
+
const app = new Koa();
|
|
18
|
+
const router = new Router();
|
|
19
|
+
/**
|
|
20
|
+
* 处理 POST 请求体中的 JSON 数据
|
|
21
|
+
*/
|
|
22
|
+
app.use(bodyParser());
|
|
23
|
+
/**
|
|
24
|
+
* 确保目录存在
|
|
25
|
+
*/
|
|
26
|
+
mkdirSync(IMAGE_DIR, { recursive: true });
|
|
27
|
+
mkdirSync(img_url, { recursive: true });
|
|
28
|
+
/**
|
|
29
|
+
* 处理图片请求
|
|
30
|
+
*/
|
|
31
|
+
router.get(`${img_url}/:filename`, getLocalImg);
|
|
32
|
+
/**
|
|
33
|
+
* 将路由注册到应用
|
|
34
|
+
*/
|
|
35
|
+
app.use(router.routes());
|
|
36
|
+
app.use(router.allowedMethods());
|
|
37
|
+
let currentPort = callback_port;
|
|
38
|
+
let size = 0;
|
|
39
|
+
/**
|
|
40
|
+
* 错误处理
|
|
41
|
+
* @param err
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
function handlePortConflict(err) {
|
|
45
|
+
if (err.code === 'EADDRINUSE') {
|
|
46
|
+
console.error(`端口 ${currentPort} 被占用,尝试启动新的端口...`);
|
|
47
|
+
currentPort++;
|
|
48
|
+
size++;
|
|
49
|
+
if (size >= 10) {
|
|
50
|
+
console.error('寻端失败~');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
createApp(currentPort);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.error('启动应用程序时发生错误:', err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 创建应用
|
|
61
|
+
* @param port
|
|
62
|
+
*/
|
|
63
|
+
function createApp(port) {
|
|
64
|
+
/**
|
|
65
|
+
* 设置配置
|
|
66
|
+
*/
|
|
67
|
+
setWebConfig({
|
|
68
|
+
callback_port: port,
|
|
69
|
+
img_url,
|
|
70
|
+
http,
|
|
71
|
+
img_size,
|
|
72
|
+
IMAGE_DIR
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* 启动应用
|
|
76
|
+
*/
|
|
77
|
+
app
|
|
78
|
+
.listen(port, async () => {
|
|
79
|
+
if (logFnc) {
|
|
80
|
+
await logFnc(port);
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
.on('error', handlePortConflict);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 启动应用
|
|
87
|
+
*/
|
|
88
|
+
createApp(currentPort);
|
|
89
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createReadStream, writeFileSync, readdirSync, unlinkSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { fileTypeFromBuffer } from 'file-type';
|
|
4
|
+
import { getWebConfig } from '../config.js';
|
|
5
|
+
/**
|
|
6
|
+
* 处理图片请求
|
|
7
|
+
* @param req
|
|
8
|
+
* @param res
|
|
9
|
+
*/
|
|
10
|
+
export function getLocalImg(ctx) {
|
|
11
|
+
const cfg = getWebConfig();
|
|
12
|
+
const filename = ctx.params.filename;
|
|
13
|
+
const imagePath = join(cfg.IMAGE_DIR, filename);
|
|
14
|
+
try {
|
|
15
|
+
const stream = createReadStream(imagePath);
|
|
16
|
+
ctx.set('Content-Type', 'image/jpeg');
|
|
17
|
+
ctx.body = stream;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
ctx.status = 404;
|
|
21
|
+
ctx.body = 'Not Found';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 自动清除机制
|
|
26
|
+
* 清除挂载下的所有图片
|
|
27
|
+
* 'jpg', 'jpeg', 'png', 'gif'
|
|
28
|
+
* @param time
|
|
29
|
+
*/
|
|
30
|
+
export function autoClearImages(time) {
|
|
31
|
+
/**
|
|
32
|
+
* 得到配置
|
|
33
|
+
*/
|
|
34
|
+
const cfg = getWebConfig();
|
|
35
|
+
/**
|
|
36
|
+
* 启动清除
|
|
37
|
+
*/
|
|
38
|
+
setInterval(() => {
|
|
39
|
+
const files = readdirSync(cfg.IMAGE_DIR);
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
const extname = file.split('.').pop();
|
|
42
|
+
if (['jpg', 'jpeg', 'png', 'gif'].includes(extname.toLowerCase())) {
|
|
43
|
+
const filePath = join(cfg.IMAGE_DIR, file);
|
|
44
|
+
unlinkSync(filePath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, time);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 存储图片
|
|
51
|
+
* @param Buffer 元素
|
|
52
|
+
*/
|
|
53
|
+
export async function setLocalImg(img) {
|
|
54
|
+
/**
|
|
55
|
+
* 检查参数是否有效
|
|
56
|
+
*/
|
|
57
|
+
if (!img)
|
|
58
|
+
return false;
|
|
59
|
+
/**
|
|
60
|
+
* 得到配置
|
|
61
|
+
*/
|
|
62
|
+
const cfg = getWebConfig();
|
|
63
|
+
/**
|
|
64
|
+
* 生成文件名
|
|
65
|
+
*/
|
|
66
|
+
const filename = `${Math.floor(Math.random() * cfg.img_size)}.${(await fileTypeFromBuffer(img))?.ext}`;
|
|
67
|
+
/**
|
|
68
|
+
* 文件路径
|
|
69
|
+
*/
|
|
70
|
+
const imagePath = join(cfg.IMAGE_DIR, filename);
|
|
71
|
+
/**
|
|
72
|
+
* 将图片保存到文件系统中
|
|
73
|
+
*/
|
|
74
|
+
writeFileSync(imagePath, img);
|
|
75
|
+
return `${cfg.img_url}/${filename}`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { publicIp } from 'public-ip';
|
|
2
|
+
/**
|
|
3
|
+
* 得到ip地址
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export async function getIP() {
|
|
7
|
+
const ip = await publicIp({
|
|
8
|
+
onlyHttps: true,
|
|
9
|
+
timeout: 10000
|
|
10
|
+
})
|
|
11
|
+
.then((ip) => {
|
|
12
|
+
if (/^(\d{1,3}\.){3}\d{1,3}$/.test(ip)) {
|
|
13
|
+
return ip;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
.catch(err => {
|
|
20
|
+
console.error(err);
|
|
21
|
+
process.exit();
|
|
22
|
+
});
|
|
23
|
+
return ip;
|
|
24
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { requestService } from './api.js';
|
|
3
|
+
import { getBotConfig } from './config.js';
|
|
4
|
+
import { getIntentsMask } from './intents.js';
|
|
5
|
+
/**
|
|
6
|
+
* @param token token
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export async function getGatewayUrl() {
|
|
10
|
+
try {
|
|
11
|
+
const response = await requestService({
|
|
12
|
+
url: '/gateway'
|
|
13
|
+
}).then(res => res.data);
|
|
14
|
+
if (response.url) {
|
|
15
|
+
return response.url;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.error('[http] err:', null);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('[token] err:', error.message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
let reconnectAttempts = 0; // 重新连接计数器
|
|
26
|
+
/**
|
|
27
|
+
* 使用获取到的网关连接地址建立 WebSocket 连接
|
|
28
|
+
* @param token
|
|
29
|
+
* @param callBack
|
|
30
|
+
*/
|
|
31
|
+
export async function createClient(call, shard = [0, 1]) {
|
|
32
|
+
/**
|
|
33
|
+
* 请求url
|
|
34
|
+
*/
|
|
35
|
+
const gatewayUrl = await getGatewayUrl();
|
|
36
|
+
// 重新连接的逻辑
|
|
37
|
+
const reconnect = async () => {
|
|
38
|
+
if (reconnectAttempts >= 5) {
|
|
39
|
+
console.info('已达到最大重连次数,取消重新连接');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
console.info('正在重新连接...');
|
|
43
|
+
// 延迟一段时间后发起重新连接
|
|
44
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
45
|
+
// 调用createClient函数重新建立连接
|
|
46
|
+
await createClient(call, shard);
|
|
47
|
+
reconnectAttempts++; // 递增重连计数器
|
|
48
|
+
};
|
|
49
|
+
if (gatewayUrl) {
|
|
50
|
+
const ws = new WebSocket(gatewayUrl);
|
|
51
|
+
ws.on('open', () => {
|
|
52
|
+
console.info('[token] ok');
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* 标记是否已连接
|
|
56
|
+
*/
|
|
57
|
+
let isConnected = false;
|
|
58
|
+
/**
|
|
59
|
+
* 存储最新的消息序号
|
|
60
|
+
*/
|
|
61
|
+
let heartbeat_interval = 30000;
|
|
62
|
+
/**
|
|
63
|
+
* 鉴权
|
|
64
|
+
*/
|
|
65
|
+
let power;
|
|
66
|
+
/**
|
|
67
|
+
* 监听消息
|
|
68
|
+
*/
|
|
69
|
+
ws.on('message', async (msg) => {
|
|
70
|
+
const message = JSON.parse(msg.toString('utf8'));
|
|
71
|
+
/**
|
|
72
|
+
* opcode
|
|
73
|
+
*
|
|
74
|
+
* s 标识消息的唯一性
|
|
75
|
+
*
|
|
76
|
+
* t 代表事件类型
|
|
77
|
+
*
|
|
78
|
+
* d 代表事件内容
|
|
79
|
+
*/
|
|
80
|
+
const { op, s, d: data, t } = message;
|
|
81
|
+
// 根据 opcode 进行处理
|
|
82
|
+
switch (op) {
|
|
83
|
+
case 0: {
|
|
84
|
+
console.log('[数据接收]', data);
|
|
85
|
+
// 存在,则执行t对应的函数
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(call, t)) {
|
|
87
|
+
call[t](data);
|
|
88
|
+
}
|
|
89
|
+
// Ready Event,鉴权成功
|
|
90
|
+
if (t === 'READY') {
|
|
91
|
+
power = setInterval(() => {
|
|
92
|
+
if (isConnected) {
|
|
93
|
+
ws.send(JSON.stringify({
|
|
94
|
+
op: 1,
|
|
95
|
+
d: null // 如果是第一次连接,传null
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
}, heartbeat_interval);
|
|
99
|
+
}
|
|
100
|
+
// Resumed Event,恢复连接成功
|
|
101
|
+
if (t === 'RESUMED') {
|
|
102
|
+
console.info('恢复连接');
|
|
103
|
+
// 重制次数
|
|
104
|
+
reconnectAttempts = 0;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case 6: {
|
|
109
|
+
console.info('[连接尝试]', message);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 7: {
|
|
113
|
+
// 执行重新连接
|
|
114
|
+
console.info('[重新连接]', message);
|
|
115
|
+
// 取消鉴权发送
|
|
116
|
+
if (power) {
|
|
117
|
+
clearInterval(power);
|
|
118
|
+
}
|
|
119
|
+
await reconnect();
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 9: {
|
|
123
|
+
console.info('[参数错误]', message);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case 10: {
|
|
127
|
+
// 重制次数
|
|
128
|
+
isConnected = true;
|
|
129
|
+
heartbeat_interval = data.heartbeat_interval;
|
|
130
|
+
const { token, intents } = getBotConfig();
|
|
131
|
+
/**
|
|
132
|
+
* 发送鉴权
|
|
133
|
+
*/
|
|
134
|
+
ws.send(JSON.stringify({
|
|
135
|
+
op: 2,
|
|
136
|
+
d: {
|
|
137
|
+
token: `QQBot ${token}`,
|
|
138
|
+
intents: getIntentsMask(intents),
|
|
139
|
+
shard,
|
|
140
|
+
properties: {
|
|
141
|
+
$os: 'linux',
|
|
142
|
+
$browser: 'my_library',
|
|
143
|
+
$device: 'my_library'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}));
|
|
147
|
+
reconnectAttempts = 0;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 11: {
|
|
151
|
+
// OpCode 11 Heartbeat ACK 消息,心跳发送成功
|
|
152
|
+
console.info('[心跳发送]', message);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
case 12: {
|
|
156
|
+
console.info('[平台数据]', message);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
ws.on('close', () => {
|
|
161
|
+
console.info('[ws] close');
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
|
|
167
|
+
1 Heartbeat Send/Receive 客户端或服务端发送心跳
|
|
168
|
+
2 Identify Send 客户端发送鉴权
|
|
169
|
+
6 Resume Send 客户端恢复连接
|
|
170
|
+
|
|
171
|
+
0 Dispatch Receive 服务端进行消息推送
|
|
172
|
+
7 Reconnect Receive 服务端通知客户端重新连接
|
|
173
|
+
9 Invalid Session Receive 当identify或resume的时候,如果参数有错,服务端会返回该消息
|
|
174
|
+
10 Hello Receive 当客户端与网关建立ws连接之后,网关下发的第一条消息
|
|
175
|
+
11 Heartbeat ACK Receive/Reply 当发送心跳成功之后,就会收到该消息
|
|
176
|
+
12 HTTP Callback ACK Reply 仅用于 http 回调模式的回包,代表机器人收到了平台推送的数据
|
|
177
|
+
|
|
178
|
+
*/
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **********
|
|
3
|
+
* 频道api
|
|
4
|
+
* ************
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 获取当前用户下的所有频道列表
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const getGuildList = async () => {
|
|
11
|
+
const data = await clientApiByQQ.meApi
|
|
12
|
+
.meGuilds()
|
|
13
|
+
.then(res => {
|
|
14
|
+
const { data } = res;
|
|
15
|
+
return data;
|
|
16
|
+
})
|
|
17
|
+
.catch(err => {
|
|
18
|
+
console.error(err);
|
|
19
|
+
return false;
|
|
20
|
+
});
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 获取频道详情
|
|
25
|
+
* @param guildId
|
|
26
|
+
* **************
|
|
27
|
+
id string 频道 ID
|
|
28
|
+
name string 频道名称
|
|
29
|
+
owner_id string 创建人用户 ID
|
|
30
|
+
owner boolean 当前人是否是创建人
|
|
31
|
+
member_count number 成员数
|
|
32
|
+
max_members number 最大成员数
|
|
33
|
+
description string 描述
|
|
34
|
+
*/
|
|
35
|
+
export const getGuildMsg = async (guildId) => {
|
|
36
|
+
const data = await clientApiByQQ.guildApi
|
|
37
|
+
.guild(guildId)
|
|
38
|
+
.then(res => {
|
|
39
|
+
const { data } = res;
|
|
40
|
+
return data;
|
|
41
|
+
})
|
|
42
|
+
.catch(err => {
|
|
43
|
+
console.error(err);
|
|
44
|
+
return false;
|
|
45
|
+
});
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* *****************
|
|
50
|
+
* 子频道api
|
|
51
|
+
* *****************
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* 获取子频道列表
|
|
55
|
+
* @param guildId
|
|
56
|
+
* @returns
|
|
57
|
+
* ***********
|
|
58
|
+
id string 子频道 ID
|
|
59
|
+
guild_id string 频道 ID
|
|
60
|
+
name string 子频道名
|
|
61
|
+
type number 子频道类型 ChannelType
|
|
62
|
+
sub_type number 子频道子类型 ChannelSubType
|
|
63
|
+
position number 排序,非必填
|
|
64
|
+
parent_id string 分组 ID
|
|
65
|
+
owner_id string 创建人 ID
|
|
66
|
+
*/
|
|
67
|
+
export const getChannels = async (guildId) => {
|
|
68
|
+
const data = await clientApiByQQ.channelApi
|
|
69
|
+
.channels(guildId)
|
|
70
|
+
.then(res => {
|
|
71
|
+
const { data } = res;
|
|
72
|
+
return data;
|
|
73
|
+
})
|
|
74
|
+
.catch(err => {
|
|
75
|
+
console.error(err);
|
|
76
|
+
return false;
|
|
77
|
+
});
|
|
78
|
+
return data;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 获取子频道详情
|
|
82
|
+
* @param channelId
|
|
83
|
+
* @returns
|
|
84
|
+
id string 子频道 ID
|
|
85
|
+
guild_id string 频道 ID
|
|
86
|
+
name string 子频道名
|
|
87
|
+
type number 子频道类型 ChannelType
|
|
88
|
+
sub_type number 子频道子类型 ChannelSubType
|
|
89
|
+
position number 排序,非必填
|
|
90
|
+
parent_id string 分组 ID
|
|
91
|
+
owner_id string 创建人 ID
|
|
92
|
+
*/
|
|
93
|
+
export const getChannel = async (channelId) => {
|
|
94
|
+
const data = await clientApiByQQ.channelApi
|
|
95
|
+
.channel(channelId)
|
|
96
|
+
.then(res => {
|
|
97
|
+
const { data } = res;
|
|
98
|
+
return data;
|
|
99
|
+
})
|
|
100
|
+
.catch(err => {
|
|
101
|
+
console.error(err);
|
|
102
|
+
return false;
|
|
103
|
+
});
|
|
104
|
+
return data;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* ***********
|
|
108
|
+
* 仅私域可用,毫无用处
|
|
109
|
+
* ***********
|
|
110
|
+
* 创建子频道
|
|
111
|
+
* 修改子频道
|
|
112
|
+
* 删除子频道
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* ********
|
|
116
|
+
* 成员api
|
|
117
|
+
* **********
|
|
118
|
+
*/
|
|
119
|
+
/***
|
|
120
|
+
* 获取频道下的成员列表:仅私域可用
|
|
121
|
+
*/
|
|
122
|
+
/**
|
|
123
|
+
*获取频道下某个成员的信息
|
|
124
|
+
* @param guildId 频道
|
|
125
|
+
* @param userId 用户
|
|
126
|
+
* @returns
|
|
127
|
+
* 次功能已在e消息中携带
|
|
128
|
+
*/
|
|
129
|
+
export const getGuildMemberMsg = async (guildId, userId) => {
|
|
130
|
+
const data = await clientApiByQQ.guildApi
|
|
131
|
+
.guildMember(guildId, userId)
|
|
132
|
+
.then(res => {
|
|
133
|
+
const { data } = res;
|
|
134
|
+
return data;
|
|
135
|
+
})
|
|
136
|
+
.catch(err => {
|
|
137
|
+
console.error(err);
|
|
138
|
+
return false;
|
|
139
|
+
});
|
|
140
|
+
return data;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* 移除频道的某个成员
|
|
144
|
+
* 仅私域
|
|
145
|
+
*/
|
|
146
|
+
/**
|
|
147
|
+
* 用于获取 channelID 指定的语音子频道中,所有在线成员的详情列表
|
|
148
|
+
* 仅私域
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* ***************
|
|
152
|
+
* 频道身份组api
|
|
153
|
+
* ***********
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* **********
|
|
157
|
+
* 子频道权限api
|
|
158
|
+
* *********
|
|
159
|
+
* /
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* *******
|
|
164
|
+
* 消息api
|
|
165
|
+
* *****
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* 撤回指定消息
|
|
169
|
+
* @param channelID
|
|
170
|
+
* @param messageID
|
|
171
|
+
* @param hideTip 是否隐藏
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
export const deleteMsg = async (channelID, messageID, hideTip) => {
|
|
175
|
+
const data = await clientApiByQQ.messageApi
|
|
176
|
+
.deleteMessage(channelID, messageID, hideTip)
|
|
177
|
+
.then(res => {
|
|
178
|
+
const { data } = res;
|
|
179
|
+
return data;
|
|
180
|
+
})
|
|
181
|
+
.catch(err => {
|
|
182
|
+
console.error(err);
|
|
183
|
+
return false;
|
|
184
|
+
});
|
|
185
|
+
return data;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* *******
|
|
189
|
+
* 私信api
|
|
190
|
+
* ********
|
|
191
|
+
*/
|
|
192
|
+
/**
|
|
193
|
+
* ******
|
|
194
|
+
* 群精华api
|
|
195
|
+
* ********
|
|
196
|
+
*/
|
|
197
|
+
/**
|
|
198
|
+
* *****
|
|
199
|
+
* 日程api
|
|
200
|
+
* *****
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* *******
|
|
204
|
+
*音频api
|
|
205
|
+
* ******
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* ******
|
|
209
|
+
* 禁言api
|
|
210
|
+
* ****
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* ***********
|
|
214
|
+
* 权限接口api
|
|
215
|
+
* ********
|
|
216
|
+
*/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const info = console.info;
|
|
2
|
+
/**
|
|
3
|
+
* 屏蔽错误反馈
|
|
4
|
+
* @param args
|
|
5
|
+
*/
|
|
6
|
+
console.info = (...args) => {
|
|
7
|
+
if (args[0] !== '[CLIENT] 心跳校验' &&
|
|
8
|
+
args[0] !== '[CLIENT] 超过重试次数,连接终止' &&
|
|
9
|
+
args[0] !== '[ERROR] createSession: ') {
|
|
10
|
+
info(...args);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export {};
|