alemonjs 1.0.0

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.
Files changed (169) hide show
  1. package/LICENSE +340 -0
  2. package/README.md +54 -0
  3. package/lib/alemon/app.js +38 -0
  4. package/lib/alemon/apps.js +121 -0
  5. package/lib/alemon/buffer.js +38 -0
  6. package/lib/alemon/dealmsg.js +423 -0
  7. package/lib/alemon/dialogue.js +61 -0
  8. package/lib/alemon/index.js +40 -0
  9. package/lib/alemon/message.js +27 -0
  10. package/lib/alemon/plugin.js +44 -0
  11. package/lib/alemon/puppeteer.js +226 -0
  12. package/lib/alemon/qrcode.js +66 -0
  13. package/lib/alemon/screenshot.js +126 -0
  14. package/lib/alemon/typings.js +96 -0
  15. package/lib/config.js +25 -0
  16. package/lib/discord/alemon/api.js +44 -0
  17. package/lib/discord/alemon/bot.js +11 -0
  18. package/lib/discord/alemon/conversation.js +7 -0
  19. package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +185 -0
  20. package/lib/discord/alemon/segment.js +62 -0
  21. package/lib/discord/index.js +50 -0
  22. package/lib/discord/login.js +99 -0
  23. package/lib/index.js +12 -0
  24. package/lib/kook/alemon/bot.js +11 -0
  25. package/lib/kook/alemon/conversation.js +56 -0
  26. package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +195 -0
  27. package/lib/kook/alemon/segment.js +90 -0
  28. package/lib/kook/index.js +39 -0
  29. package/lib/kook/login.js +53 -0
  30. package/lib/login.js +112 -0
  31. package/lib/main.js +106 -0
  32. package/lib/ntqq/alemon/bot.js +11 -0
  33. package/lib/ntqq/alemon/conversation.js +18 -0
  34. package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +142 -0
  35. package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +218 -0
  36. package/lib/ntqq/alemon/segment.js +29 -0
  37. package/lib/ntqq/alemon/types.js +1 -0
  38. package/lib/ntqq/index.js +77 -0
  39. package/lib/ntqq/login.js +74 -0
  40. package/lib/ntqq/sdk/api.js +158 -0
  41. package/lib/ntqq/sdk/config.js +46 -0
  42. package/lib/ntqq/sdk/index.js +5 -0
  43. package/lib/ntqq/sdk/intents.js +69 -0
  44. package/lib/ntqq/sdk/types.js +1 -0
  45. package/lib/ntqq/sdk/typings.js +9 -0
  46. package/lib/ntqq/sdk/web/client.js +89 -0
  47. package/lib/ntqq/sdk/web/img.js +76 -0
  48. package/lib/ntqq/sdk/web/index.js +4 -0
  49. package/lib/ntqq/sdk/web/ip.js +24 -0
  50. package/lib/ntqq/sdk/wss.js +178 -0
  51. package/lib/qq/alemon/apidoc.js +216 -0
  52. package/lib/qq/alemon/bot.js +11 -0
  53. package/lib/qq/alemon/console.js +13 -0
  54. package/lib/qq/alemon/conversation.js +139 -0
  55. package/lib/qq/alemon/doc.js +93 -0
  56. package/lib/qq/alemon/e.js +41 -0
  57. package/lib/qq/alemon/message/AUDIO_ACTION.js +57 -0
  58. package/lib/qq/alemon/message/DIRECT_MESSAGE.js +202 -0
  59. package/lib/qq/alemon/message/FORUMS_EVENT.js +66 -0
  60. package/lib/qq/alemon/message/GUILDS.js +65 -0
  61. package/lib/qq/alemon/message/GUILD_MEMBERS.js +153 -0
  62. package/lib/qq/alemon/message/GUILD_MESSAGES.js +50 -0
  63. package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +37 -0
  64. package/lib/qq/alemon/message/INTERACTION.js +36 -0
  65. package/lib/qq/alemon/message/MESSAGE.js +303 -0
  66. package/lib/qq/alemon/message/MESSAGE_AUDIT.js +41 -0
  67. package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +74 -0
  68. package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +52 -0
  69. package/lib/qq/alemon/permissions.js +43 -0
  70. package/lib/qq/alemon/privatechat.js +78 -0
  71. package/lib/qq/alemon/segment.js +25 -0
  72. package/lib/qq/alemon/types.js +25 -0
  73. package/lib/qq/index.js +44 -0
  74. package/lib/qq/login.js +151 -0
  75. package/lib/types.js +5 -0
  76. package/lib/villa/alemon/conversation.js +48 -0
  77. package/lib/villa/alemon/message/GUILDS.js +124 -0
  78. package/lib/villa/alemon/message/GUILD_MEMBERS.js +128 -0
  79. package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +127 -0
  80. package/lib/villa/alemon/message/MESSAGES.js +334 -0
  81. package/lib/villa/alemon/message/MESSAGE_AUDIT.js +128 -0
  82. package/lib/villa/alemon/message/e.js +41 -0
  83. package/lib/villa/alemon/segment.js +34 -0
  84. package/lib/villa/index.js +46 -0
  85. package/lib/villa/login.js +62 -0
  86. package/package.json +63 -0
  87. package/types/alemon/app.d.ts +22 -0
  88. package/types/alemon/apps.d.ts +41 -0
  89. package/types/alemon/buffer.d.ts +13 -0
  90. package/types/alemon/dealmsg.d.ts +41 -0
  91. package/types/alemon/dialogue.d.ts +55 -0
  92. package/types/alemon/index.d.ts +40 -0
  93. package/types/alemon/message.d.ts +17 -0
  94. package/types/alemon/plugin.d.ts +69 -0
  95. package/types/alemon/puppeteer.d.ts +53 -0
  96. package/types/alemon/qrcode.d.ts +20 -0
  97. package/types/alemon/screenshot.d.ts +23 -0
  98. package/types/alemon/typings.d.ts +525 -0
  99. package/types/config.d.ts +12 -0
  100. package/types/discord/alemon/api.d.ts +11 -0
  101. package/types/discord/alemon/bot.d.ts +6 -0
  102. package/types/discord/alemon/conversation.d.ts +6 -0
  103. package/types/discord/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +7 -0
  104. package/types/discord/alemon/segment.d.ts +46 -0
  105. package/types/discord/index.d.ts +1 -0
  106. package/types/discord/login.d.ts +7 -0
  107. package/types/index.d.ts +6 -0
  108. package/types/kook/alemon/bot.d.ts +8 -0
  109. package/types/kook/alemon/conversation.d.ts +7 -0
  110. package/types/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +6 -0
  111. package/types/kook/alemon/segment.d.ts +66 -0
  112. package/types/kook/index.d.ts +5 -0
  113. package/types/kook/login.d.ts +7 -0
  114. package/types/login.d.ts +18 -0
  115. package/types/main.d.ts +15 -0
  116. package/types/ntqq/alemon/bot.d.ts +8 -0
  117. package/types/ntqq/alemon/conversation.d.ts +8 -0
  118. package/types/ntqq/alemon/message/C2C_MESSAGE_CREATE.d.ts +2 -0
  119. package/types/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.d.ts +8 -0
  120. package/types/ntqq/alemon/segment.d.ts +20 -0
  121. package/types/ntqq/alemon/types.d.ts +11 -0
  122. package/types/ntqq/index.d.ts +1 -0
  123. package/types/ntqq/login.d.ts +6 -0
  124. package/types/ntqq/sdk/api.d.ts +44 -0
  125. package/types/ntqq/sdk/config.d.ts +23 -0
  126. package/types/ntqq/sdk/index.d.ts +5 -0
  127. package/types/ntqq/sdk/intents.d.ts +2 -0
  128. package/types/ntqq/sdk/types.d.ts +11 -0
  129. package/types/ntqq/sdk/typings.d.ts +17 -0
  130. package/types/ntqq/sdk/web/client.d.ts +8 -0
  131. package/types/ntqq/sdk/web/img.d.ts +20 -0
  132. package/types/ntqq/sdk/web/index.d.ts +4 -0
  133. package/types/ntqq/sdk/web/ip.d.ts +5 -0
  134. package/types/ntqq/sdk/wss.d.ts +35 -0
  135. package/types/qq/alemon/apidoc.d.ts +154 -0
  136. package/types/qq/alemon/bot.d.ts +8 -0
  137. package/types/qq/alemon/console.d.ts +1 -0
  138. package/types/qq/alemon/conversation.d.ts +5 -0
  139. package/types/qq/alemon/doc.d.ts +93 -0
  140. package/types/qq/alemon/e.d.ts +38 -0
  141. package/types/qq/alemon/message/AUDIO_ACTION.d.ts +15 -0
  142. package/types/qq/alemon/message/DIRECT_MESSAGE.d.ts +16 -0
  143. package/types/qq/alemon/message/FORUMS_EVENT.d.ts +25 -0
  144. package/types/qq/alemon/message/GUILDS.d.ts +19 -0
  145. package/types/qq/alemon/message/GUILD_MEMBERS.d.ts +11 -0
  146. package/types/qq/alemon/message/GUILD_MESSAGES.d.ts +12 -0
  147. package/types/qq/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +9 -0
  148. package/types/qq/alemon/message/INTERACTION.d.ts +8 -0
  149. package/types/qq/alemon/message/MESSAGE.d.ts +16 -0
  150. package/types/qq/alemon/message/MESSAGE_AUDIT.d.ts +9 -0
  151. package/types/qq/alemon/message/OPEN_FORUMS_EVENT.d.ts +28 -0
  152. package/types/qq/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +12 -0
  153. package/types/qq/alemon/permissions.d.ts +29 -0
  154. package/types/qq/alemon/privatechat.d.ts +14 -0
  155. package/types/qq/alemon/segment.d.ts +19 -0
  156. package/types/qq/alemon/types.d.ts +82 -0
  157. package/types/qq/index.d.ts +6 -0
  158. package/types/qq/login.d.ts +6 -0
  159. package/types/types.d.ts +85 -0
  160. package/types/villa/alemon/conversation.d.ts +7 -0
  161. package/types/villa/alemon/message/GUILDS.d.ts +10 -0
  162. package/types/villa/alemon/message/GUILD_MEMBERS.d.ts +14 -0
  163. package/types/villa/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +7 -0
  164. package/types/villa/alemon/message/MESSAGES.d.ts +7 -0
  165. package/types/villa/alemon/message/MESSAGE_AUDIT.d.ts +10 -0
  166. package/types/villa/alemon/message/e.d.ts +37 -0
  167. package/types/villa/alemon/segment.d.ts +26 -0
  168. package/types/villa/index.d.ts +1 -0
  169. package/types/villa/login.d.ts +7 -0
@@ -0,0 +1,128 @@
1
+ import { typeMessage } from '../../../alemon/index.js';
2
+ import { segmentVilla } from '../segment.js';
3
+ import { now_e } from './e.js';
4
+ /**
5
+ * todo
6
+ * 未判断成员退出别野
7
+ */
8
+ /**
9
+ * 涉及房间的接口不可用
10
+ */
11
+ /**
12
+ * 成员进出
13
+ * @param event 回调数据
14
+ * @param val 类型控制
15
+ */
16
+ export async function GUILD_MEMBERS_VILLA(event) {
17
+ /**
18
+ * 别野编号
19
+ */
20
+ const villa_id = event.robot.villa_id ?? '';
21
+ /**
22
+ * 制作e消息对象
23
+ */
24
+ const e = {
25
+ platform: 'villa',
26
+ /**
27
+ * 机器人信息
28
+ */
29
+ bot: {
30
+ id: event.robot.template.id,
31
+ name: event.robot.template.name,
32
+ avatar: event.robot.template.icon
33
+ },
34
+ /**
35
+ * 事件类型
36
+ */
37
+ event: 'GUILD_MEMBERS',
38
+ /**
39
+ * 消息类型
40
+ */
41
+ eventType: 'CREATE',
42
+ /**
43
+ * 是否是私域
44
+ */
45
+ isPrivate: false,
46
+ /**
47
+ * 是否是群聊
48
+ */
49
+ isGroup: true,
50
+ /**
51
+ * 是否是撤回
52
+ */
53
+ isRecall: false,
54
+ /**
55
+ * 艾特得到的qq
56
+ */
57
+ at_users: [],
58
+ /**
59
+ * 是否是艾特
60
+ */
61
+ at: false,
62
+ /**
63
+ * 是否是机器人主人
64
+ */
65
+ isMaster: false,
66
+ /**
67
+ * 去除了艾特后的消息
68
+ */
69
+ msg: '',
70
+ /**
71
+ * 别野编号
72
+ */
73
+ msg_id: event.id,
74
+ /**
75
+ *
76
+ */
77
+ at_user: undefined,
78
+ /**
79
+ *
80
+ */
81
+ guild_id: String(villa_id),
82
+ /**
83
+ * 房间编号:空
84
+ */
85
+ channel_id: '',
86
+ /**
87
+ * 原文消息
88
+ */
89
+ msg_txt: '',
90
+ /**
91
+ * 用户编号
92
+ */
93
+ user_id: '',
94
+ /**
95
+ * 用户名
96
+ */
97
+ user_name: '',
98
+ /**
99
+ * 消息触发时间
100
+ */
101
+ msg_create_time: new Date().getTime(),
102
+ /**
103
+ * 模板方法
104
+ */
105
+ segment: segmentVilla,
106
+ /**
107
+ * 用户头像
108
+ */
109
+ user_avatar: '',
110
+ ...now_e,
111
+ reply: async (msg, img, name) => {
112
+ return false;
113
+ }
114
+ };
115
+ /**
116
+ * 只匹配类型
117
+ */
118
+ await typeMessage(e)
119
+ .then(() => {
120
+ console.info(`\n[${e.event}] [${e.eventType}] [${true}] `);
121
+ return true;
122
+ })
123
+ .catch(err => {
124
+ console.error(`\n[${e.event}] [${e.eventType}] [${false}] `);
125
+ console.error(err);
126
+ return false;
127
+ });
128
+ }
@@ -0,0 +1,127 @@
1
+ import { typeMessage } from '../../../alemon/index.js';
2
+ import { segmentVilla } from '../segment.js';
3
+ import { now_e } from './e.js';
4
+ /**
5
+ * 表情表态
6
+ * @param event 回调数据
7
+ * @param val 类型控制
8
+ */
9
+ export async function GUILD_MESSAGE_REACTIONS_VILLA(event) {
10
+ /**
11
+ * 别野编号
12
+ */
13
+ const villa_id = event.robot.villa_id ?? '';
14
+ /**
15
+ * 房间号
16
+ */
17
+ const room_id = event.extend_data.EventData.SendMessage?.room_id ?? '';
18
+ /**
19
+ * 制作e消息对象
20
+ */
21
+ const e = {
22
+ platform: 'villa',
23
+ /**
24
+ * 机器人信息
25
+ */
26
+ bot: {
27
+ id: event.robot.template.id,
28
+ name: event.robot.template.name,
29
+ avatar: event.robot.template.icon
30
+ },
31
+ /**
32
+ * 事件类型
33
+ */
34
+ event: 'GUILD_MESSAGE_REACTIONS',
35
+ /**
36
+ * 消息类型 : 存在则为撤回
37
+ */
38
+ eventType: event.extend_data.EventData.AddQuickEmoticon.is_cancel
39
+ ? 'DELETE'
40
+ : 'CREATE',
41
+ /**
42
+ * 是否是私域
43
+ */
44
+ isPrivate: false,
45
+ /**
46
+ * 是否是群聊
47
+ */
48
+ isGroup: true,
49
+ /**
50
+ * 是否是撤回
51
+ */
52
+ isRecall: false,
53
+ /**
54
+ * 艾特得到的qq
55
+ */
56
+ at_users: [],
57
+ /**
58
+ * 是否是艾特
59
+ */
60
+ at: false,
61
+ /**
62
+ * 是否是机器人主人
63
+ */
64
+ isMaster: false,
65
+ /**
66
+ * 去除了艾特后的消息
67
+ */
68
+ msg: '',
69
+ /**
70
+ * 别野编号
71
+ */
72
+ msg_id: event.id,
73
+ /**
74
+ * 艾特用户
75
+ */
76
+ at_user: undefined,
77
+ /**
78
+ * 别野编号
79
+ */
80
+ guild_id: String(villa_id),
81
+ /**
82
+ * 房间编号
83
+ */
84
+ channel_id: String(room_id),
85
+ /**
86
+ * 消息原文
87
+ */
88
+ msg_txt: '',
89
+ /**
90
+ * 用户编号
91
+ */
92
+ user_id: '',
93
+ /**
94
+ * 用户名
95
+ */
96
+ user_name: '',
97
+ /**
98
+ * 消息创建时间
99
+ */
100
+ msg_create_time: new Date().getTime(),
101
+ /**
102
+ * 模板函数
103
+ */
104
+ segment: segmentVilla,
105
+ /**
106
+ * 用户头像
107
+ */
108
+ user_avatar: '',
109
+ ...now_e,
110
+ reply: async (msg, img, name) => {
111
+ return false;
112
+ }
113
+ };
114
+ /**
115
+ * 只匹配类型
116
+ */
117
+ await typeMessage(e)
118
+ .then(() => {
119
+ console.info(`\n[${e.event}] [${e.eventType}] [${true}] `);
120
+ return true;
121
+ })
122
+ .catch(err => {
123
+ console.error(`\n[${e.event}] [${e.eventType}] [${false}] `);
124
+ console.error(err);
125
+ return false;
126
+ });
127
+ }
@@ -0,0 +1,334 @@
1
+ import { InstructionMatching } from '../../../alemon/index.js';
2
+ import { Client } from 'mys-villa';
3
+ import IMGS from 'image-size';
4
+ import { segmentVilla } from '../segment.js';
5
+ import { getBotConfigByKey } from '../../../login.js';
6
+ import { now_e } from './e.js';
7
+ /**
8
+ * 获取ip
9
+ */
10
+ const ip = await Client.getIP();
11
+ /**
12
+ * 消息会话
13
+ * @param event 回调数据
14
+ * @param val 类型控制
15
+ */
16
+ export async function MESSAGES_VILLA(event) {
17
+ /**
18
+ * 数据包解析
19
+ */
20
+ const MessageContent = JSON.parse(event.extend_data.EventData.SendMessage.content);
21
+ /**
22
+ * 别野编号
23
+ */
24
+ const villa_id = event.robot.villa_id;
25
+ /**
26
+ * 房间号
27
+ */
28
+ const room_id = event.extend_data.EventData.SendMessage.room_id;
29
+ /**
30
+ * 得到特效
31
+ */
32
+ const entities = MessageContent.content?.entities ?? [];
33
+ /**
34
+ * 收集uid
35
+ */
36
+ const at_users = [];
37
+ /**
38
+ * at控制
39
+ */
40
+ let at = false;
41
+ /**
42
+ * 艾特用户
43
+ */
44
+ let at_user = undefined;
45
+ /**
46
+ * 消息原文
47
+ */
48
+ const txt = MessageContent.content.text;
49
+ /**
50
+ * 解析
51
+ */
52
+ for await (const item of entities) {
53
+ const name = txt
54
+ .substring(item.offset, item.offset + item.length)
55
+ .trim()
56
+ .replace(/^@|(\s+)?$/g, '');
57
+ if (item.entity.user_id) {
58
+ /**
59
+ * 存在用户艾特
60
+ */
61
+ at = true;
62
+ at_users.push({
63
+ id: item.entity.user_id,
64
+ name,
65
+ avatar: 'string',
66
+ bot: false
67
+ });
68
+ continue;
69
+ }
70
+ if (item.entity.bot_id) {
71
+ at_users.push({
72
+ id: item.entity.bot_id,
73
+ name,
74
+ avatar: 'string',
75
+ bot: true
76
+ });
77
+ continue;
78
+ }
79
+ }
80
+ /**
81
+ * 存在at
82
+ */
83
+ if (at) {
84
+ /**
85
+ * 找到第一个不是bot的用户
86
+ */
87
+ at_user = at_users.find(item => item.bot != true);
88
+ }
89
+ /**
90
+ * 得到登录配置
91
+ */
92
+ const cfg = getBotConfigByKey('villa');
93
+ /**
94
+ * 得到主人id
95
+ */
96
+ const masterID = cfg.masterID;
97
+ /**
98
+ * 默认不是主人
99
+ */
100
+ let isMaster = false;
101
+ /**
102
+ * 检查身份
103
+ */
104
+ if (MessageContent.user.id == masterID) {
105
+ /**
106
+ * 是主人
107
+ */
108
+ isMaster = true;
109
+ }
110
+ /**
111
+ * 清除 @ 后的消息
112
+ */
113
+ const msg = txt.replace(/(@[^\s]+\s)(?!<)/g, '').trim();
114
+ /**
115
+ * 制作e消息对象
116
+ */
117
+ const e = {
118
+ platform: 'villa',
119
+ /**
120
+ * 机器人信息
121
+ */
122
+ bot: {
123
+ id: event.robot.template.id,
124
+ name: event.robot.template.name,
125
+ avatar: event.robot.template.icon
126
+ },
127
+ /**
128
+ * 消息编号
129
+ */
130
+ /**
131
+ * 事件类型
132
+ */
133
+ event: 'MESSAGES',
134
+ /**
135
+ * 消息类型
136
+ * */
137
+ eventType: 'CREATE',
138
+ /**
139
+ * 是否是私域
140
+ *
141
+ * */
142
+ isPrivate: false,
143
+ /**
144
+ * 是否是群聊
145
+ * */
146
+ isGroup: true,
147
+ /**
148
+ * 是否是撤回
149
+ * */
150
+ isRecall: false,
151
+ /**
152
+ * 是否是艾特
153
+ * */
154
+ at,
155
+ /**
156
+ * 艾特得到的qq
157
+ * */
158
+ at_users: at_users,
159
+ /**
160
+ * 艾特用户
161
+ */
162
+ at_user,
163
+ /**
164
+ * 是否是机器人主人
165
+ */
166
+ isMaster: isMaster,
167
+ /*
168
+ * 消息编号 这个消息是可以触发回复api的消息id
169
+ */
170
+ msg_id: event.id,
171
+ /**
172
+ * 去除了艾特后的消息
173
+ * */
174
+ msg: msg,
175
+ /**
176
+ * 原文
177
+ */
178
+ msg_txt: txt,
179
+ /**
180
+ * 房间编号
181
+ */
182
+ guild_id: String(villa_id),
183
+ /**
184
+ * 房间编号
185
+ */
186
+ channel_id: String(room_id),
187
+ /**
188
+ * 用户编号
189
+ */
190
+ user_id: MessageContent.user.id,
191
+ /**
192
+ * 用户名
193
+ */
194
+ user_name: MessageContent.user.name,
195
+ /**
196
+ * 用户头像
197
+ */
198
+ user_avatar: MessageContent.user.portrait,
199
+ /**
200
+ * 创建消息事件
201
+ */
202
+ msg_create_time: new Date().getTime(),
203
+ /**
204
+ * 模板接口
205
+ */
206
+ segment: segmentVilla,
207
+ /**
208
+ *消息发送
209
+ * @param msg
210
+ * @param img
211
+ * @returns
212
+ */
213
+ reply: async (msg, img, name) => {
214
+ /**
215
+ * url获取
216
+ */
217
+ let url = '';
218
+ /**
219
+ * 第一参数是buffer
220
+ */
221
+ if (Buffer.isBuffer(msg)) {
222
+ /**
223
+ * 挂载图片
224
+ */
225
+ const dimensions = IMGS.imageSize(msg);
226
+ const uul = await Client.setLocalImg(msg);
227
+ if (!uul)
228
+ return false;
229
+ const NowObj = await Client.transferImage(villa_id, `${cfg.http}://${ip}:${cfg.port}${uul}`);
230
+ if (!NowObj) {
231
+ url = `${cfg.http}://${ip}:${cfg.port}${uul}`;
232
+ }
233
+ else {
234
+ url = NowObj.new_url;
235
+ }
236
+ /**
237
+ * 直接发送图片
238
+ */
239
+ return await Client.sendMessageImage(villa_id, room_id, url, {
240
+ width: dimensions.width,
241
+ height: dimensions.height
242
+ }).catch(err => {
243
+ console.error(err);
244
+ return false;
245
+ });
246
+ }
247
+ /**
248
+ * 第一个参数是对象且不是数组对象
249
+ */
250
+ if (typeof msg === 'object' && !Array.isArray(msg)) {
251
+ const options = msg;
252
+ if (options?.image) {
253
+ /**
254
+ * 图片对象
255
+ */
256
+ return await Client.sendMessageTextUrl(villa_id, room_id, msg, options.image).catch(err => {
257
+ console.error(err);
258
+ return false;
259
+ });
260
+ }
261
+ return false;
262
+ }
263
+ /**
264
+ * 字符解析器
265
+ */
266
+ const { entities, content } = await Client.stringParsing(msg, villa_id);
267
+ /**
268
+ * 第二参是 buffer
269
+ */
270
+ if (Buffer.isBuffer(img)) {
271
+ /**
272
+ * 挂载图片
273
+ */
274
+ const dimensions = IMGS.imageSize(img);
275
+ const uul = await Client.setLocalImg(img);
276
+ if (!uul)
277
+ return false;
278
+ const NowObj = await Client.transferImage(villa_id, `${cfg.http}://${ip}:${cfg.port}${uul}`);
279
+ if (!NowObj) {
280
+ url = `${cfg.http}://${ip}:${cfg.port}${uul}`;
281
+ }
282
+ else {
283
+ url = NowObj.new_url;
284
+ }
285
+ if (entities.length == 0) {
286
+ return await Client.sendMessageTextUrl(villa_id, room_id, content, url, {
287
+ width: dimensions.width,
288
+ height: dimensions.height
289
+ }).catch(err => {
290
+ console.error(err);
291
+ return false;
292
+ });
293
+ }
294
+ else {
295
+ return await Client.sendMessageTextEntitiesUrl(villa_id, room_id, content, entities, url, {
296
+ width: dimensions.width,
297
+ height: dimensions.height
298
+ }).catch(err => {
299
+ console.error(err);
300
+ return false;
301
+ });
302
+ }
303
+ }
304
+ if (entities.length == 0 && content != '') {
305
+ return await Client.sendMessageText(villa_id, room_id, content).catch(err => {
306
+ console.error(err);
307
+ return false;
308
+ });
309
+ }
310
+ else if (entities.length != 0 && content != '') {
311
+ return await Client.sendMessageTextEntities(villa_id, room_id, content, entities).catch(err => {
312
+ console.error(err);
313
+ return false;
314
+ });
315
+ }
316
+ return false;
317
+ },
318
+ ...now_e
319
+ };
320
+ /**
321
+ * 业务处理
322
+ */
323
+ await InstructionMatching(e)
324
+ .then(() => {
325
+ console.info(`\n[${e.channel_id}] [${e.user_name}] [${true}] ${MessageContent.content.text}`);
326
+ return true;
327
+ })
328
+ .catch((err) => {
329
+ console.error(`\n[${e.channel_id}] [${e.user_name}] [${true}] ${MessageContent.content.text}`);
330
+ console.error(err);
331
+ return false;
332
+ });
333
+ return false;
334
+ }
@@ -0,0 +1,128 @@
1
+ import { typeMessage } from '../../../alemon/index.js';
2
+ import { segmentVilla } from '../segment.js';
3
+ import { now_e } from './e.js';
4
+ /**
5
+ * 如何判断审核事件成功与否?
6
+ */
7
+ /**
8
+ * 审核事件
9
+ * @param event 回调数据
10
+ * @param val 类型控制
11
+ */
12
+ export async function MESSAGE_AUDIT_VILLA(event) {
13
+ /**
14
+ * 别野编号
15
+ */
16
+ const villa_id = event.robot.villa_id ?? '';
17
+ /**
18
+ * 房间号
19
+ */
20
+ const room_id = event.extend_data.EventData.SendMessage?.room_id ?? '';
21
+ /**
22
+ * 制作e消息对象
23
+ */
24
+ const e = {
25
+ platform: 'villa',
26
+ /**
27
+ * 机器人信息
28
+ */
29
+ bot: {
30
+ id: event.robot.template.id,
31
+ name: event.robot.template.name,
32
+ avatar: event.robot.template.icon
33
+ },
34
+ /**
35
+ * 事件类型
36
+ */
37
+ event: 'MESSAGE_AUDIT',
38
+ /**
39
+ * 消息类型
40
+ */
41
+ eventType: 'CREATE',
42
+ /**
43
+ * 是否是私域
44
+ */
45
+ isPrivate: false,
46
+ /**
47
+ * 是否是群聊
48
+ */
49
+ isGroup: true,
50
+ /**
51
+ * 是否是撤回
52
+ */
53
+ isRecall: false,
54
+ /**
55
+ * 艾特得到的qq
56
+ */
57
+ at_users: [],
58
+ /**
59
+ * 是否是艾特
60
+ */
61
+ at: false,
62
+ /**
63
+ * 是否是机器人主人
64
+ */
65
+ isMaster: false,
66
+ /**
67
+ * 去除了艾特后的消息
68
+ */
69
+ msg: '',
70
+ /**
71
+ * 别野编号
72
+ */
73
+ msg_id: event.id,
74
+ /**
75
+ * 艾特用户
76
+ */
77
+ at_user: undefined,
78
+ /**
79
+ *
80
+ */
81
+ guild_id: String(villa_id),
82
+ /**
83
+ * 房间编号
84
+ */
85
+ channel_id: String(room_id),
86
+ /**
87
+ *
88
+ */
89
+ msg_txt: '',
90
+ /**
91
+ * 用户编号
92
+ */
93
+ user_id: '',
94
+ /**
95
+ * 用户名
96
+ */
97
+ user_name: '',
98
+ /**
99
+ * 消息创建时间
100
+ */
101
+ msg_create_time: new Date().getTime(),
102
+ /**
103
+ * 模板函数
104
+ */
105
+ segment: segmentVilla,
106
+ /**
107
+ * 用户头像
108
+ */
109
+ user_avatar: '',
110
+ ...now_e,
111
+ reply: async (msg, img, name) => {
112
+ return false;
113
+ }
114
+ };
115
+ /**
116
+ * 只匹配类型
117
+ */
118
+ await typeMessage(e)
119
+ .then(() => {
120
+ console.info(`\n[${e.event}] [${e.eventType}] [${true}] `);
121
+ return true;
122
+ })
123
+ .catch(err => {
124
+ console.error(`\n[${e.event}] [${e.eventType}] [${false}] `);
125
+ console.error(err);
126
+ return false;
127
+ });
128
+ }