alemonjs 1.1.13 → 1.1.15
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/discord/alemon/conversation.js +0 -1
- package/lib/discord/alemon/reply.js +3 -15
- package/lib/kook/alemon/controller.js +9 -6
- package/lib/kook/alemon/direct.js +11 -17
- package/lib/kook/alemon/reply.js +11 -17
- package/lib/ntqq/alemon/group/controller.js +4 -3
- package/lib/ntqq/alemon/group/direct.js +18 -22
- package/lib/ntqq/alemon/group/reply.js +39 -45
- package/lib/qq/alemon/controller.js +53 -23
- package/lib/qq/alemon/direct.js +17 -27
- package/lib/qq/alemon/reply.js +11 -23
- package/lib/villa/alemon/controller.js +11 -8
- package/lib/villa/alemon/reply.js +43 -54
- package/lib/villa/sdk/api.js +1 -1
- package/lib/villa/sdk/reply.js +38 -213
- package/lib/villa/sdk/wss.js +15 -6
- package/lib/villa/villa.js +0 -2
- package/package.json +3 -3
- package/types/config/login.d.ts +1 -1
- package/types/core/dealmsg.d.ts +1 -1
- package/types/discord/alemon/controller.d.ts +1 -1
- package/types/kook/alemon/controller.d.ts +7 -67
- package/types/kook/alemon/direct.d.ts +1 -1
- package/types/kook/alemon/message/DIRECT_MESSAGE.d.ts +1 -1
- package/types/kook/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +1 -1
- package/types/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +1 -1
- package/types/ntqq/alemon/group/controller.d.ts +5 -17
- package/types/ntqq/alemon/group/direct.d.ts +1 -1
- package/types/one/alemon/message/DIRECT_MESSAGE.d.ts +1 -1
- package/types/one/alemon/message/MESSAGES.d.ts +1 -1
- package/types/qq/alemon/controller.d.ts +11 -11
- package/types/qq/alemon/direct.d.ts +1 -1
- package/types/villa/sdk/api.d.ts +2 -2
- package/types/villa/sdk/reply.d.ts +15 -58
- package/types/villa/sdk/types.d.ts +39 -10
- package/types/villa/sdk/utils.d.ts +1 -1
- package/types/villa/villa.d.ts +0 -10
package/lib/qq/alemon/reply.js
CHANGED
|
@@ -12,17 +12,11 @@ export async function replyController(msg, channel_id, msg_id, select) {
|
|
|
12
12
|
// isBuffer
|
|
13
13
|
// if withdraw == 0 , false 不撤回
|
|
14
14
|
if (Buffer.isBuffer(msg)) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}).catch(everyoneError);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
console.error(err);
|
|
24
|
-
return err;
|
|
25
|
-
}
|
|
15
|
+
return await Client.postImage({
|
|
16
|
+
id: channel_id,
|
|
17
|
+
msg_id: msg_id, //消息id, 必须,不然就是主动消息了
|
|
18
|
+
image: msg //buffer
|
|
19
|
+
}).catch(everyoneError);
|
|
26
20
|
}
|
|
27
21
|
// arr & find buffer
|
|
28
22
|
if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
|
|
@@ -35,18 +29,12 @@ export async function replyController(msg, channel_id, msg_id, select) {
|
|
|
35
29
|
})
|
|
36
30
|
.filter(element => typeof element === 'string')
|
|
37
31
|
.join('');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}).catch(everyoneError);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
console.error(err);
|
|
48
|
-
return err;
|
|
49
|
-
}
|
|
32
|
+
return await Client.postImage({
|
|
33
|
+
id: channel_id,
|
|
34
|
+
msg_id: msg_id, //消息id, 必须
|
|
35
|
+
image: msg[isBuffer], //buffer
|
|
36
|
+
content: cont
|
|
37
|
+
}).catch(everyoneError);
|
|
50
38
|
}
|
|
51
39
|
const content = Array.isArray(msg)
|
|
52
40
|
? msg.join('')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ClientVILLA } from '../sdk/index.js';
|
|
2
2
|
import { replyController } from './reply.js';
|
|
3
3
|
import { getBotConfigByKey } from '../../config/index.js';
|
|
4
|
+
import { everyoneError } from '../../log/index.js';
|
|
4
5
|
export const Controller = {
|
|
5
6
|
Member: ({ guild_id, user_id }) => {
|
|
6
7
|
return {
|
|
@@ -10,7 +11,9 @@ export const Controller = {
|
|
|
10
11
|
*/
|
|
11
12
|
information: async () => {
|
|
12
13
|
// 对进行进行过滤,并以固定格式返回
|
|
13
|
-
const data = await ClientVILLA.getMember(guild_id, user_id)
|
|
14
|
+
const data = await ClientVILLA.getMember(guild_id, user_id)
|
|
15
|
+
.then(res => res.data)
|
|
16
|
+
.catch(everyoneError);
|
|
14
17
|
if (!data)
|
|
15
18
|
return false;
|
|
16
19
|
const cfg = getBotConfigByKey('villa');
|
|
@@ -36,7 +39,7 @@ export const Controller = {
|
|
|
36
39
|
* 踢出
|
|
37
40
|
*/
|
|
38
41
|
remove: async () => {
|
|
39
|
-
return await ClientVILLA.deleteVillaMember(guild_id, user_id);
|
|
42
|
+
return await ClientVILLA.deleteVillaMember(guild_id, user_id).catch(everyoneError);
|
|
40
43
|
},
|
|
41
44
|
/**
|
|
42
45
|
* 身分组
|
|
@@ -49,7 +52,7 @@ export const Controller = {
|
|
|
49
52
|
role_id,
|
|
50
53
|
uid: user_id,
|
|
51
54
|
is_add: add
|
|
52
|
-
});
|
|
55
|
+
}).catch(everyoneError);
|
|
53
56
|
}
|
|
54
57
|
};
|
|
55
58
|
},
|
|
@@ -66,7 +69,7 @@ export const Controller = {
|
|
|
66
69
|
console.error('VILLA 无私信');
|
|
67
70
|
return false;
|
|
68
71
|
}
|
|
69
|
-
return await replyController(guild_id, channel_id, content);
|
|
72
|
+
return await replyController(guild_id, channel_id, content).catch(everyoneError);
|
|
70
73
|
},
|
|
71
74
|
/**
|
|
72
75
|
* 引用
|
|
@@ -80,7 +83,7 @@ export const Controller = {
|
|
|
80
83
|
}
|
|
81
84
|
return await replyController(guild_id, channel_id, content, {
|
|
82
85
|
quote: msg_id
|
|
83
|
-
});
|
|
86
|
+
}).catch(everyoneError);
|
|
84
87
|
},
|
|
85
88
|
/**
|
|
86
89
|
* 更新信息
|
|
@@ -98,7 +101,7 @@ export const Controller = {
|
|
|
98
101
|
return await ClientVILLA.recallMessage(guild_id, {
|
|
99
102
|
room_id: channel_id,
|
|
100
103
|
msg_uid: msg_id
|
|
101
|
-
});
|
|
104
|
+
}).catch(everyoneError);
|
|
102
105
|
},
|
|
103
106
|
/**
|
|
104
107
|
* 钉选
|
|
@@ -110,7 +113,7 @@ export const Controller = {
|
|
|
110
113
|
room_id: channel_id,
|
|
111
114
|
is_cancel: cancel,
|
|
112
115
|
msg_uid: msg_id
|
|
113
|
-
});
|
|
116
|
+
}).catch(everyoneError);
|
|
114
117
|
},
|
|
115
118
|
/**
|
|
116
119
|
* 喇叭
|
|
@@ -161,7 +164,7 @@ export const Controller = {
|
|
|
161
164
|
card: async (msg) => {
|
|
162
165
|
const arr = [];
|
|
163
166
|
for (const item of msg) {
|
|
164
|
-
arr.push(await ClientVILLA.
|
|
167
|
+
arr.push(await ClientVILLA.sendCard(guild_id, channel_id, item));
|
|
165
168
|
}
|
|
166
169
|
return arr;
|
|
167
170
|
},
|
|
@@ -10,28 +10,35 @@ import { getUrlbuffer } from '../../core/index.js';
|
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
12
|
export async function replyController(villa_id, room_id, msg, select) {
|
|
13
|
-
|
|
14
|
-
* isBuffer
|
|
15
|
-
*/
|
|
13
|
+
// isBuffer
|
|
16
14
|
if (Buffer.isBuffer(msg)) {
|
|
17
|
-
|
|
18
|
-
* 上传图片
|
|
19
|
-
*/
|
|
15
|
+
// 上传图片
|
|
20
16
|
const url = await ClientVILLA.uploadImage(villa_id, msg).then(res => res?.data?.url);
|
|
21
17
|
if (!url)
|
|
22
18
|
return false;
|
|
23
19
|
const dimensions = IMGS.imageSize(msg);
|
|
24
|
-
return await ClientVILLA.
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
return await ClientVILLA.replyMessage(villa_id, room_id, {
|
|
21
|
+
images: [
|
|
22
|
+
{
|
|
23
|
+
url,
|
|
24
|
+
width: dimensions.width,
|
|
25
|
+
height: dimensions.height
|
|
26
|
+
}
|
|
27
|
+
]
|
|
27
28
|
}, select?.quote).catch(everyoneError);
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
* isString arr and find buffer
|
|
31
|
-
*/
|
|
30
|
+
// isString arr and find buffer
|
|
32
31
|
if (Array.isArray(msg) && msg.find(item => Buffer.isBuffer(item))) {
|
|
33
|
-
|
|
34
|
-
const
|
|
32
|
+
const buffers = msg.filter(item => Buffer.isBuffer(item));
|
|
33
|
+
const images = [];
|
|
34
|
+
for (const item of buffers) {
|
|
35
|
+
const ISize = IMGS.imageSize(item);
|
|
36
|
+
images.push({
|
|
37
|
+
url: await ClientVILLA.uploadImage(villa_id, item).then(res => res?.data?.url),
|
|
38
|
+
width: ISize.width,
|
|
39
|
+
height: ISize.height
|
|
40
|
+
});
|
|
41
|
+
}
|
|
35
42
|
// 删除所有buffer
|
|
36
43
|
const cont = msg
|
|
37
44
|
.map(item => {
|
|
@@ -41,28 +48,10 @@ export async function replyController(villa_id, room_id, msg, select) {
|
|
|
41
48
|
})
|
|
42
49
|
.filter(element => typeof element === 'string')
|
|
43
50
|
.join('');
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
-
const url = await ClientVILLA.uploadImage(villa_id, msg[isBuffer]).then(res => res?.data?.url);
|
|
50
|
-
if (!url)
|
|
51
|
-
return false;
|
|
52
|
-
// 识别大小
|
|
53
|
-
const dimensions = IMGS.imageSize(msg[isBuffer]);
|
|
54
|
-
if (entities.length == 0) {
|
|
55
|
-
return await ClientVILLA.sendMessageTextUrl(villa_id, room_id, content, url, {
|
|
56
|
-
width: dimensions.width,
|
|
57
|
-
height: dimensions.height
|
|
58
|
-
}, select?.quote).catch(everyoneError);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return await ClientVILLA.sendMessageTextEntitiesUrl(villa_id, room_id, content, entities, url, {
|
|
62
|
-
width: dimensions.width,
|
|
63
|
-
height: dimensions.height
|
|
64
|
-
}, select?.quote).catch(everyoneError);
|
|
65
|
-
}
|
|
51
|
+
return await ClientVILLA.replyMessage(villa_id, room_id, {
|
|
52
|
+
msg: cont,
|
|
53
|
+
images: images
|
|
54
|
+
}, select?.quote).catch(everyoneError);
|
|
66
55
|
}
|
|
67
56
|
// string and string[]
|
|
68
57
|
const cont = Array.isArray(msg)
|
|
@@ -80,28 +69,28 @@ export async function replyController(villa_id, room_id, msg, select) {
|
|
|
80
69
|
const match = cont.match(/<http>(.*?)<\/http>/);
|
|
81
70
|
if (match) {
|
|
82
71
|
const getUrl = match[1];
|
|
83
|
-
//
|
|
84
|
-
const url = await ClientVILLA.transferImage(villa_id, getUrl).then(res => res?.data?.new_url);
|
|
85
|
-
if (!url)
|
|
86
|
-
return false;
|
|
72
|
+
// 先请求确保图片正常
|
|
87
73
|
const msg = await getUrlbuffer(getUrl);
|
|
88
74
|
if (!msg)
|
|
89
75
|
return false;
|
|
90
|
-
// 如果是直接的url,应该直接使用转存
|
|
91
76
|
const dimensions = IMGS.imageSize(msg);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
77
|
+
// url 形式的直接转存
|
|
78
|
+
const url = await ClientVILLA.transferImage(villa_id, getUrl).then(res => res?.data?.new_url);
|
|
79
|
+
// 如果是直接的url,应该直接使用转存
|
|
80
|
+
const images = [
|
|
81
|
+
{
|
|
82
|
+
url,
|
|
83
|
+
width: dimensions.width,
|
|
84
|
+
height: dimensions.height
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const contreplace = cont.replace(/<http>(.*?)<\/http>/, '');
|
|
88
|
+
return await ClientVILLA.replyMessage(villa_id, room_id, {
|
|
89
|
+
msg: contreplace == '' ? undefined : contreplace,
|
|
90
|
+
images: images
|
|
95
91
|
}, select?.quote).catch(everyoneError);
|
|
96
92
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const { entities, content } = await ClientVILLA.stringParsing(cont, villa_id);
|
|
101
|
-
if (entities.length == 0 && content != '') {
|
|
102
|
-
return await ClientVILLA.sendMessageText(villa_id, room_id, content, select?.quote).catch(everyoneError);
|
|
103
|
-
}
|
|
104
|
-
else if (entities.length != 0 && content != '') {
|
|
105
|
-
return await ClientVILLA.sendMessageTextEntities(villa_id, room_id, content, entities, select?.quote).catch(everyoneError);
|
|
106
|
-
}
|
|
93
|
+
return await ClientVILLA.replyMessage(villa_id, room_id, {
|
|
94
|
+
msg: cont
|
|
95
|
+
}, select?.quote).catch(everyoneError);
|
|
107
96
|
}
|
package/lib/villa/sdk/api.js
CHANGED
|
@@ -242,7 +242,7 @@ export async function sendMessage(villa_id, data) {
|
|
|
242
242
|
* @param panel 消息组件面板json序列化后得到的字符串
|
|
243
243
|
* @returns
|
|
244
244
|
*/
|
|
245
|
-
export async function
|
|
245
|
+
export async function sendCard(villa_id, room_id, content) {
|
|
246
246
|
return await sendMessage(villa_id, {
|
|
247
247
|
room_id,
|
|
248
248
|
object_name: 'MHY:Text',
|
package/lib/villa/sdk/reply.js
CHANGED
|
@@ -1,237 +1,62 @@
|
|
|
1
1
|
import { sendMessage } from './api.js';
|
|
2
|
+
import { stringParsing } from './mechanism.js';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param room_id 房间
|
|
6
|
-
* @param url 图片地址
|
|
7
|
-
* @param size 图片配置
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export async function sendMessageImage(villa_id, room_id, url, size, msg_id) {
|
|
11
|
-
let data = {
|
|
12
|
-
/**
|
|
13
|
-
* 消息文本 支持 [爱心] 来转换成表情
|
|
14
|
-
*/
|
|
15
|
-
content: {
|
|
16
|
-
url,
|
|
17
|
-
size
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
if (msg_id) {
|
|
21
|
-
const [id, at] = String(msg_id).split('.');
|
|
22
|
-
data = {
|
|
23
|
-
...data,
|
|
24
|
-
...{
|
|
25
|
-
quote: {
|
|
26
|
-
original_message_id: id,
|
|
27
|
-
original_message_send_time: Number(at),
|
|
28
|
-
quoted_message_id: id,
|
|
29
|
-
quoted_message_send_time: Number(at)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return await sendMessage(villa_id, {
|
|
35
|
-
/**
|
|
36
|
-
* 房间号
|
|
37
|
-
*/
|
|
38
|
-
room_id,
|
|
39
|
-
/**
|
|
40
|
-
* 消息类型 */
|
|
41
|
-
object_name: 'MHY:Image',
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
msg_content: JSON.stringify(data)
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 消息发送
|
|
50
|
-
* @param villa_id 别野
|
|
51
|
-
* @param room_id 房间
|
|
52
|
-
* @param text 文本
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
export async function sendMessageText(villa_id, room_id, text, msg_id) {
|
|
56
|
-
let data = {
|
|
57
|
-
content: {
|
|
58
|
-
text
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
if (msg_id) {
|
|
62
|
-
const [id, at] = String(msg_id).split('.');
|
|
63
|
-
data = {
|
|
64
|
-
...data,
|
|
65
|
-
...{
|
|
66
|
-
quote: {
|
|
67
|
-
original_message_id: id,
|
|
68
|
-
original_message_send_time: Number(at),
|
|
69
|
-
quoted_message_id: id,
|
|
70
|
-
quoted_message_send_time: Number(at)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return await sendMessage(villa_id, {
|
|
76
|
-
/**
|
|
77
|
-
* 房间号
|
|
78
|
-
*/
|
|
79
|
-
room_id,
|
|
80
|
-
object_name: 'MHY:Text',
|
|
81
|
-
msg_content: JSON.stringify(data)
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 消息发送
|
|
86
|
-
* @param villa_id 别野
|
|
87
|
-
* @param room_id 房间
|
|
88
|
-
* @param text 文本
|
|
89
|
-
* @param entities 渲染
|
|
4
|
+
* 数据序列化
|
|
5
|
+
* @param data
|
|
90
6
|
* @returns
|
|
91
7
|
*/
|
|
92
|
-
export
|
|
93
|
-
|
|
94
|
-
content: {
|
|
95
|
-
text,
|
|
96
|
-
entities
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
if (msg_id) {
|
|
100
|
-
const [id, at] = String(msg_id).split('.');
|
|
101
|
-
data = {
|
|
102
|
-
...data,
|
|
103
|
-
...{
|
|
104
|
-
quote: {
|
|
105
|
-
original_message_id: id,
|
|
106
|
-
original_message_send_time: Number(at),
|
|
107
|
-
quoted_message_id: id,
|
|
108
|
-
quoted_message_send_time: Number(at)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return await sendMessage(villa_id, {
|
|
114
|
-
room_id,
|
|
115
|
-
object_name: 'MHY:Text',
|
|
116
|
-
msg_content: JSON.stringify(data)
|
|
117
|
-
});
|
|
8
|
+
export function stringify(data) {
|
|
9
|
+
return JSON.stringify(data);
|
|
118
10
|
}
|
|
119
11
|
/**
|
|
120
12
|
* 消息发送
|
|
121
13
|
* @param villa_id 别野
|
|
122
14
|
* @param room_id 房间
|
|
123
|
-
* @param
|
|
124
|
-
* @param
|
|
125
|
-
* @param size 图片配置
|
|
15
|
+
* @param m {msg:文本 images:{ url size }}
|
|
16
|
+
* @param msg_id 消息编号
|
|
126
17
|
* @returns
|
|
127
18
|
*/
|
|
128
|
-
export async function
|
|
129
|
-
|
|
130
|
-
content:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
url,
|
|
135
|
-
...size
|
|
136
|
-
}
|
|
137
|
-
]
|
|
138
|
-
}
|
|
19
|
+
export async function replyMessage(villa_id, room_id, m, msg_id) {
|
|
20
|
+
const data = {
|
|
21
|
+
content: undefined,
|
|
22
|
+
panel: m?.panel,
|
|
23
|
+
quote: undefined
|
|
139
24
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
quoted_message_id: id,
|
|
149
|
-
quoted_message_send_time: Number(at)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
25
|
+
let object_name = 'MHY:Text';
|
|
26
|
+
if (m?.msg || m?.images?.length > 1) {
|
|
27
|
+
// 文字模式
|
|
28
|
+
const { entities, content } = await stringParsing(m.msg, villa_id);
|
|
29
|
+
data.content = {
|
|
30
|
+
text: content,
|
|
31
|
+
entities,
|
|
32
|
+
images: m?.images ?? []
|
|
152
33
|
};
|
|
153
34
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* @param text 文本
|
|
165
|
-
* @param images 图片集
|
|
166
|
-
* @returns
|
|
167
|
-
*/
|
|
168
|
-
export async function sendMessageTextImages(villa_id, room_id, text, images, msg_id) {
|
|
169
|
-
let data = {
|
|
170
|
-
content: {
|
|
171
|
-
text,
|
|
172
|
-
images
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
if (msg_id) {
|
|
176
|
-
const [id, at] = String(msg_id).split('.');
|
|
177
|
-
data = {
|
|
178
|
-
...data,
|
|
179
|
-
...{
|
|
180
|
-
quote: {
|
|
181
|
-
original_message_id: id,
|
|
182
|
-
original_message_send_time: Number(at),
|
|
183
|
-
quoted_message_id: id,
|
|
184
|
-
quoted_message_send_time: Number(at)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
35
|
+
else {
|
|
36
|
+
// 图片模式
|
|
37
|
+
data.content = {
|
|
38
|
+
url: m.images[0].url,
|
|
39
|
+
size: m.images[0]?.width && m.images[0]?.height
|
|
40
|
+
? {
|
|
41
|
+
width: m.images[0]?.width,
|
|
42
|
+
height: m.images[0]?.height
|
|
43
|
+
}
|
|
44
|
+
: undefined
|
|
187
45
|
};
|
|
46
|
+
object_name = 'MHY:Image';
|
|
188
47
|
}
|
|
189
|
-
return await sendMessage(villa_id, {
|
|
190
|
-
room_id,
|
|
191
|
-
object_name: 'MHY:Text',
|
|
192
|
-
msg_content: JSON.stringify(data)
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* 消息发送
|
|
197
|
-
* @param villa_id 别野
|
|
198
|
-
* @param room_id 房间
|
|
199
|
-
* @param text 文本
|
|
200
|
-
* @param entities 渲染
|
|
201
|
-
* @param url 图片
|
|
202
|
-
* @param size 图片配置
|
|
203
|
-
* @returns
|
|
204
|
-
*/
|
|
205
|
-
export async function sendMessageTextEntitiesUrl(villa_id, room_id, text, entities, url, size, msg_id) {
|
|
206
|
-
let data = {
|
|
207
|
-
content: {
|
|
208
|
-
text,
|
|
209
|
-
entities,
|
|
210
|
-
images: [
|
|
211
|
-
{
|
|
212
|
-
url,
|
|
213
|
-
...size
|
|
214
|
-
}
|
|
215
|
-
]
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
48
|
if (msg_id) {
|
|
219
49
|
const [id, at] = String(msg_id).split('.');
|
|
220
|
-
data = {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
original_message_send_time: Number(at),
|
|
226
|
-
quoted_message_id: id,
|
|
227
|
-
quoted_message_send_time: Number(at)
|
|
228
|
-
}
|
|
229
|
-
}
|
|
50
|
+
data.quote = {
|
|
51
|
+
original_message_id: id,
|
|
52
|
+
original_message_send_time: Number(at),
|
|
53
|
+
quoted_message_id: id,
|
|
54
|
+
quoted_message_send_time: Number(at)
|
|
230
55
|
};
|
|
231
56
|
}
|
|
232
57
|
return await sendMessage(villa_id, {
|
|
233
58
|
room_id,
|
|
234
|
-
object_name:
|
|
235
|
-
msg_content:
|
|
59
|
+
object_name: object_name,
|
|
60
|
+
msg_content: stringify(data)
|
|
236
61
|
});
|
|
237
62
|
}
|
package/lib/villa/sdk/wss.js
CHANGED
|
@@ -55,7 +55,7 @@ export async function createClientWS(callBackByVilla) {
|
|
|
55
55
|
meta: null
|
|
56
56
|
})
|
|
57
57
|
}));
|
|
58
|
-
//
|
|
58
|
+
// 20s 心跳
|
|
59
59
|
setInterval(() => {
|
|
60
60
|
ws.send(createMessage({
|
|
61
61
|
ID: counter.getNextID(),
|
|
@@ -77,19 +77,24 @@ export async function createClientWS(callBackByVilla) {
|
|
|
77
77
|
if (obj.bizType == 7) {
|
|
78
78
|
// 登录
|
|
79
79
|
const reply = ProtoCommand('PLoginReply').decode(obj.BodyData);
|
|
80
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
81
|
+
console.log('PLoginReply:', LongToNumber(reply));
|
|
80
82
|
if (reply.code)
|
|
81
83
|
console.log('登录失败');
|
|
82
84
|
}
|
|
83
85
|
else if (obj.bizType == 6) {
|
|
84
86
|
// 心跳
|
|
85
87
|
const reply = ProtoCommand('PHeartBeatReply').decode(obj.BodyData);
|
|
88
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
89
|
+
console.log('PHeartBeatReply:', LongToNumber(reply));
|
|
86
90
|
if (reply.code)
|
|
87
91
|
console.log('心跳错误');
|
|
88
92
|
}
|
|
89
93
|
else if (obj.bizType == 8) {
|
|
90
94
|
// 退出登录
|
|
91
95
|
const reply = ProtoCommand('PLogoutReply').decode(obj.BodyData);
|
|
92
|
-
|
|
96
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
97
|
+
console.log('PLogoutReply:', LongToNumber(reply));
|
|
93
98
|
}
|
|
94
99
|
else if (obj.bizType == 53) {
|
|
95
100
|
// 强制下线
|
|
@@ -101,19 +106,23 @@ export async function createClientWS(callBackByVilla) {
|
|
|
101
106
|
// 回调数据包
|
|
102
107
|
const reply = ProtoModel('RobotEvent').decode(obj.BodyData);
|
|
103
108
|
const data = LongToNumber(reply);
|
|
104
|
-
|
|
109
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
110
|
+
console.log('data', data);
|
|
105
111
|
callBackByVilla(data);
|
|
106
112
|
}
|
|
107
113
|
else {
|
|
108
|
-
|
|
114
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
115
|
+
console.log('未知数据');
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
118
|
catch {
|
|
112
|
-
|
|
119
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
120
|
+
console.log('代码错误');
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
else {
|
|
116
|
-
|
|
124
|
+
if (process.env?.VILLA_WS == 'dev')
|
|
125
|
+
console.log('未知数据');
|
|
117
126
|
}
|
|
118
127
|
});
|
|
119
128
|
ws.on('error', error => {
|
package/lib/villa/villa.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "DOCS https://alemonjs.com/",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ts-node alemon.config.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"koa2-cors": "^2.0.6",
|
|
21
21
|
"lodash": "^4.17.21",
|
|
22
22
|
"mime-types": "^2.1.35",
|
|
23
|
+
"protobufjs": "^7.2.5",
|
|
23
24
|
"public-ip": "^6.0.1",
|
|
24
25
|
"puppeteer": "^20.7.1",
|
|
25
26
|
"qq-guild-bot": "^2.9.5",
|
|
@@ -44,9 +45,8 @@
|
|
|
44
45
|
"eslint-config-prettier": "^8.8.0",
|
|
45
46
|
"eslint-plugin-prettier": "^4.2.1",
|
|
46
47
|
"prettier": "^2.8.8",
|
|
47
|
-
"protobufjs": "^7.2.5",
|
|
48
|
-
"protoc": "^1.1.3",
|
|
49
48
|
"ts-node": "^10.9.1",
|
|
49
|
+
"typedoc": "^0.25.4",
|
|
50
50
|
"typescript": "^5.0.4"
|
|
51
51
|
},
|
|
52
52
|
"author": "ningmengchongshui",
|
package/types/config/login.d.ts
CHANGED
package/types/core/dealmsg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { ControllerOption, UserInformationType } from '../../core/index.js';
|
|
2
|
+
import { type ControllerOption, type UserInformationType } from '../../core/index.js';
|
|
3
3
|
export declare const Controller: {
|
|
4
4
|
Member: ({ guild_id, user_id, channel_id }: {
|
|
5
5
|
guild_id: any;
|