@dcrays/dcgchat-test 0.2.13 → 0.2.14
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/package.json +1 -1
- package/src/bot.ts +41 -32
- package/src/skill.ts +8 -1
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -188,50 +188,59 @@ const EXT_LIST = [
|
|
|
188
188
|
|
|
189
189
|
function extractMobookFiles(text = '') {
|
|
190
190
|
if (typeof text !== 'string' || !text.trim()) return [];
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
const result = new Set();
|
|
193
|
-
|
|
194
|
-
// ✅ 支持的文件类型(可扩展)
|
|
195
|
-
const EXT = `(${EXT_LIST.join('|')})`
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
// 1️⃣ 提取 `xxx.xxx`(反引号包裹)
|
|
199
|
-
const backtickMatches = text.match(
|
|
200
|
-
new RegExp(`\`([^\\\`]+?\\.${EXT})\``, 'gi')
|
|
201
|
-
) || [];
|
|
202
193
|
|
|
203
|
-
|
|
194
|
+
// ✅ 扩展名
|
|
195
|
+
const EXT = `(${EXT_LIST.join('|')})`;
|
|
196
|
+
|
|
197
|
+
// ✅ 文件名字符(增强:支持中文、符号)
|
|
198
|
+
const FILE_NAME = `[\\w\\u4e00-\\u9fa5::《》()()\\-\\s]+?`;
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
// 1️⃣ `xxx.xxx`
|
|
202
|
+
const backtickReg = new RegExp(`\`([^\\\`]+?\\.${EXT})\``, 'gi');
|
|
203
|
+
(text.match(backtickReg) || []).forEach(item => {
|
|
204
204
|
const name = item.replace(/`/g, '').trim();
|
|
205
205
|
if (isValidFileName(name)) {
|
|
206
206
|
result.add(`/mobook/${name}`);
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
209
|
|
|
210
|
-
// 2️⃣
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
) || [];
|
|
214
|
-
|
|
215
|
-
fullPathMatches.forEach(p => {
|
|
210
|
+
// 2️⃣ /mobook/xxx.xxx
|
|
211
|
+
const fullPathReg = new RegExp(`/mobook/${FILE_NAME}\\.${EXT}`, 'gi');
|
|
212
|
+
(text.match(fullPathReg) || []).forEach(p => {
|
|
216
213
|
result.add(normalizePath(p));
|
|
217
214
|
});
|
|
218
215
|
|
|
219
|
-
// 3️⃣
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
216
|
+
// 3️⃣ mobook下的 xxx.xxx
|
|
217
|
+
const inlineReg = new RegExp(`mobook下的\\s*(${FILE_NAME}\\.${EXT})`, 'gi');
|
|
218
|
+
(text.match(inlineReg) || []).forEach(item => {
|
|
219
|
+
const match = item.match(new RegExp(`${FILE_NAME}\\.${EXT}`, 'i'));
|
|
220
|
+
if (match && isValidFileName(match[0])) {
|
|
221
|
+
result.add(`/mobook/${match[0].trim()}`);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// 🆕 4️⃣ **xxx.xxx**
|
|
226
|
+
const boldReg = new RegExp(`\\*\\*(${FILE_NAME}\\.${EXT})\\*\\*`, 'gi');
|
|
227
|
+
(text.match(boldReg) || []).forEach(item => {
|
|
228
|
+
const name = item.replace(/\*\*/g, '').trim();
|
|
229
|
+
if (isValidFileName(name)) {
|
|
230
|
+
result.add(`/mobook/${name}`);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
223
233
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
);
|
|
228
|
-
if (
|
|
229
|
-
result.add(`/mobook/${
|
|
234
|
+
// 🆕 5️⃣ xxx.xxx (123字节)
|
|
235
|
+
const looseReg = new RegExp(`(${FILE_NAME}\\.${EXT})\\s*\\(`, 'gi');
|
|
236
|
+
(text.match(looseReg) || []).forEach(item => {
|
|
237
|
+
const name = item.replace(/\s*\(.+$/, '').trim();
|
|
238
|
+
if (isValidFileName(name)) {
|
|
239
|
+
result.add(`/mobook/${name}`);
|
|
230
240
|
}
|
|
231
241
|
});
|
|
232
242
|
|
|
233
243
|
} catch (e) {
|
|
234
|
-
// 容错:解析异常不影响主流程
|
|
235
244
|
console.warn('extractMobookFiles error:', e);
|
|
236
245
|
}
|
|
237
246
|
|
|
@@ -307,7 +316,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
307
316
|
|
|
308
317
|
const route = core.channel.routing.resolveAgentRoute({
|
|
309
318
|
cfg,
|
|
310
|
-
channel: "dcgchat
|
|
319
|
+
channel: "dcgchat",
|
|
311
320
|
accountId: account.accountId,
|
|
312
321
|
peer: { kind: "direct", id: userId },
|
|
313
322
|
});
|
|
@@ -344,13 +353,13 @@ export async function handleDcgchatMessage(params: {
|
|
|
344
353
|
ChatType: "direct",
|
|
345
354
|
SenderName: userId,
|
|
346
355
|
SenderId: userId,
|
|
347
|
-
Provider: "dcgchat
|
|
348
|
-
Surface: "dcgchat
|
|
356
|
+
Provider: "dcgchat" as const,
|
|
357
|
+
Surface: "dcgchat" as const,
|
|
349
358
|
MessageSid: msg.content.message_id,
|
|
350
359
|
Timestamp: Date.now(),
|
|
351
360
|
WasMentioned: true,
|
|
352
361
|
CommandAuthorized: true,
|
|
353
|
-
OriginatingChannel: "dcgchat
|
|
362
|
+
OriginatingChannel: "dcgchat" as const,
|
|
354
363
|
OriginatingTo: `user:${userId}`,
|
|
355
364
|
...mediaPayload,
|
|
356
365
|
});
|
package/src/skill.ts
CHANGED
|
@@ -67,7 +67,14 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
try {
|
|
70
|
-
const
|
|
70
|
+
const flags = entry.props?.flags ?? 0;
|
|
71
|
+
const isUtf8 = (flags & 0x800) !== 0;
|
|
72
|
+
let entryPath: string;
|
|
73
|
+
if (!isUtf8 && entry.props?.pathBuffer) {
|
|
74
|
+
entryPath = new TextDecoder('gbk').decode(entry.props.pathBuffer);
|
|
75
|
+
} else {
|
|
76
|
+
entryPath = entry.path;
|
|
77
|
+
}
|
|
71
78
|
const pathParts = entryPath.split("/");
|
|
72
79
|
|
|
73
80
|
// 检测根目录
|