@alemonjs/qq-bot 2.1.0-alpha.2 → 2.1.0-alpha.21
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/README.md +7 -30
- package/lib/config.d.ts +8 -0
- package/lib/config.js +20 -0
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +3 -12
- package/lib/hook.d.ts +30 -9
- package/lib/hook.js +19 -17
- package/lib/index.d.ts +5 -6
- package/lib/index.js +37 -19
- package/lib/index.webhook.d.ts +1 -0
- package/lib/index.webhook.js +5 -4
- package/lib/index.websoket.d.ts +1 -0
- package/lib/index.websoket.js +41 -22
- package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -0
- package/lib/message/AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/CHANNEL_CREATE.d.ts +15 -0
- package/lib/message/CHANNEL_CREATE.js +1 -0
- package/lib/message/CHANNEL_DELETE.d.ts +15 -0
- package/lib/message/CHANNEL_DELETE.js +1 -0
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
- package/lib/message/CHANNEL_UPDATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
- package/lib/message/ERROR.d.ts +1 -0
- package/lib/message/ERROR.js +1 -0
- package/lib/message/GUILD_CREATE.d.ts +15 -0
- package/lib/message/GUILD_CREATE.js +1 -0
- package/lib/message/GUILD_DELETE.d.ts +15 -0
- package/lib/message/GUILD_DELETE.js +1 -0
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/message/GUILD_UPDATE.d.ts +15 -0
- package/lib/message/GUILD_UPDATE.js +1 -0
- package/lib/message/INTERACTION_CREATE.d.ts +53 -0
- package/lib/message/INTERACTION_CREATE.js +1 -0
- package/lib/message/MESSAGE_CREATE.d.ts +1 -0
- package/lib/message/MESSAGE_CREATE.js +1 -0
- package/lib/message/MESSAGE_DELETE.d.ts +1 -0
- package/lib/message/MESSAGE_DELETE.js +1 -0
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
- package/lib/message/READY.d.ts +6 -0
- package/lib/message/READY.js +1 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +9 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
- package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
- package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
- package/lib/message/group/C2C_MSG_REJECT.js +1 -0
- package/lib/message/group/FRIEND_ADD.d.ts +4 -0
- package/lib/message/group/FRIEND_ADD.js +1 -0
- package/lib/message/group/FRIEND_DEL.d.ts +4 -0
- package/lib/message/group/FRIEND_DEL.js +1 -0
- package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +11 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
- package/lib/register.d.ts +2 -3
- package/lib/register.js +270 -176
- package/lib/sdk/api.d.ts +196 -969
- package/lib/sdk/api.js +267 -916
- package/lib/sdk/client.webhook.d.ts +9 -0
- package/lib/sdk/{client.js → client.webhook.js} +19 -53
- package/lib/sdk/client.websoket.d.ts +9 -0
- package/lib/sdk/client.websoket.js +43 -96
- package/lib/sdk/config.d.ts +1 -0
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +3 -0
- package/lib/sdk/intents.js +25 -90
- package/lib/sdk/message.d.ts +4 -0
- package/lib/sdk/message.group.d.ts +24 -0
- package/lib/sdk/message.group.js +1 -0
- package/lib/sdk/message.guild.d.ts +38 -0
- package/lib/sdk/message.guild.js +1 -0
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/message.public.d.ts +6 -0
- package/lib/sdk/message.public.js +1 -0
- package/lib/sdk/typing.d.ts +67 -59
- package/lib/sdk/typing.js +1 -0
- package/lib/sdk/webhook.secret.d.ts +14 -0
- package/lib/sdk/webhook.secret.js +6 -21
- package/lib/sends.d.ts +29 -0
- package/lib/sends.js +546 -477
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +7 -12
- package/package.json +9 -5
- package/lib/index.group.js +0 -19
- package/lib/index.guild.js +0 -36
- package/lib/sdk/client.websoket.group.js +0 -221
- package/lib/sdk/client.websoket.guild.js +0 -205
- package/lib/sdk/counter.js +0 -19
- package/lib/sdk/from.js +0 -44
package/README.md
CHANGED
|
@@ -46,34 +46,11 @@ qq-bot:
|
|
|
46
46
|
# ws: 'ws://[your ip]:17157/websocket'
|
|
47
47
|
# 3) 自定义模式 (用于连接类官网连接方式的指定服务端)
|
|
48
48
|
# gatewayURL: 'ws://[your ip]:8080'
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
ssl_certificate_key /usr/local/nginx/bundle.key;
|
|
57
|
-
# 对应 route: ''
|
|
58
|
-
location /webhook {
|
|
59
|
-
# 指向 webhook 服务的端口 17157
|
|
60
|
-
proxy_pass http://localhost:17157;
|
|
61
|
-
proxy_set_header Host $host;
|
|
62
|
-
proxy_set_header X-Real-IP $remote_addr;
|
|
63
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
64
|
-
proxy_set_header X-Forwarded-Proto $scheme;
|
|
65
|
-
}
|
|
66
|
-
# 对应 ws: ''
|
|
67
|
-
location /websocket {
|
|
68
|
-
# 指向 WebSocket 服务的端口 17157
|
|
69
|
-
proxy_pass http://localhost:17157;
|
|
70
|
-
proxy_http_version 1.1;
|
|
71
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
72
|
-
proxy_set_header Connection "upgrade";
|
|
73
|
-
proxy_set_header Host $host;
|
|
74
|
-
proxy_set_header X-Real-IP $remote_addr;
|
|
75
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
76
|
-
proxy_set_header X-Forwarded-Proto $scheme;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
49
|
+
# 其他
|
|
50
|
+
# 使用 user_key
|
|
51
|
+
master_key:
|
|
52
|
+
- 'xxx'
|
|
53
|
+
# 使用 user_id
|
|
54
|
+
master_id:
|
|
55
|
+
- 'yyy'
|
|
79
56
|
```
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Options as sdkOptions } from './sdk/typing';
|
|
2
|
+
export declare const platform = "qq-bot";
|
|
3
|
+
export type Options = {
|
|
4
|
+
master_key?: string[];
|
|
5
|
+
master_id?: string[];
|
|
6
|
+
} & sdkOptions;
|
|
7
|
+
export declare const getQQBotConfig: () => Options;
|
|
8
|
+
export declare const getMaster: (UserId: string) => readonly [boolean, string];
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getConfigValue, useUserHashKey } from 'alemonjs';
|
|
2
|
+
|
|
3
|
+
const platform = 'qq-bot';
|
|
4
|
+
const getQQBotConfig = () => {
|
|
5
|
+
const value = getConfigValue() || {};
|
|
6
|
+
return value[platform] || {};
|
|
7
|
+
};
|
|
8
|
+
const getMaster = (UserId) => {
|
|
9
|
+
const config = getQQBotConfig();
|
|
10
|
+
const master_key = config.master_key || [];
|
|
11
|
+
const master_id = config.master_id || [];
|
|
12
|
+
const UserKey = useUserHashKey({
|
|
13
|
+
Platform: platform,
|
|
14
|
+
UserId: UserId
|
|
15
|
+
});
|
|
16
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
17
|
+
return [is, UserKey];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { getMaster, getQQBotConfig, platform };
|
package/lib/desktop.d.ts
CHANGED
package/lib/desktop.js
CHANGED
|
@@ -3,30 +3,22 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { getConfig, getConfigValue } from 'alemonjs';
|
|
5
5
|
|
|
6
|
-
// 当前目录
|
|
7
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
// 被激活的时候。
|
|
9
7
|
const activate = context => {
|
|
10
|
-
// 创建一个 webview。
|
|
11
8
|
const webView = context.createSidebarWebView(context);
|
|
12
|
-
// 当命令被触发的时候。
|
|
13
9
|
context.onCommand('open.qq-bot', () => {
|
|
14
10
|
const dir = join(__dirname, '../', 'dist', 'index.html');
|
|
15
11
|
const scriptReg = /<script.*?src="(.+?)".*?>/;
|
|
16
12
|
const styleReg = /<link.*?rel="stylesheet".*?href="(.+?)".*?>/;
|
|
17
13
|
const iconReg = /<link.*?rel="icon".*?href="(.+?)".*?>/g;
|
|
18
|
-
// 创建 webview 路径
|
|
19
14
|
const styleUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.css'));
|
|
20
15
|
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
21
|
-
// 确保路径存在
|
|
22
16
|
const html = readFileSync(dir, 'utf-8')
|
|
23
|
-
.replace(iconReg,
|
|
17
|
+
.replace(iconReg, '')
|
|
24
18
|
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
|
25
19
|
.replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
|
|
26
|
-
// 立即渲染 webview
|
|
27
20
|
webView.loadWebView(html);
|
|
28
21
|
});
|
|
29
|
-
// 监听 webview 的消息。
|
|
30
22
|
webView.onMessage(data => {
|
|
31
23
|
try {
|
|
32
24
|
if (data.type === 'qq-bot.form.save') {
|
|
@@ -35,7 +27,6 @@ const activate = context => {
|
|
|
35
27
|
const value = config.value ?? {};
|
|
36
28
|
value['qq-bot'] = {
|
|
37
29
|
...qqBot,
|
|
38
|
-
// master_key 12121,1313,1313,13 转为数组
|
|
39
30
|
master_key: qqBot.master_key.split(',')
|
|
40
31
|
};
|
|
41
32
|
config.saveValue(value);
|
|
@@ -43,9 +34,9 @@ const activate = context => {
|
|
|
43
34
|
}
|
|
44
35
|
else if (data.type === 'qq-bot.init') {
|
|
45
36
|
let config = getConfigValue();
|
|
46
|
-
if (!config)
|
|
37
|
+
if (!config) {
|
|
47
38
|
config = {};
|
|
48
|
-
|
|
39
|
+
}
|
|
49
40
|
webView.postMessage({
|
|
50
41
|
type: 'qq-bot.init',
|
|
51
42
|
data: config['qq-bot'] ?? {}
|
package/lib/hook.d.ts
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { GROUP_AT_MESSAGE_CREATE_TYPE } from './message/group/GROUP_AT_MESSAGE_CREATE';
|
|
3
|
+
import { QQBotAPI as API } from './sdk/api';
|
|
4
|
+
import { AT_MESSAGE_CREATE_TYPE } from './message/AT_MESSAGE_CREATE';
|
|
5
|
+
import { INTERACTION_CREATE_TYPE } from './message/INTERACTION_CREATE';
|
|
6
|
+
import { DIRECT_MESSAGE_CREATE_TYPE } from './message/DIRECT_MESSAGE_CREATE';
|
|
7
|
+
import { C2C_MESSAGE_CREATE_TYPE } from './message/group/C2C_MESSAGE_CREATE';
|
|
8
|
+
type MAP = {
|
|
9
|
+
'message.create': GROUP_AT_MESSAGE_CREATE_TYPE | AT_MESSAGE_CREATE_TYPE;
|
|
10
|
+
'private.message.create': DIRECT_MESSAGE_CREATE_TYPE | C2C_MESSAGE_CREATE_TYPE;
|
|
11
|
+
'interaction.create': INTERACTION_CREATE_TYPE;
|
|
12
|
+
'private.interaction.create': undefined;
|
|
13
|
+
'message.update': undefined;
|
|
14
|
+
'message.delete': undefined;
|
|
15
|
+
'message.reaction.add': undefined;
|
|
16
|
+
'message.reaction.remove': undefined;
|
|
17
|
+
'channel.create': undefined;
|
|
18
|
+
'channel.delete': undefined;
|
|
19
|
+
'guild.join': undefined;
|
|
20
|
+
'guild.exit': undefined;
|
|
21
|
+
'member.add': undefined;
|
|
22
|
+
'member.remove': undefined;
|
|
23
|
+
'private.message.update': undefined;
|
|
24
|
+
'private.message.delete': undefined;
|
|
25
|
+
'private.friend.add': undefined;
|
|
26
|
+
'private.guild.add': undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
29
|
+
export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
|
|
30
|
+
export declare const useMode: <T extends EventKeys>(event: Events[T]) => (mode: "guild" | "group") => boolean;
|
|
31
|
+
export {};
|
package/lib/hook.js
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
|
+
import { QQBotAPI } from './sdk/api.js';
|
|
3
|
+
|
|
4
|
+
const useValue = (event) => {
|
|
5
|
+
const value = createEventValue(event);
|
|
6
|
+
return [value];
|
|
7
|
+
};
|
|
8
|
+
const useClient = (event) => {
|
|
9
|
+
const [client] = useClient$1(event, QQBotAPI);
|
|
10
|
+
const value = createEventValue(event);
|
|
11
|
+
return [client, value];
|
|
12
|
+
};
|
|
6
13
|
const useMode = (event) => {
|
|
7
14
|
const tag = event.tag;
|
|
8
15
|
let currentMode = 'group';
|
|
9
|
-
|
|
10
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
16
|
+
if (tag === 'GROUP_AT_MESSAGE_CREATE') {
|
|
11
17
|
currentMode = 'group';
|
|
12
18
|
}
|
|
13
|
-
|
|
14
|
-
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
19
|
+
if (tag === 'C2C_MESSAGE_CREATE') {
|
|
15
20
|
currentMode = 'group';
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
22
|
+
if (tag === 'DIRECT_MESSAGE_CREATE') {
|
|
19
23
|
currentMode = 'guild';
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
if (tag == 'AT_MESSAGE_CREATE') {
|
|
25
|
+
if (tag === 'AT_MESSAGE_CREATE') {
|
|
23
26
|
currentMode = 'guild';
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
28
|
+
if (tag === 'MESSAGE_CREATE') {
|
|
27
29
|
currentMode = 'guild';
|
|
28
30
|
}
|
|
29
31
|
const isMode = (mode) => {
|
|
30
|
-
return currentMode
|
|
32
|
+
return currentMode === mode;
|
|
31
33
|
};
|
|
32
34
|
return isMode;
|
|
33
35
|
};
|
|
34
36
|
|
|
35
|
-
export { useMode };
|
|
37
|
+
export { useClient, useMode, useValue };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { platform } from './
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
declare const
|
|
5
|
-
|
|
6
|
-
export { _default as default };
|
|
1
|
+
export { platform } from './config';
|
|
2
|
+
export * from './hook';
|
|
3
|
+
export { QQBotAPI as API } from './sdk/api';
|
|
4
|
+
declare const main: () => void;
|
|
5
|
+
export default main;
|
package/lib/index.js
CHANGED
|
@@ -1,31 +1,49 @@
|
|
|
1
1
|
import { getConfigValue } from 'alemonjs';
|
|
2
|
-
import { start } from './index.
|
|
3
|
-
import { start as start$1 } from './index.
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { useMode } from './hook.js';
|
|
2
|
+
import { start } from './index.webhook.js';
|
|
3
|
+
import { start as start$1 } from './index.websoket.js';
|
|
4
|
+
import { platform } from './config.js';
|
|
5
|
+
export { useClient, useMode, useValue } from './hook.js';
|
|
6
|
+
export { QQBotAPI as API } from './sdk/api.js';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
const main = () => {
|
|
10
9
|
let value = getConfigValue();
|
|
11
|
-
if (!value)
|
|
10
|
+
if (!value) {
|
|
12
11
|
value = {};
|
|
12
|
+
}
|
|
13
13
|
const config = value[platform];
|
|
14
|
-
if (config?.
|
|
14
|
+
if (config?.route || config?.port || config?.ws) {
|
|
15
15
|
start();
|
|
16
|
-
return;
|
|
17
16
|
}
|
|
18
|
-
else
|
|
17
|
+
else {
|
|
19
18
|
start$1();
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
else if (config?.route || config?.port || config?.ws) {
|
|
23
|
-
start$2();
|
|
24
|
-
return;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
};
|
|
21
|
+
const mainProcess = () => {
|
|
22
|
+
['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
|
|
23
|
+
process?.on?.(sig, () => {
|
|
24
|
+
logger.info?.(`[@alemonjs/qq-bot][${sig}] 收到信号,正在关闭...`);
|
|
25
|
+
setImmediate(() => process.exit(0));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
process?.on?.('exit', code => {
|
|
29
|
+
logger.info?.(`[@alemonjs/qq-bot][exit] 进程退出,code=${code}`);
|
|
30
|
+
});
|
|
31
|
+
process.on('message', msg => {
|
|
32
|
+
try {
|
|
33
|
+
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
34
|
+
if (data?.type === 'start') {
|
|
35
|
+
main();
|
|
36
|
+
}
|
|
37
|
+
else if (data?.type === 'stop') {
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch { }
|
|
42
|
+
});
|
|
43
|
+
if (process.send) {
|
|
44
|
+
process.send(JSON.stringify({ type: 'ready' }));
|
|
28
45
|
}
|
|
29
46
|
};
|
|
47
|
+
mainProcess();
|
|
30
48
|
|
|
31
|
-
export {
|
|
49
|
+
export { main as default, platform };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const start: () => void;
|
package/lib/index.webhook.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { QQBotClient } from './sdk/client.js';
|
|
2
|
-
import {
|
|
1
|
+
import { QQBotClient } from './sdk/client.webhook.js';
|
|
2
|
+
import { register } from './register.js';
|
|
3
|
+
import { getQQBotConfig } from './config.js';
|
|
3
4
|
|
|
4
5
|
const start = () => {
|
|
5
6
|
const config = getQQBotConfig();
|
|
7
|
+
const { master_id: _, master_key: __, ...cfgConfig } = config;
|
|
6
8
|
const client = new QQBotClient({
|
|
7
|
-
...
|
|
9
|
+
...cfgConfig
|
|
8
10
|
});
|
|
9
|
-
// 连接
|
|
10
11
|
client.connect();
|
|
11
12
|
register(client);
|
|
12
13
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const start: () => void;
|
package/lib/index.websoket.js
CHANGED
|
@@ -1,36 +1,55 @@
|
|
|
1
1
|
import { QQBotClients } from './sdk/client.websoket.js';
|
|
2
|
-
import {
|
|
2
|
+
import { register } from './register.js';
|
|
3
|
+
import { getQQBotConfig } from './config.js';
|
|
3
4
|
|
|
4
5
|
const start = () => {
|
|
5
6
|
const config = getQQBotConfig();
|
|
7
|
+
const notPrivateIntents = [
|
|
8
|
+
'GUILDS',
|
|
9
|
+
'GUILD_MEMBERS',
|
|
10
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
11
|
+
'DIRECT_MESSAGE',
|
|
12
|
+
'PUBLIC_GUILD_MESSAGES'
|
|
13
|
+
];
|
|
14
|
+
const isPrivateIntents = [
|
|
15
|
+
'GUILDS',
|
|
16
|
+
'GUILD_MEMBERS',
|
|
17
|
+
'GUILD_MESSAGES',
|
|
18
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
19
|
+
'DIRECT_MESSAGE',
|
|
20
|
+
'FORUMS_EVENT'
|
|
21
|
+
];
|
|
22
|
+
const isGroupIntents = ['GROUP_AND_C2C_EVENT'];
|
|
23
|
+
const pubIntents = ['INTERACTION'];
|
|
24
|
+
const intents = [];
|
|
25
|
+
if (config?.mode === 'guild') {
|
|
26
|
+
if (config?.is_private) {
|
|
27
|
+
intents.push(...isPrivateIntents, ...pubIntents);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
intents.push(...notPrivateIntents, ...pubIntents);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (config?.mode === 'group') {
|
|
34
|
+
intents.push(...isGroupIntents, ...pubIntents);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (config?.is_private) {
|
|
38
|
+
intents.push(...isPrivateIntents, ...pubIntents);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
intents.push(...notPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
6
44
|
const client = new QQBotClients({
|
|
7
45
|
...config,
|
|
8
|
-
intents: config?.intents
|
|
9
|
-
? [
|
|
10
|
-
'GUILDS', // base
|
|
11
|
-
'GUILD_MEMBERS', // base
|
|
12
|
-
'GUILD_MESSAGES',
|
|
13
|
-
'GUILD_MESSAGE_REACTIONS',
|
|
14
|
-
'DIRECT_MESSAGE',
|
|
15
|
-
'INTERACTION',
|
|
16
|
-
'FORUMS_EVENT'
|
|
17
|
-
]
|
|
18
|
-
: [
|
|
19
|
-
'GUILDS', // base
|
|
20
|
-
'GUILD_MEMBERS', // base
|
|
21
|
-
'GUILD_MESSAGE_REACTIONS',
|
|
22
|
-
'DIRECT_MESSAGE',
|
|
23
|
-
'INTERACTION',
|
|
24
|
-
'PUBLIC_GUILD_MESSAGES',
|
|
25
|
-
'GROUP_AND_C2C_EVENT'
|
|
26
|
-
],
|
|
46
|
+
intents: config?.intents || intents,
|
|
27
47
|
is_private: config?.is_private ?? false,
|
|
28
48
|
sandbox: config?.sandbox ?? false,
|
|
29
49
|
shard: config?.shard ?? [0, 1],
|
|
30
50
|
mode: config?.mode ?? 'group'
|
|
31
51
|
});
|
|
32
|
-
|
|
33
|
-
client.connect(config?.gatewayURL);
|
|
52
|
+
void client.connect(config?.gatewayURL);
|
|
34
53
|
register(client);
|
|
35
54
|
};
|
|
36
55
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type AT_MESSAGE_CREATE_TYPE = {
|
|
2
|
+
attachments?: {
|
|
3
|
+
id: string;
|
|
4
|
+
url: string;
|
|
5
|
+
content_type: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
size: number;
|
|
8
|
+
height: number;
|
|
9
|
+
width: number;
|
|
10
|
+
}[];
|
|
11
|
+
author: {
|
|
12
|
+
avatar: string;
|
|
13
|
+
bot: boolean;
|
|
14
|
+
id: string;
|
|
15
|
+
username: string;
|
|
16
|
+
};
|
|
17
|
+
channel_id: string;
|
|
18
|
+
content: string;
|
|
19
|
+
guild_id: string;
|
|
20
|
+
id: string;
|
|
21
|
+
member: {
|
|
22
|
+
joined_at: string;
|
|
23
|
+
nick: string;
|
|
24
|
+
roles: string[];
|
|
25
|
+
};
|
|
26
|
+
mentions: {
|
|
27
|
+
avatar: string;
|
|
28
|
+
bot: boolean;
|
|
29
|
+
id: string;
|
|
30
|
+
username: string;
|
|
31
|
+
}[];
|
|
32
|
+
seq: number;
|
|
33
|
+
seq_in_channel: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type CHANNEL_CREATE_TYPE = {
|
|
2
|
+
application_id?: string;
|
|
3
|
+
guild_id: string;
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
op_user_id: string;
|
|
7
|
+
owner_id: string;
|
|
8
|
+
parent_id?: string;
|
|
9
|
+
permissions?: string;
|
|
10
|
+
position?: number;
|
|
11
|
+
private_type: number;
|
|
12
|
+
speak_permission: number;
|
|
13
|
+
sub_type: number;
|
|
14
|
+
type: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type CHANNEL_DELETE_TYPE = {
|
|
2
|
+
application_id?: string;
|
|
3
|
+
guild_id: string;
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
op_user_id: string;
|
|
7
|
+
owner_id: string;
|
|
8
|
+
parent_id?: string;
|
|
9
|
+
permissions?: string;
|
|
10
|
+
position?: number;
|
|
11
|
+
private_type: number;
|
|
12
|
+
speak_permission: number;
|
|
13
|
+
sub_type: number;
|
|
14
|
+
type: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type CHANNEL_UPDATE_TYPE = {
|
|
2
|
+
application_id?: string;
|
|
3
|
+
guild_id: string;
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
op_user_id: string;
|
|
7
|
+
owner_id: string;
|
|
8
|
+
parent_id?: string;
|
|
9
|
+
permissions?: string;
|
|
10
|
+
position?: number;
|
|
11
|
+
private_type: number;
|
|
12
|
+
speak_permission: number;
|
|
13
|
+
sub_type: number;
|
|
14
|
+
type: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type DIRECT_MESSAGE_CREATE_TYPE = {
|
|
2
|
+
attachments?: {
|
|
3
|
+
content_type: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
height: number;
|
|
6
|
+
id: string;
|
|
7
|
+
size: number;
|
|
8
|
+
url: string;
|
|
9
|
+
width: number;
|
|
10
|
+
}[];
|
|
11
|
+
author: {
|
|
12
|
+
avatar: string;
|
|
13
|
+
bot: boolean;
|
|
14
|
+
id: string;
|
|
15
|
+
username: string;
|
|
16
|
+
};
|
|
17
|
+
channel_id: string;
|
|
18
|
+
content: string;
|
|
19
|
+
direct_message: boolean;
|
|
20
|
+
guild_id: string;
|
|
21
|
+
id: string;
|
|
22
|
+
member: {
|
|
23
|
+
joined_at: string;
|
|
24
|
+
};
|
|
25
|
+
seq: number;
|
|
26
|
+
seq_in_channel: string;
|
|
27
|
+
src_guild_id: string;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type DIRECT_MESSAGE_DELETE_TYPE = {
|
|
2
|
+
message: {
|
|
3
|
+
author: {
|
|
4
|
+
bot: boolean;
|
|
5
|
+
id: string;
|
|
6
|
+
username: string;
|
|
7
|
+
};
|
|
8
|
+
channel_id: string;
|
|
9
|
+
direct_message: boolean;
|
|
10
|
+
guild_id: string;
|
|
11
|
+
id: string;
|
|
12
|
+
src_guild_id: string;
|
|
13
|
+
};
|
|
14
|
+
op_user: {
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ERROR_TYPE = any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type GUILD_CREATE_TYPE = {
|
|
2
|
+
description: string;
|
|
3
|
+
icon: string;
|
|
4
|
+
id: string;
|
|
5
|
+
joined_at: string;
|
|
6
|
+
max_members: number;
|
|
7
|
+
member_count: number;
|
|
8
|
+
name: string;
|
|
9
|
+
op_user_id: string;
|
|
10
|
+
owner: boolean;
|
|
11
|
+
owner_id: string;
|
|
12
|
+
union_appid: string;
|
|
13
|
+
union_org_id: string;
|
|
14
|
+
union_world_id: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type GUILD_DELETE_TYPE = {
|
|
2
|
+
description: string;
|
|
3
|
+
icon: string;
|
|
4
|
+
id: string;
|
|
5
|
+
joined_at: string;
|
|
6
|
+
max_members: number;
|
|
7
|
+
member_count: number;
|
|
8
|
+
name: string;
|
|
9
|
+
op_user_id: string;
|
|
10
|
+
owner: boolean;
|
|
11
|
+
owner_id: string;
|
|
12
|
+
union_appid: string;
|
|
13
|
+
union_org_id: string;
|
|
14
|
+
union_world_id: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type GUILD_MEMBER_REMOVE_TYPE = {
|
|
2
|
+
guild_id: string;
|
|
3
|
+
joined_at: string;
|
|
4
|
+
nick: string;
|
|
5
|
+
op_user_id: string;
|
|
6
|
+
roles: string[];
|
|
7
|
+
source_type?: string;
|
|
8
|
+
user: {
|
|
9
|
+
avatar: string;
|
|
10
|
+
bot: number;
|
|
11
|
+
id: string;
|
|
12
|
+
username: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|