@alemonjs/onebot 2.1.0-alpha.5 → 2.1.0-alpha.7
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.js +11 -12
- package/lib/sdk/wss.js +5 -11
- package/package.json +4 -1
package/lib/index.js
CHANGED
|
@@ -20,7 +20,7 @@ var index = () => {
|
|
|
20
20
|
reverse_port: config?.reverse_port ?? 17158
|
|
21
21
|
});
|
|
22
22
|
client.connect();
|
|
23
|
-
const url = `ws://127.0.0.1:${process.env?.port ||
|
|
23
|
+
const url = `ws://127.0.0.1:${process.env?.port || 17117}`;
|
|
24
24
|
const cbp = cbpPlatform(url);
|
|
25
25
|
const createUserAvatar = (id) => {
|
|
26
26
|
return `https://q1.qlogo.cn/g?b=qq&s=0&nk=${id}`;
|
|
@@ -91,15 +91,18 @@ var index = () => {
|
|
|
91
91
|
};
|
|
92
92
|
cbp.send(e);
|
|
93
93
|
});
|
|
94
|
-
// 错误处理
|
|
95
|
-
client.on('ERROR', event => {
|
|
96
|
-
logger.error(event);
|
|
97
|
-
});
|
|
98
94
|
/**
|
|
99
95
|
* @param val
|
|
100
96
|
* @returns
|
|
101
97
|
*/
|
|
102
98
|
const DataToMessage = async (val = []) => {
|
|
99
|
+
// 空元素
|
|
100
|
+
const empty = {
|
|
101
|
+
type: 'text',
|
|
102
|
+
data: {
|
|
103
|
+
text: ''
|
|
104
|
+
}
|
|
105
|
+
};
|
|
103
106
|
const message = await Promise.all(val.map(async (item) => {
|
|
104
107
|
if (item.type == 'Text') {
|
|
105
108
|
return {
|
|
@@ -124,16 +127,11 @@ var index = () => {
|
|
|
124
127
|
return {
|
|
125
128
|
type: 'at',
|
|
126
129
|
data: {
|
|
127
|
-
qq: item.value
|
|
130
|
+
qq: item.value
|
|
128
131
|
}
|
|
129
132
|
};
|
|
130
133
|
}
|
|
131
|
-
return
|
|
132
|
-
type: 'text',
|
|
133
|
-
data: {
|
|
134
|
-
text: ''
|
|
135
|
-
}
|
|
136
|
-
};
|
|
134
|
+
return empty;
|
|
137
135
|
}
|
|
138
136
|
else if (item.type == 'Image') {
|
|
139
137
|
return {
|
|
@@ -161,6 +159,7 @@ var index = () => {
|
|
|
161
159
|
}
|
|
162
160
|
};
|
|
163
161
|
}
|
|
162
|
+
return empty;
|
|
164
163
|
}));
|
|
165
164
|
return message;
|
|
166
165
|
};
|
package/lib/sdk/wss.js
CHANGED
|
@@ -51,8 +51,7 @@ class OneBotClient extends OneBotAPI {
|
|
|
51
51
|
try {
|
|
52
52
|
const event = JSON.parse(data.toString());
|
|
53
53
|
if (!event) {
|
|
54
|
-
|
|
55
|
-
this.#events['ERROR'](event);
|
|
54
|
+
logger.error('[OneBot] WebSocket message is empty');
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
58
57
|
else if (event?.post_type == 'meta_event') {
|
|
@@ -102,16 +101,11 @@ class OneBotClient extends OneBotAPI {
|
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
catch (err) {
|
|
105
|
-
|
|
106
|
-
this.#events['ERROR'](err);
|
|
104
|
+
logger.error('[OneBot] WebSocket error: ', err);
|
|
107
105
|
}
|
|
108
106
|
};
|
|
109
107
|
const onClose = (code, reason) => {
|
|
110
|
-
|
|
111
|
-
this.#events['ERROR']({
|
|
112
|
-
de: code,
|
|
113
|
-
reason: reason.toString('utf8')
|
|
114
|
-
});
|
|
108
|
+
logger.error(`[OneBot] WebSocket closed: ${code} - ${reason.toString('utf8')}`);
|
|
115
109
|
};
|
|
116
110
|
if (!this.ws) {
|
|
117
111
|
if (reverse_enable) {
|
|
@@ -123,14 +117,14 @@ class OneBotClient extends OneBotAPI {
|
|
|
123
117
|
this.ws.on('message', onMessage);
|
|
124
118
|
// close
|
|
125
119
|
this.ws.on('close', onClose);
|
|
126
|
-
|
|
120
|
+
logger.info(`[OneBot] connected: ws://127.0.0.1:${reverse_port}`);
|
|
127
121
|
});
|
|
128
122
|
}
|
|
129
123
|
else {
|
|
130
124
|
// forward_open
|
|
131
125
|
this.ws = new WebSocket(url, c);
|
|
132
126
|
this.ws.on('open', () => {
|
|
133
|
-
|
|
127
|
+
logger.info(`[OneBot] connected: ${url}`);
|
|
134
128
|
});
|
|
135
129
|
// message
|
|
136
130
|
this.ws.on('message', onMessage);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/onebot",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.7",
|
|
4
4
|
"description": "onebot v11",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"ws": "^8.18.1"
|
|
25
25
|
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"alemonjs": "^2.1.0-alpha.15"
|
|
28
|
+
},
|
|
26
29
|
"alemonjs": {
|
|
27
30
|
"desktop": {
|
|
28
31
|
"platform": [
|