@alemonjs/onebot 0.2.0 → 0.2.1
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/lib/index-11.js +4 -3
- package/lib/index-12.js +4 -3
- package/lib/index.d.ts +5 -1
- package/lib/index.js +10 -1
- package/lib/sdk-v11/type.d.ts +90 -0
- package/lib/sdk-v11/wss.d.ts +53 -0
- package/package.json +1 -1
package/lib/index-11.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineBot, getConfig, useUserHashKey, OnProcessor } from 'alemonjs';
|
|
2
2
|
import { OneBotClient } from './sdk-v11/wss.js';
|
|
3
3
|
|
|
4
|
+
const platform = 'onebot';
|
|
4
5
|
var INDEXV11 = defineBot(() => {
|
|
5
6
|
const cfg = getConfig();
|
|
6
7
|
const config = cfg.value?.onebot;
|
|
@@ -13,7 +14,6 @@ var INDEXV11 = defineBot(() => {
|
|
|
13
14
|
// token
|
|
14
15
|
access_token: config?.token ?? ''
|
|
15
16
|
});
|
|
16
|
-
const Platform = 'onebot';
|
|
17
17
|
//
|
|
18
18
|
client.connect();
|
|
19
19
|
//
|
|
@@ -52,13 +52,13 @@ var INDEXV11 = defineBot(() => {
|
|
|
52
52
|
};
|
|
53
53
|
const UserId = String(event.user_id);
|
|
54
54
|
const UserKey = useUserHashKey({
|
|
55
|
-
Platform,
|
|
55
|
+
Platform: platform,
|
|
56
56
|
UserId
|
|
57
57
|
});
|
|
58
58
|
// 定义消
|
|
59
59
|
const e = {
|
|
60
60
|
// 平台类型
|
|
61
|
-
Platform:
|
|
61
|
+
Platform: platform,
|
|
62
62
|
// 频道
|
|
63
63
|
GuildId: String(event.group_id),
|
|
64
64
|
// guild_name: event.group_name,
|
|
@@ -109,6 +109,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
109
109
|
client.on('ERROR', event => {
|
|
110
110
|
console.error('ERROR', event);
|
|
111
111
|
});
|
|
112
|
+
global.client = client;
|
|
112
113
|
return {
|
|
113
114
|
api: {
|
|
114
115
|
use: {
|
package/lib/index-12.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineBot, getConfig, useUserHashKey, OnProcessor } from 'alemonjs';
|
|
2
2
|
import { OneBotClient } from './sdk-v12/wss.js';
|
|
3
3
|
|
|
4
|
+
const platform = 'onebot';
|
|
4
5
|
var INDEXV12 = defineBot(() => {
|
|
5
6
|
const cfg = getConfig();
|
|
6
7
|
const config = cfg.value?.onebot;
|
|
@@ -13,7 +14,6 @@ var INDEXV12 = defineBot(() => {
|
|
|
13
14
|
// token
|
|
14
15
|
access_token: config?.token ?? ''
|
|
15
16
|
});
|
|
16
|
-
const Platform = 'onebot';
|
|
17
17
|
//
|
|
18
18
|
client.connect();
|
|
19
19
|
//
|
|
@@ -70,13 +70,13 @@ var INDEXV12 = defineBot(() => {
|
|
|
70
70
|
};
|
|
71
71
|
const UserId = String(event.user_id);
|
|
72
72
|
const UserKey = useUserHashKey({
|
|
73
|
-
Platform,
|
|
73
|
+
Platform: platform,
|
|
74
74
|
UserId
|
|
75
75
|
});
|
|
76
76
|
// 定义消
|
|
77
77
|
const e = {
|
|
78
78
|
// 平台类型
|
|
79
|
-
Platform:
|
|
79
|
+
Platform: platform,
|
|
80
80
|
// 频道
|
|
81
81
|
GuildId: event.group_id,
|
|
82
82
|
// guild_name: event.group_name,
|
|
@@ -125,6 +125,7 @@ var INDEXV12 = defineBot(() => {
|
|
|
125
125
|
client.on('ERROR', event => {
|
|
126
126
|
console.error(event);
|
|
127
127
|
});
|
|
128
|
+
global.client = client;
|
|
128
129
|
return {
|
|
129
130
|
api: {
|
|
130
131
|
use: {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as alemonjs from 'alemonjs';
|
|
2
|
+
import { OneBotClient } from './sdk-v11/wss.js';
|
|
2
3
|
|
|
4
|
+
declare const platform = "onebot";
|
|
5
|
+
type Client = OneBotClient;
|
|
6
|
+
declare const client: Client;
|
|
3
7
|
declare const _default: () => alemonjs.ClientAPI;
|
|
4
8
|
|
|
5
|
-
export { _default as default };
|
|
9
|
+
export { type Client, client, _default as default, platform };
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,15 @@ import { defineBot, getConfig } from 'alemonjs';
|
|
|
2
2
|
import INDEXV12 from './index-12.js';
|
|
3
3
|
import INDEXV11 from './index-11.js';
|
|
4
4
|
|
|
5
|
+
const platform = 'onebot';
|
|
6
|
+
const client = new Proxy({}, {
|
|
7
|
+
get: (_, prop) => {
|
|
8
|
+
if (prop in global.client) {
|
|
9
|
+
return global.client[prop];
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
5
14
|
var index = defineBot(() => {
|
|
6
15
|
const cfg = getConfig();
|
|
7
16
|
const config = cfg.value?.onebot;
|
|
@@ -13,4 +22,4 @@ var index = defineBot(() => {
|
|
|
13
22
|
return INDEXV11();
|
|
14
23
|
});
|
|
15
24
|
|
|
16
|
-
export { index as default };
|
|
25
|
+
export { client, index as default, platform };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
interface Sender {
|
|
2
|
+
user_id: number;
|
|
3
|
+
nickname: string;
|
|
4
|
+
card: string;
|
|
5
|
+
role: 'admin' | 'member';
|
|
6
|
+
}
|
|
7
|
+
type Message = {
|
|
8
|
+
type: 'image';
|
|
9
|
+
data: {
|
|
10
|
+
file: string;
|
|
11
|
+
sub_type: number;
|
|
12
|
+
file_id: string;
|
|
13
|
+
url: string;
|
|
14
|
+
file_size: string;
|
|
15
|
+
file_unique: string;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
type: 'text';
|
|
19
|
+
data: {
|
|
20
|
+
text: string;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
type: 'json';
|
|
24
|
+
data: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'forward';
|
|
27
|
+
data: {
|
|
28
|
+
id: number;
|
|
29
|
+
content: any[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
interface MESSAGES_TYPE {
|
|
33
|
+
self_id: number;
|
|
34
|
+
user_id: number;
|
|
35
|
+
time: number;
|
|
36
|
+
message_id: number;
|
|
37
|
+
message_seq: number;
|
|
38
|
+
real_id: number;
|
|
39
|
+
message_type: 'group';
|
|
40
|
+
sender: Sender;
|
|
41
|
+
raw_message: string;
|
|
42
|
+
font: number;
|
|
43
|
+
sub_type: 'normal';
|
|
44
|
+
message: Message[];
|
|
45
|
+
message_format: 'array';
|
|
46
|
+
post_type: 'message';
|
|
47
|
+
group_id: number;
|
|
48
|
+
}
|
|
49
|
+
interface DIRECT_MESSAGE_TYPE {
|
|
50
|
+
self_id: number;
|
|
51
|
+
user_id: number;
|
|
52
|
+
time: number;
|
|
53
|
+
message_id: number;
|
|
54
|
+
message_seq: number;
|
|
55
|
+
real_id: number;
|
|
56
|
+
message_type: 'private';
|
|
57
|
+
sender: {
|
|
58
|
+
user_id: 1715713638;
|
|
59
|
+
nickname: string;
|
|
60
|
+
card: '';
|
|
61
|
+
};
|
|
62
|
+
raw_message: string;
|
|
63
|
+
font: 14;
|
|
64
|
+
sub_type: 'group' | 'friend';
|
|
65
|
+
message: Message[];
|
|
66
|
+
message_format: 'array';
|
|
67
|
+
post_type: 'message';
|
|
68
|
+
group_id: number;
|
|
69
|
+
temp_source: number;
|
|
70
|
+
}
|
|
71
|
+
interface meta_event_lifecycle {
|
|
72
|
+
time: number;
|
|
73
|
+
self_id: number;
|
|
74
|
+
post_type: 'meta_event';
|
|
75
|
+
meta_event_type: 'lifecycle';
|
|
76
|
+
sub_type: 'connect';
|
|
77
|
+
}
|
|
78
|
+
interface meta_event_heartbeat {
|
|
79
|
+
time: number;
|
|
80
|
+
self_id: number;
|
|
81
|
+
post_type: 'meta_event';
|
|
82
|
+
meta_event_type: 'heartbeat';
|
|
83
|
+
status: {
|
|
84
|
+
online: boolean;
|
|
85
|
+
good: boolean;
|
|
86
|
+
};
|
|
87
|
+
interval: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type { DIRECT_MESSAGE_TYPE, MESSAGES_TYPE, meta_event_heartbeat, meta_event_lifecycle };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DIRECT_MESSAGE_TYPE, MESSAGES_TYPE, meta_event_lifecycle, meta_event_heartbeat } from './type.js';
|
|
2
|
+
|
|
3
|
+
type OneBotEventMap = {
|
|
4
|
+
DIRECT_MESSAGE: DIRECT_MESSAGE_TYPE;
|
|
5
|
+
MESSAGES: MESSAGES_TYPE;
|
|
6
|
+
META: meta_event_lifecycle | meta_event_heartbeat;
|
|
7
|
+
ERROR: any;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 连接
|
|
11
|
+
*/
|
|
12
|
+
declare class OneBotClient {
|
|
13
|
+
#private;
|
|
14
|
+
/**
|
|
15
|
+
* 设置配置
|
|
16
|
+
* @param opstion
|
|
17
|
+
*/
|
|
18
|
+
constructor(opstion: {
|
|
19
|
+
url: string;
|
|
20
|
+
access_token: string;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* 注册事件处理程序
|
|
24
|
+
* @param key 事件名称
|
|
25
|
+
* @param val 事件处理函数
|
|
26
|
+
*/
|
|
27
|
+
on<T extends keyof OneBotEventMap>(key: T, val: (event: OneBotEventMap[T]) => any): this;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param cfg
|
|
31
|
+
* @param conversation
|
|
32
|
+
*/
|
|
33
|
+
connect(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param options
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
sendGroupMessage(options: {
|
|
40
|
+
group_id: number;
|
|
41
|
+
message: any[];
|
|
42
|
+
}): void;
|
|
43
|
+
/**
|
|
44
|
+
* @param options
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
sendPrivateMessage(options: {
|
|
48
|
+
user_id: number;
|
|
49
|
+
message: any[];
|
|
50
|
+
}): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { OneBotClient };
|