@alemonjs/qq-bot 2.1.31 → 2.1.33
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 +1950 -25
- package/dist/assets/index.css +1 -1
- package/dist/assets/index.js +3 -3
- package/dist/index.html +1 -1
- package/lib/config.d.ts +8 -0
- package/lib/config.js +23 -1
- package/lib/desktop.js +8 -1
- package/lib/hook.d.ts +2 -1
- package/lib/index.js +5 -8
- package/lib/index.webhook.js +3 -0
- package/lib/index.websoket.d.ts +2 -0
- package/lib/index.websoket.js +20 -18
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +7 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +7 -0
- package/lib/message/group/GROUP_JOIN_REQUEST.d.ts +23 -0
- package/lib/message/group/GROUP_JOIN_REQUEST.js +1 -0
- package/lib/message/group/GROUP_MESSAGE_CREATE.d.ts +7 -0
- package/lib/register.d.ts +10 -1
- package/lib/register.js +508 -53
- package/lib/sdk/api.d.ts +116 -3
- package/lib/sdk/api.js +390 -17
- package/lib/sdk/client.webhook.js +14 -14
- package/lib/sdk/client.websoket.d.ts +2 -1
- package/lib/sdk/client.websoket.js +321 -110
- package/lib/sdk/config.d.ts +3 -1
- package/lib/sdk/config.js +6 -2
- package/lib/sdk/instance.js +2 -0
- package/lib/sdk/intents.d.ts +1 -1
- package/lib/sdk/intents.js +2 -0
- package/lib/sdk/message.group.d.ts +2 -0
- package/lib/sdk/registry.d.ts +25 -0
- package/lib/sdk/registry.js +116 -0
- package/lib/sdk/session.d.ts +18 -0
- package/lib/sdk/session.js +56 -0
- package/lib/sdk/typing.d.ts +125 -1
- package/lib/sends.d.ts +6 -2
- package/lib/sends.js +136 -57
- package/lib/upload.d.ts +21 -0
- package/lib/upload.js +60 -0
- package/package.json +6 -5
package/dist/index.html
CHANGED
package/lib/config.d.ts
CHANGED
|
@@ -6,7 +6,15 @@ export type Options = {
|
|
|
6
6
|
master_id?: string[];
|
|
7
7
|
markdownToText?: boolean;
|
|
8
8
|
hideUnsupported?: boolean | number;
|
|
9
|
+
bots?: Record<string, Omit<sdkOptions, 'app_id'> & {
|
|
10
|
+
app_id?: string;
|
|
11
|
+
}>;
|
|
12
|
+
default_bot?: string;
|
|
9
13
|
} & sdkOptions;
|
|
10
14
|
export declare const getQQBotConfig: () => Options;
|
|
15
|
+
export declare const getQQBotBots: () => {
|
|
16
|
+
bots: Map<string, sdkOptions>;
|
|
17
|
+
defaultBot?: string;
|
|
18
|
+
};
|
|
11
19
|
export declare const getIdentity: (UserId: string) => readonly [boolean, string];
|
|
12
20
|
export declare const getMaster: (UserId: string) => readonly [boolean, string];
|
package/lib/config.js
CHANGED
|
@@ -8,6 +8,28 @@ const getQQBotConfig = () => {
|
|
|
8
8
|
const bagValue = value[platformFullName] || {};
|
|
9
9
|
return { ...commonValue, ...bagValue };
|
|
10
10
|
};
|
|
11
|
+
const getQQBotBots = () => {
|
|
12
|
+
const config = getQQBotConfig();
|
|
13
|
+
const { bots: configuredBots, default_bot, master_id: _masterId, master_key: _masterKey, markdownToText: _markdown, hideUnsupported: _hide, ...common } = config;
|
|
14
|
+
const bots = new Map();
|
|
15
|
+
if (configuredBots && Object.keys(configuredBots).length) {
|
|
16
|
+
for (const [botId, value] of Object.entries(configuredBots)) {
|
|
17
|
+
if (value.app_id && value.app_id !== botId)
|
|
18
|
+
throw new Error(`qq-bot bots.${botId}.app_id must match its map key`);
|
|
19
|
+
if (!value.secret)
|
|
20
|
+
throw new Error(`qq-bot bots.${botId}.secret is required`);
|
|
21
|
+
bots.set(botId, { ...common, ...value, app_id: botId, secret: value.secret });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (config.app_id && config.secret) {
|
|
25
|
+
bots.set(config.app_id, common);
|
|
26
|
+
}
|
|
27
|
+
if (bots.size > 1 && !default_bot)
|
|
28
|
+
throw new Error('qq-bot.default_bot is required when multiple bots are configured');
|
|
29
|
+
if (default_bot && !bots.has(default_bot))
|
|
30
|
+
throw new Error(`qq-bot.default_bot ${default_bot} is not configured`);
|
|
31
|
+
return { bots, defaultBot: default_bot || (bots.size === 1 ? bots.keys().next().value : undefined) };
|
|
32
|
+
};
|
|
11
33
|
const getIdentity = (UserId) => {
|
|
12
34
|
const isMasterUser = UserId ? isMaster(UserId, platform) : false;
|
|
13
35
|
const UserKey = createUserHashKey({
|
|
@@ -20,4 +42,4 @@ const getMaster = (UserId) => {
|
|
|
20
42
|
return getIdentity(UserId);
|
|
21
43
|
};
|
|
22
44
|
|
|
23
|
-
export { getIdentity, getMaster, getQQBotConfig, platform, platformFullName };
|
|
45
|
+
export { getIdentity, getMaster, getQQBotBots, getQQBotConfig, platform, platformFullName };
|
package/lib/desktop.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
|
|
|
2
2
|
import { dirname, join } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { getConfig, getConfigValue } from 'alemonjs';
|
|
5
|
+
import { getQQBotRegistry } from './index.websoket.js';
|
|
5
6
|
|
|
6
7
|
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
7
8
|
const activate = context => {
|
|
@@ -22,7 +23,7 @@ const activate = context => {
|
|
|
22
23
|
webView.onMessage(data => {
|
|
23
24
|
try {
|
|
24
25
|
if (data.type === 'qq-bot.form.save') {
|
|
25
|
-
const db = data.data;
|
|
26
|
+
const { bots_json: _botsJson, ...db } = data.data;
|
|
26
27
|
const config = getConfig();
|
|
27
28
|
const value = config.value ?? {};
|
|
28
29
|
value['qq-bot'] = {
|
|
@@ -43,6 +44,12 @@ const activate = context => {
|
|
|
43
44
|
data: config['qq-bot'] ?? {}
|
|
44
45
|
});
|
|
45
46
|
}
|
|
47
|
+
else if (data.type === 'qq-bot.status') {
|
|
48
|
+
webView.postMessage({
|
|
49
|
+
type: 'qq-bot.status',
|
|
50
|
+
data: getQQBotRegistry()?.getConnectionStatus() ?? { Platform: 'qq-bot', state: 'stopped', bots: [] }
|
|
51
|
+
});
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
catch (e) {
|
|
48
55
|
console.error(e);
|
package/lib/hook.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { C2C_MSG_RECEIVE_TYPE } from './message/group/C2C_MSG_RECEIVE';
|
|
|
31
31
|
import { C2C_MSG_REJECT_TYPE } from './message/group/C2C_MSG_REJECT';
|
|
32
32
|
import { MESSAGE_AUDIT_PASS_TYPE } from './message/group/MESSAGE_AUDIT_PASS';
|
|
33
33
|
import { MESSAGE_AUDIT_REJECT_TYPE } from './message/group/MESSAGE_AUDIT_REJECT';
|
|
34
|
+
import { GROUP_JOIN_REQUEST_TYPE } from './message/group/GROUP_JOIN_REQUEST';
|
|
34
35
|
type MAP = {
|
|
35
36
|
'message.create': GROUP_AT_MESSAGE_CREATE_TYPE | GROUP_MESSAGE_CREATE_TYPE | AT_MESSAGE_CREATE_TYPE | MESSAGE_CREATE_TYPE;
|
|
36
37
|
'private.message.create': DIRECT_MESSAGE_CREATE_TYPE | C2C_MESSAGE_CREATE_TYPE;
|
|
@@ -52,7 +53,7 @@ type MAP = {
|
|
|
52
53
|
'member.ban': undefined;
|
|
53
54
|
'member.unban': undefined;
|
|
54
55
|
'member.update': GUILD_MEMBER_UPDATE_TYPE;
|
|
55
|
-
'notice.create': GROUP_MSG_RECEIVE_TYPE | GROUP_MSG_REJECT_TYPE | MESSAGE_AUDIT_PASS_TYPE | MESSAGE_AUDIT_REJECT_TYPE;
|
|
56
|
+
'notice.create': GROUP_MSG_RECEIVE_TYPE | GROUP_MSG_REJECT_TYPE | MESSAGE_AUDIT_PASS_TYPE | MESSAGE_AUDIT_REJECT_TYPE | GROUP_JOIN_REQUEST_TYPE;
|
|
56
57
|
'private.message.update': undefined;
|
|
57
58
|
'private.message.delete': DIRECT_MESSAGE_DELETE_TYPE;
|
|
58
59
|
'private.friend.add': FRIEND_ADD_TYPE;
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { definePlatform
|
|
1
|
+
import { definePlatform } from 'alemonjs';
|
|
2
2
|
import { start } from './index.webhook.js';
|
|
3
3
|
import { start as start$1 } from './index.websoket.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getQQBotConfig } from './config.js';
|
|
5
|
+
export { platform } from './config.js';
|
|
5
6
|
export { useClient, useMode, useValue } from './hook.js';
|
|
6
7
|
export { QQBotAPI as API } from './sdk/api.js';
|
|
7
8
|
|
|
8
9
|
const main = () => {
|
|
9
|
-
|
|
10
|
-
if (!value) {
|
|
11
|
-
value = {};
|
|
12
|
-
}
|
|
13
|
-
const config = value[platform];
|
|
10
|
+
const config = getQQBotConfig();
|
|
14
11
|
if (config?.route || config?.port || config?.ws) {
|
|
15
12
|
start();
|
|
16
13
|
}
|
|
@@ -20,4 +17,4 @@ const main = () => {
|
|
|
20
17
|
};
|
|
21
18
|
var index = definePlatform({ main });
|
|
22
19
|
|
|
23
|
-
export { index as default
|
|
20
|
+
export { index as default };
|
package/lib/index.webhook.js
CHANGED
|
@@ -4,6 +4,9 @@ import { getQQBotConfig } from './config.js';
|
|
|
4
4
|
|
|
5
5
|
const start = () => {
|
|
6
6
|
const config = getQQBotConfig();
|
|
7
|
+
if (config.bots && Object.keys(config.bots).length > 1) {
|
|
8
|
+
throw new Error('qq-bot.bots is only supported by WebSocket mode; remove route/port/ws to use the QQ WebSocket gateway');
|
|
9
|
+
}
|
|
7
10
|
const { master_id: _, master_key: __, ...cfgConfig } = config;
|
|
8
11
|
const client = new QQBotClient({
|
|
9
12
|
...cfgConfig
|
package/lib/index.websoket.d.ts
CHANGED
package/lib/index.websoket.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getQQBotConfig } from './config.js';
|
|
1
|
+
import { getQQBotConfig, getQQBotBots } from './config.js';
|
|
2
|
+
import { QQBotRegistry } from './sdk/registry.js';
|
|
4
3
|
|
|
4
|
+
let activeRegistry;
|
|
5
|
+
const getQQBotRegistry = () => activeRegistry;
|
|
5
6
|
const start = () => {
|
|
6
7
|
const config = getQQBotConfig();
|
|
8
|
+
const { bots, defaultBot } = getQQBotBots();
|
|
9
|
+
const registry = new QQBotRegistry(defaultBot);
|
|
10
|
+
activeRegistry = registry;
|
|
7
11
|
const notPrivateIntents = [
|
|
8
12
|
'GUILDS',
|
|
9
13
|
'GUILD_MEMBERS',
|
|
@@ -19,27 +23,25 @@ const start = () => {
|
|
|
19
23
|
'DIRECT_MESSAGE',
|
|
20
24
|
'FORUMS_EVENT'
|
|
21
25
|
];
|
|
22
|
-
const isGroupIntents = ['GROUP_AND_C2C_EVENT'];
|
|
26
|
+
const isGroupIntents = ['GROUP_AND_C2C_EVENT', 'GROUP_MEMBER_EVENT'];
|
|
23
27
|
const pubIntents = ['INTERACTION'];
|
|
24
28
|
const intents = [];
|
|
25
29
|
if (config?.is_private) {
|
|
26
|
-
intents.push(...isPrivateIntents, ...pubIntents);
|
|
30
|
+
intents.push(...isPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
27
31
|
}
|
|
28
32
|
else {
|
|
29
33
|
intents.push(...notPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
30
34
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
void client.connect(config?.gatewayURL);
|
|
42
|
-
register(client);
|
|
35
|
+
for (const [botId, botConfig] of bots) {
|
|
36
|
+
const client = registry.add(botId, {
|
|
37
|
+
...botConfig,
|
|
38
|
+
intents: botConfig.intents || intents,
|
|
39
|
+
is_private: botConfig.is_private ?? false,
|
|
40
|
+
sandbox: botConfig.sandbox ?? false,
|
|
41
|
+
shard: botConfig.shard ?? [0, 1]
|
|
42
|
+
});
|
|
43
|
+
void client.connect(botConfig.gatewayURL);
|
|
44
|
+
}
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
export { start };
|
|
47
|
+
export { getQQBotRegistry, start };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type GROUP_JOIN_REQUEST_TYPE = {
|
|
2
|
+
group_openid: string;
|
|
3
|
+
join_request_id: string;
|
|
4
|
+
risk_tips?: string;
|
|
5
|
+
union_openid?: string;
|
|
6
|
+
member_openid: string;
|
|
7
|
+
username: string;
|
|
8
|
+
apply_at: string;
|
|
9
|
+
apply_source: string;
|
|
10
|
+
invited_by?: string;
|
|
11
|
+
bot: boolean;
|
|
12
|
+
verify_info?: {
|
|
13
|
+
method: string;
|
|
14
|
+
verify_message?: string;
|
|
15
|
+
review_qa_list?: {
|
|
16
|
+
question: string;
|
|
17
|
+
answer: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
auto_approved?: {
|
|
21
|
+
strategy_id: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/register.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import { cbpPlatform } from 'alemonjs';
|
|
1
2
|
import { QQBotClients } from './sdk/client.websoket';
|
|
2
|
-
export
|
|
3
|
+
export type QQBotRegistration = {
|
|
4
|
+
onAction: (data: any, consume: (result: any[]) => void) => Promise<void>;
|
|
5
|
+
onApi: (data: any, consume: (result: any[]) => void) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const register: (client: QQBotClients, options?: {
|
|
8
|
+
botId?: string;
|
|
9
|
+
cbp?: ReturnType<typeof cbpPlatform>;
|
|
10
|
+
bindActions?: boolean;
|
|
11
|
+
}) => QQBotRegistration;
|