koishi-plugin-share-links-analysis 0.2.1 → 0.2.3
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 +32 -17
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.apply = apply;
|
|
|
6
6
|
const koishi_1 = require("koishi");
|
|
7
7
|
const core_1 = require("./core");
|
|
8
8
|
const xiaohongshu_1 = require("./parsers/xiaohongshu");
|
|
9
|
+
const types_1 = require("koishi-plugin-adapter-onebot/lib/types");
|
|
9
10
|
exports.name = 'share-links-analysis';
|
|
10
11
|
exports.inject = {
|
|
11
12
|
required: ['BiliBiliVideo', 'database', 'puppeteer'],
|
|
@@ -157,16 +158,15 @@ async function sendResult_plain(session, config, result, logger) {
|
|
|
157
158
|
message = message.replace(/{stats}/g, escapeHtml(result.stats || ''));
|
|
158
159
|
// 【修复】只要 videoUrl 存在就处理,仅当 duration 明确超长时才替换为提示
|
|
159
160
|
if (result.videoUrl) {
|
|
161
|
+
message = message.replace(/{videoUrl}/g, escapeHtml(result.videoUrl));
|
|
160
162
|
// 仅当 duration 是有效数字且超长时,才显示提示
|
|
161
163
|
if (typeof result.duration === 'number' && result.duration > config.Maximumduration * 60) {
|
|
162
164
|
const tip = escapeHtml(config.Maximumduration_tip || '');
|
|
163
165
|
message = message.replace(/{video}/g, tip);
|
|
164
|
-
message = message.replace(/{videoUrl}/g, '');
|
|
165
166
|
}
|
|
166
167
|
else {
|
|
167
168
|
// 正常发送视频和链接
|
|
168
169
|
message = message.replace(/{video}/g, koishi_1.h.video(result.videoUrl).toString());
|
|
169
|
-
message = message.replace(/{videoUrl}/g, escapeHtml(result.videoUrl));
|
|
170
170
|
if (config.logLevel === 'link_only' || config.logLevel === 'full') {
|
|
171
171
|
logger.info(`视频直链 (${result.platform}): ${result.videoUrl}`);
|
|
172
172
|
}
|
|
@@ -179,12 +179,12 @@ async function sendResult_plain(session, config, result, logger) {
|
|
|
179
179
|
}
|
|
180
180
|
// 过滤空行,保留含有 < 的行(如图片、视频标签)
|
|
181
181
|
const cleanMessage = message.split('\n').filter(line => line.trim() !== '' || line.includes('<')).join('\n');
|
|
182
|
-
if (cleanMessage) {
|
|
183
|
-
await session.send(koishi_1.h.quote(session.messageId) + cleanMessage);
|
|
184
|
-
}
|
|
185
182
|
if (config.logLevel === 'full') {
|
|
186
183
|
logger.info(`解析结果: \n ${JSON.stringify(result, null, 2)}`);
|
|
187
184
|
}
|
|
185
|
+
if (cleanMessage) {
|
|
186
|
+
await session.send(koishi_1.h.quote(session.messageId) + cleanMessage);
|
|
187
|
+
}
|
|
188
188
|
}
|
|
189
189
|
async function sendResult_forward(session, config, result, logger) {
|
|
190
190
|
if (config.logLevel === 'full') {
|
|
@@ -197,6 +197,13 @@ async function sendResult_forward(session, config, result, logger) {
|
|
|
197
197
|
message = message.replace(/{description}/g, escapeHtml(result.description || ''));
|
|
198
198
|
message = message.replace(/{sourceUrl}/g, escapeHtml(result.sourceUrl || ''));
|
|
199
199
|
message = message.replace(/{stats}/g, escapeHtml(result.stats || ''));
|
|
200
|
+
if (result.videoUrl) {
|
|
201
|
+
message = message.replace(/{videoUrl}/g, escapeHtml(result.videoUrl));
|
|
202
|
+
}
|
|
203
|
+
if (typeof result.duration === 'number' && result.duration > config.Maximumduration * 60) {
|
|
204
|
+
const tip = escapeHtml(config.Maximumduration_tip || '');
|
|
205
|
+
message = message.replace(/{video}/g, tip);
|
|
206
|
+
}
|
|
200
207
|
// Step 2: 检查是否包含视频占位符
|
|
201
208
|
const hasVideoInTemplate = message.includes('{video}');
|
|
202
209
|
// Step 3: 构建富媒体映射
|
|
@@ -276,7 +283,6 @@ async function sendResult_forward(session, config, result, logger) {
|
|
|
276
283
|
nickname: '分享助手',
|
|
277
284
|
content: [
|
|
278
285
|
{ type: 'video', data: { file: result.videoUrl } },
|
|
279
|
-
{ type: 'text', data: { text: `\n视频直链: ${result.videoUrl}` } }
|
|
280
286
|
]
|
|
281
287
|
}
|
|
282
288
|
});
|
|
@@ -287,18 +293,27 @@ async function sendResult_forward(session, config, result, logger) {
|
|
|
287
293
|
}
|
|
288
294
|
if (forwardNodes.length === 0)
|
|
289
295
|
return;
|
|
290
|
-
// Step 6: 发送合并转发
|
|
291
|
-
if (!(session.onebot && session.onebot._request))
|
|
292
|
-
throw new Error("onebot is not defined");
|
|
293
|
-
await session.onebot._request('send_group_forward_msg', {
|
|
294
|
-
group_id: session.guildId,
|
|
295
|
-
messages: forwardNodes,
|
|
296
|
-
news: [{ text: result.description || '' }],
|
|
297
|
-
prompt: result.title || '',
|
|
298
|
-
summary: 'Powered by furryaxw',
|
|
299
|
-
source: result.title || ''
|
|
300
|
-
});
|
|
301
296
|
if (config.logLevel === 'full') {
|
|
302
297
|
logger.info(`解析结果: \n ${JSON.stringify(result, null, 2)}`);
|
|
303
298
|
}
|
|
299
|
+
// Step 6: 发送合并转发
|
|
300
|
+
if (!(session.onebot && session.onebot._request))
|
|
301
|
+
throw new Error("Onebot is not defined");
|
|
302
|
+
try {
|
|
303
|
+
await session.onebot._request('send_group_forward_msg', {
|
|
304
|
+
group_id: session.guildId,
|
|
305
|
+
messages: forwardNodes,
|
|
306
|
+
news: [{ text: result.description || '' }],
|
|
307
|
+
prompt: result.title || '',
|
|
308
|
+
summary: 'Powered by furryaxw',
|
|
309
|
+
source: result.title || ''
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
if (e instanceof types_1.TimeoutError) {
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
throw e;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
304
319
|
}
|