cortico-world-forward-reader 0.1.2 → 0.1.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/package.json +1 -1
- package/src/index.js +4 -4
- package/src/onebot.js +12 -4
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -58,7 +58,7 @@ function clockOf(time) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/** 把一条消息的段合成一行,并挑出里面嵌套的转发段。 */
|
|
61
|
-
function foldMessage(segments) {
|
|
61
|
+
function foldMessage(segments, opts = {}) {
|
|
62
62
|
const parts = [];
|
|
63
63
|
const nested = [];
|
|
64
64
|
for (const seg of segments || []) {
|
|
@@ -67,7 +67,7 @@ function foldMessage(segments) {
|
|
|
67
67
|
nested.push(seg);
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
|
-
const piece = segmentText(seg);
|
|
70
|
+
const piece = segmentText(seg, opts);
|
|
71
71
|
if (piece) parts.push(piece);
|
|
72
72
|
}
|
|
73
73
|
return { text: parts.join('').trim(), nested };
|
|
@@ -157,7 +157,7 @@ export class ForwardReaderWorld {
|
|
|
157
157
|
const out = [];
|
|
158
158
|
const state = { items: 0, levels: 0, truncated: false };
|
|
159
159
|
const segments = data?.message || [];
|
|
160
|
-
const whole = foldMessage(segments);
|
|
160
|
+
const whole = foldMessage(segments, { links: true });
|
|
161
161
|
const who = senderName(data?.sender);
|
|
162
162
|
const when = clockOf(data?.time);
|
|
163
163
|
|
|
@@ -212,7 +212,7 @@ export class ForwardReaderWorld {
|
|
|
212
212
|
}
|
|
213
213
|
const who = senderName(item?.sender);
|
|
214
214
|
const when = clockOf(item?.time);
|
|
215
|
-
const folded = foldMessage(item?.message);
|
|
215
|
+
const folded = foldMessage(item?.message, { links: true });
|
|
216
216
|
const head = `${pad(depth)}[${who}${when ? ' ' + when : ''}]`;
|
|
217
217
|
state.items += 1;
|
|
218
218
|
out.push(`${head} ${folded.text || '(空)'}`);
|
package/src/onebot.js
CHANGED
|
@@ -97,15 +97,23 @@ export async function callOneBot(cfg, action, params = {}) {
|
|
|
97
97
|
return json.data ?? json;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
100
|
+
/**
|
|
101
|
+
* 一条消息里的某个段 → 一行给人看的小字。
|
|
102
|
+
* opts.links 为真时,图片后面补上地址(SnowLuma 一般给 url,取不到就退回 file),
|
|
103
|
+
* 这样带图的那条记录也能拿链接去看图,而不是只剩一个「[图片]」。
|
|
104
|
+
*/
|
|
105
|
+
export function segmentText(seg, opts = {}) {
|
|
102
106
|
if (!seg || typeof seg !== 'object') return '';
|
|
103
107
|
const d = seg.data || {};
|
|
104
108
|
switch (seg.type) {
|
|
105
109
|
case 'text':
|
|
106
110
|
return d.text || '';
|
|
107
|
-
case 'image':
|
|
108
|
-
|
|
111
|
+
case 'image': {
|
|
112
|
+
const base = `[图片${d.summary ? ':' + d.summary : ''}]`;
|
|
113
|
+
if (!opts.links) return base;
|
|
114
|
+
const where = d.url || d.path || d.file || '';
|
|
115
|
+
return where ? `${base} ${where}` : base;
|
|
116
|
+
}
|
|
109
117
|
case 'face':
|
|
110
118
|
return `[表情${d.id ? ':' + d.id : ''}]`;
|
|
111
119
|
case 'mface':
|