@alemonjs/onebot 0.1.0 → 0.1.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 +24 -11
- package/lib/index-12.js +24 -11
- package/lib/sdk-v11/wss.js +2 -2
- package/lib/sdk-v12/wss.js +2 -2
- package/package.json +1 -1
package/lib/index-11.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
1
|
+
import { defineBot, getConfig, createHash, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
2
2
|
import { OneBotClient } from './sdk-v11/wss.js';
|
|
3
3
|
|
|
4
4
|
var INDEXV11 = defineBot(() => {
|
|
@@ -35,6 +35,21 @@ var INDEXV11 = defineBot(() => {
|
|
|
35
35
|
for (const item of arr) {
|
|
36
36
|
msg = msg.replace(item.text, '').trim();
|
|
37
37
|
}
|
|
38
|
+
const url = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}`;
|
|
39
|
+
const UserAvatar = {
|
|
40
|
+
toBuffer: async () => {
|
|
41
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
42
|
+
return Buffer.from(arrayBuffer);
|
|
43
|
+
},
|
|
44
|
+
toBase64: async () => {
|
|
45
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
46
|
+
return Buffer.from(arrayBuffer).toString('base64');
|
|
47
|
+
},
|
|
48
|
+
toURL: async () => {
|
|
49
|
+
return url;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const UserKey = createHash(`onebot:${event.user_id}`);
|
|
38
53
|
// 定义消
|
|
39
54
|
const e = {
|
|
40
55
|
// 平台类型
|
|
@@ -46,17 +61,15 @@ var INDEXV11 = defineBot(() => {
|
|
|
46
61
|
ChannelId: String(event.group_id),
|
|
47
62
|
// 是否是主人
|
|
48
63
|
IsMaster: uis.includes(String(event.user_id)),
|
|
49
|
-
// 用户
|
|
64
|
+
// 用户Id
|
|
50
65
|
UserId: String(event.user_id),
|
|
51
|
-
GuildIdName: '',
|
|
52
|
-
GuildIdAvatar: '',
|
|
53
|
-
ChannelName: '',
|
|
54
66
|
// 用户名
|
|
55
67
|
UserName: event.sender.nickname,
|
|
68
|
+
UserKey,
|
|
56
69
|
// 用户头像
|
|
57
|
-
UserAvatar:
|
|
70
|
+
UserAvatar: UserAvatar,
|
|
58
71
|
// 格式化数据
|
|
59
|
-
|
|
72
|
+
MessageId: String(event.message_id),
|
|
60
73
|
// 用户消息
|
|
61
74
|
MessageBody: [
|
|
62
75
|
Text(msg),
|
|
@@ -69,7 +82,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
69
82
|
MessageText: msg,
|
|
70
83
|
// 用户openId
|
|
71
84
|
// 用户openId
|
|
72
|
-
|
|
85
|
+
OpenId: String(event.user_id),
|
|
73
86
|
// 创建时间
|
|
74
87
|
CreateAt: Date.now(),
|
|
75
88
|
// 标签
|
|
@@ -88,7 +101,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
88
101
|
});
|
|
89
102
|
client.on('DIRECT_MESSAGE', () => {
|
|
90
103
|
// const e = {
|
|
91
|
-
// isMaster: event.user_id ==
|
|
104
|
+
// isMaster: event.user_id == masterId,
|
|
92
105
|
// msg_txt: event.raw_message,
|
|
93
106
|
// msg: event.raw_message.trim(),
|
|
94
107
|
// msg_id: event.message_id,
|
|
@@ -114,7 +127,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
114
127
|
MessageBody: val
|
|
115
128
|
}, 'Text');
|
|
116
129
|
if (content) {
|
|
117
|
-
return Promise.all([content].map(item => client.
|
|
130
|
+
return Promise.all([content].map(item => client.sendGroupMessage({
|
|
118
131
|
group_id: event.ChannelId,
|
|
119
132
|
message: [
|
|
120
133
|
{
|
|
@@ -130,7 +143,7 @@ var INDEXV11 = defineBot(() => {
|
|
|
130
143
|
MessageBody: val
|
|
131
144
|
}, 'Image');
|
|
132
145
|
if (images) {
|
|
133
|
-
return Promise.all(images.map(item => client.
|
|
146
|
+
return Promise.all(images.map(item => client.sendGroupMessage({
|
|
134
147
|
group_id: event.ChannelId,
|
|
135
148
|
message: [
|
|
136
149
|
{
|
package/lib/index-12.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
1
|
+
import { defineBot, getConfig, createHash, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
2
2
|
import { OneBotClient } from './sdk-v12/wss.js';
|
|
3
3
|
|
|
4
4
|
var INDEXV12 = defineBot(() => {
|
|
@@ -53,6 +53,21 @@ var INDEXV12 = defineBot(() => {
|
|
|
53
53
|
for (const item of arr) {
|
|
54
54
|
msg = msg.replace(item.text, '').trim();
|
|
55
55
|
}
|
|
56
|
+
const url = event.platform == 'qq' ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}` : '';
|
|
57
|
+
const UserAvatar = {
|
|
58
|
+
toBuffer: async () => {
|
|
59
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
60
|
+
return Buffer.from(arrayBuffer);
|
|
61
|
+
},
|
|
62
|
+
toBase64: async () => {
|
|
63
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
64
|
+
return Buffer.from(arrayBuffer).toString('base64');
|
|
65
|
+
},
|
|
66
|
+
toURL: async () => {
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const UserKey = createHash(`onebot:${event.user_id}`);
|
|
56
71
|
// 定义消
|
|
57
72
|
const e = {
|
|
58
73
|
// 平台类型
|
|
@@ -64,17 +79,15 @@ var INDEXV12 = defineBot(() => {
|
|
|
64
79
|
ChannelId: event.group_id,
|
|
65
80
|
// 是否是主人
|
|
66
81
|
IsMaster: uis.includes(String(event.user_id)),
|
|
67
|
-
// 用户
|
|
82
|
+
// 用户Id
|
|
68
83
|
UserId: event.user_id,
|
|
84
|
+
UserKey,
|
|
69
85
|
// 用户名
|
|
70
86
|
UserName: event.sender.nickname,
|
|
71
|
-
GuildIdName: '',
|
|
72
|
-
GuildIdAvatar: '',
|
|
73
|
-
ChannelName: '',
|
|
74
87
|
// 用户头像
|
|
75
|
-
UserAvatar:
|
|
88
|
+
UserAvatar: UserAvatar,
|
|
76
89
|
// 格式化数据
|
|
77
|
-
|
|
90
|
+
MessageId: event.message_id,
|
|
78
91
|
// 用户消息
|
|
79
92
|
MessageBody: [
|
|
80
93
|
Text(msg),
|
|
@@ -87,7 +100,7 @@ var INDEXV12 = defineBot(() => {
|
|
|
87
100
|
MessageText: msg,
|
|
88
101
|
// 表情
|
|
89
102
|
// 用户openId
|
|
90
|
-
|
|
103
|
+
OpenId: event.user_id,
|
|
91
104
|
//
|
|
92
105
|
tag: 'MESSAGES',
|
|
93
106
|
// 创建时间
|
|
@@ -106,7 +119,7 @@ var INDEXV12 = defineBot(() => {
|
|
|
106
119
|
});
|
|
107
120
|
client.on('DIRECT_MESSAGE', () => {
|
|
108
121
|
// const e = {
|
|
109
|
-
// isMaster: event.user_id ==
|
|
122
|
+
// isMaster: event.user_id == masterId,
|
|
110
123
|
// msg_txt: event.raw_message,
|
|
111
124
|
// msg: event.raw_message.trim(),
|
|
112
125
|
// msg_id: event.message_id,
|
|
@@ -132,7 +145,7 @@ var INDEXV12 = defineBot(() => {
|
|
|
132
145
|
MessageBody: val
|
|
133
146
|
}, 'Text');
|
|
134
147
|
if (content) {
|
|
135
|
-
return Promise.all([content].map(item => client.
|
|
148
|
+
return Promise.all([content].map(item => client.sendGroupMessage({
|
|
136
149
|
group_id: event.ChannelId,
|
|
137
150
|
message: [
|
|
138
151
|
{
|
|
@@ -148,7 +161,7 @@ var INDEXV12 = defineBot(() => {
|
|
|
148
161
|
MessageBody: val
|
|
149
162
|
}, 'Image');
|
|
150
163
|
if (images) {
|
|
151
|
-
return Promise.all(images.map(item => client.
|
|
164
|
+
return Promise.all(images.map(item => client.sendGroupMessage({
|
|
152
165
|
group_id: event.ChannelId,
|
|
153
166
|
message: [
|
|
154
167
|
{
|
package/lib/sdk-v11/wss.js
CHANGED
|
@@ -111,7 +111,7 @@ class OneBotClient {
|
|
|
111
111
|
* @param options
|
|
112
112
|
* @returns
|
|
113
113
|
*/
|
|
114
|
-
|
|
114
|
+
sendGroupMessage(options) {
|
|
115
115
|
return this.#ws.send(JSON.stringify({
|
|
116
116
|
action: 'send_group_msg',
|
|
117
117
|
params: options,
|
|
@@ -122,7 +122,7 @@ class OneBotClient {
|
|
|
122
122
|
* @param options
|
|
123
123
|
* @returns
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
sendPrivateMessage(options) {
|
|
126
126
|
return this.#ws.send(JSON.stringify({
|
|
127
127
|
action: 'send_private_msg',
|
|
128
128
|
params: options,
|
package/lib/sdk-v12/wss.js
CHANGED
|
@@ -99,7 +99,7 @@ class OneBotClient {
|
|
|
99
99
|
* @param options
|
|
100
100
|
* @returns
|
|
101
101
|
*/
|
|
102
|
-
|
|
102
|
+
sendGroupMessage(options) {
|
|
103
103
|
return this.#ws.send(JSON.stringify({
|
|
104
104
|
action: 'send_group_msg',
|
|
105
105
|
params: options,
|
|
@@ -110,7 +110,7 @@ class OneBotClient {
|
|
|
110
110
|
* @param options
|
|
111
111
|
* @returns
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
sendPrivateMessage(options) {
|
|
114
114
|
return this.#ws.send(JSON.stringify({
|
|
115
115
|
action: 'send_private_msg',
|
|
116
116
|
params: options,
|