@alemonjs/onebot 0.1.1 → 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/README.md +1 -1
- package/lib/index-11.js +21 -26
- package/lib/index-12.js +23 -30
- package/lib/index.d.ts +8 -2
- 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/README.md
CHANGED
package/lib/index-11.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineBot, getConfig,
|
|
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;
|
|
@@ -26,7 +27,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
26
27
|
const uis = config.master_uids ?? [];
|
|
27
28
|
let msg = '';
|
|
28
29
|
const arr = [];
|
|
29
|
-
let at_users = []
|
|
30
|
+
// let at_users = []
|
|
30
31
|
for (const item of event.message) {
|
|
31
32
|
if (item.type == 'text') {
|
|
32
33
|
msg = item.data.text;
|
|
@@ -49,39 +50,30 @@ var INDEXV11 = defineBot(() => {
|
|
|
49
50
|
return url;
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
|
-
const
|
|
53
|
+
const UserId = String(event.user_id);
|
|
54
|
+
const UserKey = useUserHashKey({
|
|
55
|
+
Platform: platform,
|
|
56
|
+
UserId
|
|
57
|
+
});
|
|
53
58
|
// 定义消
|
|
54
59
|
const e = {
|
|
55
60
|
// 平台类型
|
|
56
|
-
Platform:
|
|
61
|
+
Platform: platform,
|
|
57
62
|
// 频道
|
|
58
63
|
GuildId: String(event.group_id),
|
|
59
64
|
// guild_name: event.group_name,
|
|
60
65
|
// 子频道
|
|
61
66
|
ChannelId: String(event.group_id),
|
|
62
|
-
// 是否是主人
|
|
63
67
|
IsMaster: uis.includes(String(event.user_id)),
|
|
64
|
-
|
|
65
|
-
UserId:
|
|
66
|
-
// 用户名
|
|
68
|
+
IsBot: false,
|
|
69
|
+
UserId: UserId,
|
|
67
70
|
UserName: event.sender.nickname,
|
|
68
71
|
UserKey,
|
|
69
|
-
// 用户头像
|
|
70
72
|
UserAvatar: UserAvatar,
|
|
71
|
-
//
|
|
73
|
+
// message
|
|
72
74
|
MessageId: String(event.message_id),
|
|
73
|
-
// 用户消息
|
|
74
|
-
MessageBody: [
|
|
75
|
-
Text(msg),
|
|
76
|
-
...at_users.map(item => At(item.id, 'user', {
|
|
77
|
-
name: item.name,
|
|
78
|
-
avatar: item.avatar,
|
|
79
|
-
bot: item.bot
|
|
80
|
-
}))
|
|
81
|
-
],
|
|
82
75
|
MessageText: msg,
|
|
83
76
|
// 用户openId
|
|
84
|
-
// 用户openId
|
|
85
77
|
OpenId: String(event.user_id),
|
|
86
78
|
// 创建时间
|
|
87
79
|
CreateAt: Date.now(),
|
|
@@ -117,15 +109,17 @@ var INDEXV11 = defineBot(() => {
|
|
|
117
109
|
client.on('ERROR', event => {
|
|
118
110
|
console.error('ERROR', event);
|
|
119
111
|
});
|
|
112
|
+
global.client = client;
|
|
120
113
|
return {
|
|
121
114
|
api: {
|
|
122
115
|
use: {
|
|
123
116
|
send: (event, val) => {
|
|
124
117
|
if (val.length < 0)
|
|
125
118
|
return Promise.all([]);
|
|
126
|
-
const content =
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
const content = val
|
|
120
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
121
|
+
.map(item => item.value)
|
|
122
|
+
.join('');
|
|
129
123
|
if (content) {
|
|
130
124
|
return Promise.all([content].map(item => client.sendGroupMessage({
|
|
131
125
|
group_id: event.ChannelId,
|
|
@@ -139,9 +133,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
139
133
|
]
|
|
140
134
|
})));
|
|
141
135
|
}
|
|
142
|
-
const images =
|
|
143
|
-
MessageBody: val
|
|
144
|
-
}, 'Image');
|
|
136
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value);
|
|
145
137
|
if (images) {
|
|
146
138
|
return Promise.all(images.map(item => client.sendGroupMessage({
|
|
147
139
|
group_id: event.ChannelId,
|
|
@@ -156,6 +148,9 @@ var INDEXV11 = defineBot(() => {
|
|
|
156
148
|
})));
|
|
157
149
|
}
|
|
158
150
|
return Promise.all([]);
|
|
151
|
+
},
|
|
152
|
+
mention: async () => {
|
|
153
|
+
return [];
|
|
159
154
|
}
|
|
160
155
|
}
|
|
161
156
|
}
|
package/lib/index-12.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineBot, getConfig,
|
|
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;
|
|
@@ -67,45 +68,34 @@ var INDEXV12 = defineBot(() => {
|
|
|
67
68
|
return url;
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
|
-
const
|
|
71
|
+
const UserId = String(event.user_id);
|
|
72
|
+
const UserKey = useUserHashKey({
|
|
73
|
+
Platform: platform,
|
|
74
|
+
UserId
|
|
75
|
+
});
|
|
71
76
|
// 定义消
|
|
72
77
|
const e = {
|
|
73
78
|
// 平台类型
|
|
74
|
-
Platform:
|
|
79
|
+
Platform: platform,
|
|
75
80
|
// 频道
|
|
76
81
|
GuildId: event.group_id,
|
|
77
82
|
// guild_name: event.group_name,
|
|
78
83
|
// 子频道
|
|
79
84
|
ChannelId: event.group_id,
|
|
80
|
-
//
|
|
85
|
+
// uyser
|
|
81
86
|
IsMaster: uis.includes(String(event.user_id)),
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
UserId: UserId,
|
|
88
|
+
IsBot: false,
|
|
84
89
|
UserKey,
|
|
85
|
-
// 用户名
|
|
86
90
|
UserName: event.sender.nickname,
|
|
87
|
-
// 用户头像
|
|
88
91
|
UserAvatar: UserAvatar,
|
|
89
|
-
//
|
|
92
|
+
// message
|
|
90
93
|
MessageId: event.message_id,
|
|
91
|
-
// 用户消息
|
|
92
|
-
MessageBody: [
|
|
93
|
-
Text(msg),
|
|
94
|
-
...at_users.map(item => At(item.id, 'user', {
|
|
95
|
-
name: item.name,
|
|
96
|
-
avatar: item.avatar,
|
|
97
|
-
bot: item.bot
|
|
98
|
-
}))
|
|
99
|
-
],
|
|
100
94
|
MessageText: msg,
|
|
101
|
-
// 表情
|
|
102
|
-
// 用户openId
|
|
103
95
|
OpenId: event.user_id,
|
|
104
|
-
//
|
|
105
|
-
tag: 'MESSAGES',
|
|
106
|
-
// 创建时间
|
|
107
96
|
CreateAt: Date.now(),
|
|
108
|
-
//
|
|
97
|
+
// ohther
|
|
98
|
+
tag: 'MESSAGES',
|
|
109
99
|
value: null
|
|
110
100
|
};
|
|
111
101
|
// 当访问的时候获取
|
|
@@ -135,15 +125,17 @@ var INDEXV12 = defineBot(() => {
|
|
|
135
125
|
client.on('ERROR', event => {
|
|
136
126
|
console.error(event);
|
|
137
127
|
});
|
|
128
|
+
global.client = client;
|
|
138
129
|
return {
|
|
139
130
|
api: {
|
|
140
131
|
use: {
|
|
141
132
|
send: (event, val) => {
|
|
142
133
|
if (val.length < 0)
|
|
143
134
|
return Promise.all([]);
|
|
144
|
-
const content =
|
|
145
|
-
|
|
146
|
-
|
|
135
|
+
const content = val
|
|
136
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
137
|
+
.map(item => item.value)
|
|
138
|
+
.join('');
|
|
147
139
|
if (content) {
|
|
148
140
|
return Promise.all([content].map(item => client.sendGroupMessage({
|
|
149
141
|
group_id: event.ChannelId,
|
|
@@ -157,9 +149,7 @@ var INDEXV12 = defineBot(() => {
|
|
|
157
149
|
]
|
|
158
150
|
})));
|
|
159
151
|
}
|
|
160
|
-
const images =
|
|
161
|
-
MessageBody: val
|
|
162
|
-
}, 'Image');
|
|
152
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value);
|
|
163
153
|
if (images) {
|
|
164
154
|
return Promise.all(images.map(item => client.sendGroupMessage({
|
|
165
155
|
group_id: event.ChannelId,
|
|
@@ -174,6 +164,9 @@ var INDEXV12 = defineBot(() => {
|
|
|
174
164
|
})));
|
|
175
165
|
}
|
|
176
166
|
return Promise.all([]);
|
|
167
|
+
},
|
|
168
|
+
mention: async () => {
|
|
169
|
+
return [];
|
|
177
170
|
}
|
|
178
171
|
}
|
|
179
172
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import * as alemonjs from 'alemonjs';
|
|
2
|
+
import { OneBotClient } from './sdk-v11/wss.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
declare const platform = "onebot";
|
|
5
|
+
type Client = OneBotClient;
|
|
6
|
+
declare const client: Client;
|
|
7
|
+
declare const _default: () => alemonjs.ClientAPI;
|
|
8
|
+
|
|
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 };
|