koishi-plugin-share-links-analysis 0.3.0 → 0.5.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.
- package/lib/core.d.ts +1 -0
- package/lib/core.js +11 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +36 -207
- package/lib/parsers/bilibili.js +48 -40
- package/lib/parsers/tmp.json +46 -0
- package/lib/parsers/twitter.d.ts +10 -0
- package/lib/parsers/twitter.js +160 -0
- package/lib/parsers/xiaohongshu.d.ts +1 -1
- package/lib/parsers/xiaohongshu.js +46 -33
- package/lib/types.d.ts +11 -18
- package/lib/utils.d.ts +6 -1
- package/lib/utils.js +481 -0
- package/package.json +1 -1
package/lib/core.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export declare function resolveLinks(content: string): Link[];
|
|
|
15
15
|
* @returns 处理后的链接结果,如果失败则返回 null
|
|
16
16
|
*/
|
|
17
17
|
export declare function processLink(ctx: Context, config: PluginConfig, link: Link, session: Session): Promise<ParsedInfo | null>;
|
|
18
|
+
export declare function init(ctx: Context, config: PluginConfig): Promise<null>;
|
package/lib/core.js
CHANGED
|
@@ -36,10 +36,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.resolveLinks = resolveLinks;
|
|
38
38
|
exports.processLink = processLink;
|
|
39
|
+
exports.init = init;
|
|
39
40
|
const Bilibili = __importStar(require("./parsers/bilibili"));
|
|
40
41
|
const Xiaohongshu = __importStar(require("./parsers/xiaohongshu"));
|
|
42
|
+
const Twitter = __importStar(require("./parsers/twitter"));
|
|
41
43
|
// 定义所有支持的解析器
|
|
42
|
-
const parsers = [Bilibili, Xiaohongshu];
|
|
44
|
+
const parsers = [Bilibili, Xiaohongshu, Twitter];
|
|
43
45
|
/**
|
|
44
46
|
* 从文本中解析出所有支持的链接
|
|
45
47
|
* @param content 消息内容
|
|
@@ -69,3 +71,11 @@ async function processLink(ctx, config, link, session) {
|
|
|
69
71
|
}
|
|
70
72
|
return null;
|
|
71
73
|
}
|
|
74
|
+
async function init(ctx, config) {
|
|
75
|
+
for (const parser of parsers) {
|
|
76
|
+
if (typeof parser.init === 'function') {
|
|
77
|
+
await parser.init(ctx, config);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export declare const inject: {
|
|
|
5
5
|
required: string[];
|
|
6
6
|
optional: never[];
|
|
7
7
|
};
|
|
8
|
-
export declare const usage = "\n\u5F00\u542F\u63D2\u4EF6\u540E\uFF0C\u5373\u53EF\u81EA\u52A8\u89E3\u6790\u5206\u4EAB\u94FE\u63A5\u3002\n\u5411Bot\u53D1\u9001B\u7AD9\u3001\u5C0F\u7EA2\u4E66\u7B49\u652F\u6301\u5E73\u53F0\u7684\u5206\u4EAB\u94FE\u63A5\uFF0C\u4F1A\u8FD4\u56DE\u56FE\u6587\u4FE1\u606F\u4E0E\u89C6\u9891\u3002\n\u60A8\u53EF\u4EE5\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u4E3A\u4E0D\u540C\u5E73\u53F0\u5206\u522B\u8BBE\u7F6E\u8FD4\u56DE\u7684\u56FE\u6587\u6D88\u606F\u683C\u5F0F\u3002\n";
|
|
8
|
+
export declare const usage = "\n\u5F00\u542F\u63D2\u4EF6\u540E\uFF0C\u5373\u53EF\u81EA\u52A8\u89E3\u6790\u5206\u4EAB\u94FE\u63A5\u3002\n\u5411Bot\u53D1\u9001B\u7AD9\u3001\u5C0F\u7EA2\u4E66\u7B49\u652F\u6301\u5E73\u53F0\u7684\u5206\u4EAB\u94FE\u63A5\uFF0C\u4F1A\u8FD4\u56DE\u56FE\u6587\u4FE1\u606F\u4E0E\u89C6\u9891\u3002\n\u60A8\u53EF\u4EE5\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u4E3A\u4E0D\u540C\u5E73\u53F0\u5206\u522B\u8BBE\u7F6E\u8FD4\u56DE\u7684\u56FE\u6587\u6D88\u606F\u683C\u5F0F\u3002\n\u6B64\u63D2\u4EF6\u53EA\u6D4B\u8BD5\u8FC7\u5728Napcat\u4E0B\u7684\u517C\u5BB9\u6027\u60C5\u51B5\uFF0C\u4E0D\u4FDD\u8BC1\u5176\u4ED6\u5E73\u53F0\u53EF\u7528\u3002\n";
|
|
9
9
|
export declare const Config: Schema<PluginConfig>;
|
|
10
10
|
export declare function apply(ctx: Context, config: PluginConfig): void;
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.Config = exports.usage = exports.inject = exports.name = void 0;
|
|
|
5
5
|
exports.apply = apply;
|
|
6
6
|
const koishi_1 = require("koishi");
|
|
7
7
|
const core_1 = require("./core");
|
|
8
|
-
const
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
9
|
exports.name = 'share-links-analysis';
|
|
10
10
|
exports.inject = {
|
|
11
11
|
required: ['BiliBiliVideo', 'database', 'puppeteer'],
|
|
@@ -15,6 +15,7 @@ exports.usage = `
|
|
|
15
15
|
开启插件后,即可自动解析分享链接。
|
|
16
16
|
向Bot发送B站、小红书等支持平台的分享链接,会返回图文信息与视频。
|
|
17
17
|
您可以在插件配置中为不同平台分别设置返回的图文消息格式。
|
|
18
|
+
此插件只测试过在Napcat下的兼容性情况,不保证其他平台可用。
|
|
18
19
|
`;
|
|
19
20
|
// 配置文件
|
|
20
21
|
exports.Config = koishi_1.Schema.intersect([
|
|
@@ -23,39 +24,41 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
23
24
|
koishi_1.Schema.const('1').description('低清晰度优先'),
|
|
24
25
|
koishi_1.Schema.const('2').description('高清晰度优先'),
|
|
25
26
|
]).role('radio').default('1').description("发送的视频清晰度优先策略"),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
MinimumTimeInterval: koishi_1.Schema.number().default(
|
|
27
|
+
Max_size: koishi_1.Schema.number().default(5).description("允许发送的最大文件大小(Mb)"),
|
|
28
|
+
Max_size_tip: koishi_1.Schema.string().default('文件体积过大,策略已阻止发送').description("对大文件的文字提示内容"),
|
|
29
|
+
MinimumTimeInterval: koishi_1.Schema.number().default(600).description("若干秒内不再处理相同链接,防止刷屏").min(1),
|
|
29
30
|
waitTip_Switch: koishi_1.Schema.union([
|
|
30
31
|
koishi_1.Schema.const(false).description('不返回文字提示'),
|
|
31
32
|
koishi_1.Schema.string().description('返回文字提示'),
|
|
32
33
|
]).description("是否返回等待提示。开启后,会发送`等待提示语`").default(false),
|
|
33
|
-
useForward: koishi_1.Schema.
|
|
34
|
+
useForward: koishi_1.Schema.union([
|
|
35
|
+
koishi_1.Schema.const("plain").description("普通发送"),
|
|
36
|
+
koishi_1.Schema.const("forward").description("合并转发"),
|
|
37
|
+
koishi_1.Schema.const("mixed").description("混合发送"),
|
|
38
|
+
]).default("mixed").description("发送模式"),
|
|
34
39
|
}).description("基础设置"),
|
|
35
40
|
koishi_1.Schema.object({
|
|
36
41
|
format: koishi_1.Schema.string().role('textarea').default(`{title}
|
|
37
42
|
{cover}
|
|
38
43
|
作者:{authorName}
|
|
39
|
-
简介:{description}
|
|
40
44
|
{stats}
|
|
41
|
-
|
|
42
|
-
{
|
|
45
|
+
----------
|
|
46
|
+
{mainbody}
|
|
47
|
+
----------
|
|
48
|
+
{sourceUrl}
|
|
49
|
+
{video}`).description('图文/视频输出格式。<br/>可用占位符: `{title}`, `{cover}`, `{authorName}`, `{mainbody}`, `{stats}`, `{sourceUrl}`, `{video}`, `{videoUrl}`'),
|
|
43
50
|
}).description("格式化模板"),
|
|
44
|
-
koishi_1.Schema.object({
|
|
45
|
-
bilibiliStatsFormat: koishi_1.Schema.string().role('textarea').default('播放: {播放} | 弹幕: {弹幕} | 点赞: {点赞} | 硬币: {硬币} | 收藏: {收藏}')
|
|
46
|
-
.description('Bilibili 链接的数据统计格式。<br/>可用占位符: `{播放}`, `{弹幕}`, `{点赞}`, `{硬币}`, `{收藏}`'),
|
|
47
|
-
xiaohongshuStatsFormat: koishi_1.Schema.string().role('textarea').default('点赞: {点赞} | 收藏: {收藏} | 评论: {评论}')
|
|
48
|
-
.description('小红书链接的数据统计格式。<br/>可用占位符: `{点赞}`, `{收藏}`, `{评论}`'),
|
|
49
|
-
}).description("数据格式化"),
|
|
50
51
|
koishi_1.Schema.object({
|
|
51
52
|
parseLimit: koishi_1.Schema.number().default(3).description("单对话多链接解析上限"),
|
|
52
53
|
useNumeral: koishi_1.Schema.boolean().default(true).description("使用格式化数字 (如 10000 -> 1万)"),
|
|
53
54
|
showError: koishi_1.Schema.boolean().default(false).description("当链接不正确时提醒发送者"),
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
koishi_1.Schema.const("av").description("AV 号"),
|
|
57
|
-
]).default("bv").description("B站ID 偏好"),
|
|
55
|
+
allow_sensitive: koishi_1.Schema.boolean().default(false).description("允许NSFW内容"),
|
|
56
|
+
proxy: koishi_1.Schema.string().description("代理设置"),
|
|
58
57
|
}).description("高级解析设置"),
|
|
58
|
+
koishi_1.Schema.object({
|
|
59
|
+
onebotReadDir: koishi_1.Schema.string().description('OneBot 实现 (如 NapCat) 所在的容器或环境提供的路径前缀。').default("/app/.config/QQ/NapCat/temp"),
|
|
60
|
+
localDownloadDir: koishi_1.Schema.string().description('与上述路径对应的、Koishi 所在的容器或主机可以访问的路径前缀。').default("/koishi/data/temp"),
|
|
61
|
+
}).description('跨环境路径映射设置'),
|
|
59
62
|
koishi_1.Schema.object({
|
|
60
63
|
userAgent: koishi_1.Schema.string().description("所有 API 请求所用的 User-Agent").default("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"),
|
|
61
64
|
logLevel: koishi_1.Schema.union([
|
|
@@ -75,8 +78,8 @@ function apply(ctx, config) {
|
|
|
75
78
|
const logger = ctx.logger('share-links-analysis');
|
|
76
79
|
const lastProcessedUrls = {};
|
|
77
80
|
ctx.on('ready', async () => {
|
|
78
|
-
logger.info('
|
|
79
|
-
await (0,
|
|
81
|
+
logger.info('插件已启动,执行插件初始化');
|
|
82
|
+
await (0, core_1.init)(ctx, config);
|
|
80
83
|
});
|
|
81
84
|
ctx.middleware(async (session, next) => {
|
|
82
85
|
if (!session.content || !session.channelId)
|
|
@@ -95,7 +98,7 @@ function apply(ctx, config) {
|
|
|
95
98
|
const now = Date.now();
|
|
96
99
|
if (!lastProcessedUrls[channelId])
|
|
97
100
|
lastProcessedUrls[channelId] = {};
|
|
98
|
-
if (now - (lastProcessedUrls[channelId][link.url] || 0) < config.
|
|
101
|
+
if (now - (lastProcessedUrls[channelId][link.url] || 0) < config.Min_Interval * 1000) {
|
|
99
102
|
if (config.logLevel === 'full')
|
|
100
103
|
logger.info(`链接 ${link.url} 在冷却时间内,跳过处理。`);
|
|
101
104
|
continue;
|
|
@@ -115,194 +118,20 @@ function apply(ctx, config) {
|
|
|
115
118
|
}
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
|
-
function escapeHtml(str) {
|
|
119
|
-
if (!str)
|
|
120
|
-
return '';
|
|
121
|
-
return str.replace(/&/g, '&')
|
|
122
|
-
.replace(/</g, '<')
|
|
123
|
-
.replace(/>/g, '>')
|
|
124
|
-
.replace(/"/g, '"')
|
|
125
|
-
.replace(/'/g, ''');
|
|
126
|
-
}
|
|
127
121
|
async function sendResult(session, config, result, logger) {
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
await sendResult_forward(session, config, result, logger);
|
|
131
|
-
return; // 成功,结束
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
logger.warn('合并转发失败:', err);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
await sendResult_plain(session, config, result, logger);
|
|
122
|
+
if (!session.channel) {
|
|
123
|
+
await (0, utils_1.sendResult_plain)(session, config, result, logger);
|
|
140
124
|
return;
|
|
141
125
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
message = message.replace(/{sourceUrl}/g, escapeHtml(result.sourceUrl || ''));
|
|
153
|
-
message = message.replace(/{cover}/g, result.coverUrl ? koishi_1.h.image(result.coverUrl).toString() : '');
|
|
154
|
-
const imagesText = result.images ? result.images.map(img => koishi_1.h.image(img).toString()).join('\n') : '';
|
|
155
|
-
message = message.replace(/{images}/g, imagesText);
|
|
156
|
-
message = message.replace(/{stats}/g, escapeHtml(result.stats || ''));
|
|
157
|
-
// 【修复】只要 videoUrl 存在就处理,仅当 duration 明确超长时才替换为提示
|
|
158
|
-
if (result.videoUrl) {
|
|
159
|
-
message = message.replace(/{videoUrl}/g, escapeHtml(result.videoUrl));
|
|
160
|
-
// 仅当 duration 是有效数字且超长时,才显示提示
|
|
161
|
-
if (typeof result.duration === 'number' && result.duration > config.Maximumduration * 60) {
|
|
162
|
-
const tip = escapeHtml(config.Maximumduration_tip || '');
|
|
163
|
-
message = message.replace(/{video}/g, tip);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
// 正常发送视频和链接
|
|
167
|
-
message = message.replace(/{video}/g, koishi_1.h.video(result.videoUrl).toString());
|
|
168
|
-
if (config.logLevel === 'link_only' || config.logLevel === 'full') {
|
|
169
|
-
logger.info(`视频直链 (${result.platform}): ${result.videoUrl}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
// 没有视频则移除占位符
|
|
175
|
-
message = message.replace(/{video}/g, '');
|
|
176
|
-
message = message.replace(/{videoUrl}/g, '');
|
|
177
|
-
}
|
|
178
|
-
// 过滤空行,保留含有 < 的行(如图片、视频标签)
|
|
179
|
-
const cleanMessage = message.split('\n').filter(line => line.trim() !== '' || line.includes('<')).join('\n');
|
|
180
|
-
if (config.logLevel === 'full') {
|
|
181
|
-
logger.info(`解析结果: \n ${JSON.stringify(result, null, 2)}`);
|
|
182
|
-
}
|
|
183
|
-
if (cleanMessage) {
|
|
184
|
-
await session.send(koishi_1.h.quote(session.messageId) + cleanMessage);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async function sendResult_forward(session, config, result, logger) {
|
|
188
|
-
if (config.logLevel === 'full') {
|
|
189
|
-
logger.info('进入合并转发发送');
|
|
190
|
-
}
|
|
191
|
-
let message = config.format;
|
|
192
|
-
// Step 1: 替换纯文本字段
|
|
193
|
-
message = message.replace(/{title}/g, escapeHtml(result.title || ''));
|
|
194
|
-
message = message.replace(/{authorName}/g, escapeHtml(result.authorName || ''));
|
|
195
|
-
message = message.replace(/{description}/g, escapeHtml(result.description || ''));
|
|
196
|
-
message = message.replace(/{sourceUrl}/g, escapeHtml(result.sourceUrl || ''));
|
|
197
|
-
message = message.replace(/{stats}/g, escapeHtml(result.stats || ''));
|
|
198
|
-
if (result.videoUrl) {
|
|
199
|
-
message = message.replace(/{videoUrl}/g, escapeHtml(result.videoUrl));
|
|
200
|
-
}
|
|
201
|
-
if (typeof result.duration === 'number' && result.duration > config.Maximumduration * 60) {
|
|
202
|
-
const tip = escapeHtml(config.Maximumduration_tip || '');
|
|
203
|
-
message = message.replace(/{video}/g, tip);
|
|
204
|
-
}
|
|
205
|
-
// Step 2: 检查是否包含视频占位符
|
|
206
|
-
const hasVideoInTemplate = message.includes('{video}');
|
|
207
|
-
// Step 3: 构建富媒体映射
|
|
208
|
-
const mediaMap = {};
|
|
209
|
-
// 处理封面
|
|
210
|
-
if (result.coverUrl) {
|
|
211
|
-
mediaMap['{cover}'] = [{ type: 'image', data: { file: result.coverUrl } }];
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
mediaMap['{cover}'] = [];
|
|
215
|
-
}
|
|
216
|
-
// 处理图片列表
|
|
217
|
-
if (result.images && result.images.length > 0) {
|
|
218
|
-
mediaMap['{images}'] = result.images.map(img => ({ type: 'image', data: { file: img } }));
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
mediaMap['{images}'] = [];
|
|
222
|
-
}
|
|
223
|
-
// Step 4: 按行处理,仅过滤纯空行,并精确控制换行
|
|
224
|
-
const lines = message.split('\n').filter(line => line.trim() !== '');
|
|
225
|
-
const nonVideoSegments = [];
|
|
226
|
-
for (let i = 0; i < lines.length; i++) {
|
|
227
|
-
const line = lines[i];
|
|
228
|
-
const isLastLine = i === lines.length - 1;
|
|
229
|
-
// 按富媒体占位符分割
|
|
230
|
-
const tokens = line.split(/(\{cover\}|\{images\}|\{video\})/g);
|
|
231
|
-
// 用于存储当前行的消息段
|
|
232
|
-
const currentLineSegments = [];
|
|
233
|
-
let hasTextContent = false; // 新增标志:当前行是否包含纯文本
|
|
234
|
-
for (const token of tokens) {
|
|
235
|
-
if (token === '{cover}' || token === '{images}') {
|
|
236
|
-
// 插入对应的消息段
|
|
237
|
-
currentLineSegments.push(...mediaMap[token]);
|
|
238
|
-
}
|
|
239
|
-
else if (token === '{video}') {
|
|
240
|
-
// 视频不放入 nonVideoSegments,跳过
|
|
241
|
-
}
|
|
242
|
-
else if (token.trim() !== '') {
|
|
243
|
-
// 普通文本
|
|
244
|
-
currentLineSegments.push({ type: 'text', data: { text: token } });
|
|
245
|
-
hasTextContent = true; // 标记当前行有文本
|
|
246
|
-
}
|
|
247
|
-
// 注意:token 为空字符串时(如占位符在行首/尾),不添加任何内容
|
|
248
|
-
}
|
|
249
|
-
// 只有当 currentLineSegments 不为空时,才将其加入总列表
|
|
250
|
-
if (currentLineSegments.length > 0) {
|
|
251
|
-
nonVideoSegments.push(...currentLineSegments);
|
|
252
|
-
}
|
|
253
|
-
// 如果不是最后一行,且当前行非空,则添加一个换行符
|
|
254
|
-
if (!isLastLine && hasTextContent) {
|
|
255
|
-
nonVideoSegments.push({ type: 'text', data: { text: '\n' } });
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
// Step 5: 构建转发节点
|
|
259
|
-
const forwardNodes = [];
|
|
260
|
-
// 非视频内容节点
|
|
261
|
-
if (nonVideoSegments.length > 0) {
|
|
262
|
-
forwardNodes.push({
|
|
263
|
-
type: 'node',
|
|
264
|
-
data: {
|
|
265
|
-
user_id: session.selfId,
|
|
266
|
-
nickname: '分享助手',
|
|
267
|
-
content: nonVideoSegments
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
// 视频节点(仅当模板中有 {video} 且有有效视频时)
|
|
272
|
-
if (hasVideoInTemplate && result.videoUrl) {
|
|
273
|
-
if (typeof result.duration === 'number' && result.duration > config.Maximumduration * 60) {
|
|
274
|
-
// 超时提示已作为普通文本处理(在模板中替换为文字)
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
forwardNodes.push({
|
|
278
|
-
type: 'node',
|
|
279
|
-
data: {
|
|
280
|
-
user_id: session.selfId,
|
|
281
|
-
nickname: '分享助手',
|
|
282
|
-
content: [
|
|
283
|
-
{ type: 'video', data: { file: result.videoUrl } },
|
|
284
|
-
]
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
if (config.logLevel === 'link_only' || config.logLevel === 'full') {
|
|
288
|
-
logger.info(`视频直链 (${result.platform}): ${result.videoUrl}`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (forwardNodes.length === 0)
|
|
293
|
-
return;
|
|
294
|
-
if (config.logLevel === 'full') {
|
|
295
|
-
logger.info(`解析结果: \n ${JSON.stringify(result, null, 2)}`);
|
|
126
|
+
switch (config.useForward) {
|
|
127
|
+
case "plain":
|
|
128
|
+
await (0, utils_1.sendResult_plain)(session, config, result, logger);
|
|
129
|
+
return;
|
|
130
|
+
case 'forward':
|
|
131
|
+
await (0, utils_1.sendResult_forward)(session, config, result, logger, false);
|
|
132
|
+
return;
|
|
133
|
+
case "mixed":
|
|
134
|
+
await (0, utils_1.sendResult_forward)(session, config, result, logger, true);
|
|
135
|
+
return;
|
|
296
136
|
}
|
|
297
|
-
// Step 6: 发送合并转发
|
|
298
|
-
if (!(session.onebot && session.onebot._request))
|
|
299
|
-
throw new Error("Onebot is not defined");
|
|
300
|
-
await session.onebot._request('send_group_forward_msg', {
|
|
301
|
-
group_id: session.guildId,
|
|
302
|
-
messages: forwardNodes,
|
|
303
|
-
news: [{ text: result.description || '-' }, { text: '点击查看详情 | Powered by furryaxw' }],
|
|
304
|
-
prompt: result.title || '',
|
|
305
|
-
summary: '分享解析',
|
|
306
|
-
source: result.title || ''
|
|
307
|
-
});
|
|
308
137
|
}
|
package/lib/parsers/bilibili.js
CHANGED
|
@@ -4,6 +4,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.match = match;
|
|
5
5
|
exports.process = process;
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
+
const linkRules = [
|
|
8
|
+
{
|
|
9
|
+
pattern: /(?:https?:\/\/)?(?:www\.bilibili\.com\/video\/)(([ab]v[0-9a-zA-Z]+))/gi,
|
|
10
|
+
type: "video",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
pattern: /(?:https?:\/\/)?(?:b23\.tv\/([0-9a-zA-Z]+))/gi,
|
|
14
|
+
type: "short",
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
const bvPattern = /(?<![a-zA-Z0-9/])(BV[1-9A-HJ-NP-Za-km-z]{10})(?![a-zA-Z0-9])/gi;
|
|
7
18
|
/**
|
|
8
19
|
* 在文本中匹配B站链接 (长链/短链/纯BV号)
|
|
9
20
|
* @param content 消息内容
|
|
@@ -11,36 +22,40 @@ const utils_1 = require("../utils");
|
|
|
11
22
|
*/
|
|
12
23
|
function match(content) {
|
|
13
24
|
const results = [];
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
for (const { pattern, type } of linkRules) {
|
|
27
|
+
let match;
|
|
28
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
29
|
+
const id = match[1];
|
|
30
|
+
if (!id)
|
|
31
|
+
continue;
|
|
32
|
+
const host = type === "short" ? "b23.tv" : "www.bilibili.com";
|
|
33
|
+
const path = type === "short" ? id : `video/${id}`;
|
|
34
|
+
const url = `https://${host}/${path}`;
|
|
35
|
+
if (seen.has(url))
|
|
36
|
+
continue;
|
|
37
|
+
seen.add(url);
|
|
38
|
+
results.push({
|
|
39
|
+
platform: 'bilibili',
|
|
40
|
+
type,
|
|
41
|
+
id,
|
|
42
|
+
url,
|
|
43
|
+
});
|
|
32
44
|
}
|
|
33
45
|
}
|
|
34
|
-
// 匹配独立的 BV
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
46
|
+
// 匹配独立的 BV 号(不包含在链接中)
|
|
47
|
+
let bvMatch;
|
|
48
|
+
while ((bvMatch = bvPattern.exec(content)) !== null) {
|
|
49
|
+
const videoId = bvMatch[1];
|
|
50
|
+
const url = `https://www.bilibili.com/video/${videoId}`;
|
|
51
|
+
if (seen.has(url))
|
|
52
|
+
continue;
|
|
53
|
+
seen.add(url);
|
|
39
54
|
results.push({
|
|
40
55
|
platform: 'bilibili',
|
|
41
56
|
type: 'video',
|
|
42
57
|
id: videoId,
|
|
43
|
-
url
|
|
58
|
+
url,
|
|
44
59
|
});
|
|
45
60
|
}
|
|
46
61
|
return results;
|
|
@@ -154,29 +169,22 @@ async function process(ctx, config, link, session) {
|
|
|
154
169
|
catch (e) {
|
|
155
170
|
logger.error(`通过BiliBiliVideo服务获取视频流失败,bvid: ${data.bvid}: ${e.message}`);
|
|
156
171
|
}
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
165
|
-
let statsString = config.bilibiliStatsFormat;
|
|
166
|
-
// 【修复】使用类型安全的方式遍历对象,防止 TypeScript 报错
|
|
167
|
-
Object.keys(stats).forEach(key => {
|
|
168
|
-
statsString = statsString.replace(`{${key}}`, stats[key]);
|
|
169
|
-
});
|
|
172
|
+
const play = (0, utils_1.numeral)(data.stat.view, config);
|
|
173
|
+
const danmaku = (0, utils_1.numeral)(data.stat.danmaku, config);
|
|
174
|
+
const liked = (0, utils_1.numeral)(data.stat.like, config);
|
|
175
|
+
const coin = (0, utils_1.numeral)(data.stat.coin, config);
|
|
176
|
+
const favorite = (0, utils_1.numeral)(data.stat.favorite, config);
|
|
177
|
+
const statsString = `播放: ${play} | 弹幕: ${danmaku}
|
|
178
|
+
点赞: ${liked} | 硬币: ${coin} | 收藏: ${favorite}`;
|
|
170
179
|
return {
|
|
171
180
|
platform: 'bilibili',
|
|
172
181
|
title: data.title,
|
|
173
182
|
authorName: data.owner.name,
|
|
174
|
-
|
|
183
|
+
mainbody: (0, utils_1.escapeHtml)(data.desc),
|
|
175
184
|
coverUrl: data.pic,
|
|
176
185
|
videoUrl: videoUrl,
|
|
177
|
-
duration: data.duration,
|
|
178
186
|
sourceUrl: `https://www.bilibili.com/video/${data.bvid}`,
|
|
179
|
-
stats: statsString,
|
|
187
|
+
stats: statsString,
|
|
180
188
|
};
|
|
181
189
|
}
|
|
182
190
|
catch (error) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
allSameType: true,
|
|
3
|
+
article: null,
|
|
4
|
+
combinedMediaUrl: null,
|
|
5
|
+
communityNote: null,
|
|
6
|
+
conversationID: '1988209837298377142',
|
|
7
|
+
date: 'Tue Nov 11 11:38:59 +0000 2025',
|
|
8
|
+
date_epoch: 1762861139,
|
|
9
|
+
fetched_on: 1763038701,
|
|
10
|
+
hasMedia: true,
|
|
11
|
+
hashtags: [],
|
|
12
|
+
lang: 'zxx',
|
|
13
|
+
likes: 80,
|
|
14
|
+
mediaURLs: [
|
|
15
|
+
'https://pbs.twimg.com/media/G5eKTetbcAE9wtk.jpg'
|
|
16
|
+
],
|
|
17
|
+
media_extended: [
|
|
18
|
+
{
|
|
19
|
+
altText: null,
|
|
20
|
+
id_str: '1988209827773116417',
|
|
21
|
+
size: {
|
|
22
|
+
height: 1840,
|
|
23
|
+
width: 1840
|
|
24
|
+
},
|
|
25
|
+
thumbnail_url: 'https://pbs.twimg.com/media/G5eKTetbcAE9wtk.jpg',
|
|
26
|
+
type: 'image',
|
|
27
|
+
url: 'https://pbs.twimg.com/media/G5eKTetbcAE9wtk.jpg'
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
pollData: null,
|
|
31
|
+
possibly_sensitive: false,
|
|
32
|
+
qrt: null,
|
|
33
|
+
qrtURL: null,
|
|
34
|
+
replies: 5,
|
|
35
|
+
replyingTo: null,
|
|
36
|
+
replyingToID: null,
|
|
37
|
+
retweet: null,
|
|
38
|
+
retweetURL: null,
|
|
39
|
+
retweets: 4,
|
|
40
|
+
text: 'https://t.co/b8AyvpjhAE',
|
|
41
|
+
tweetID: '1988209837298377142',
|
|
42
|
+
tweetURL: 'https://twitter.com/moyushuang_/status/1988209837298377142',
|
|
43
|
+
user_name: '魔芋凉粉',
|
|
44
|
+
user_profile_image_url: 'https://pbs.twimg.com/profile_images/1830265587676962816/KM46JNnI_normal.jpg',
|
|
45
|
+
user_screen_name: 'moyushuang_'
|
|
46
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, Session } from 'koishi';
|
|
2
|
+
import { PluginConfig, ParsedInfo, Link } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 在文本中匹配 Twitter/X 链接
|
|
5
|
+
*/
|
|
6
|
+
export declare function match(content: string): Link[];
|
|
7
|
+
/**
|
|
8
|
+
* 处理单条 Twitter 链接
|
|
9
|
+
*/
|
|
10
|
+
export declare function process(ctx: Context, config: PluginConfig, link: Link, session: Session): Promise<ParsedInfo | null>;
|