koztv-blog-tools 1.3.8 → 1.3.9
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/bin/tg-login.js +0 -0
- package/dist/node.js +13 -79
- package/dist/node.mjs +13 -79
- package/package.json +1 -1
package/bin/tg-login.js
CHANGED
|
File without changes
|
package/dist/node.js
CHANGED
|
@@ -406,108 +406,42 @@ function compressVideo(inputPath, outputPath) {
|
|
|
406
406
|
}
|
|
407
407
|
function entitiesToMarkdown(text, entities) {
|
|
408
408
|
if (!entities || entities.length === 0) return text;
|
|
409
|
-
const mergedEntities = [];
|
|
410
|
-
const processedIndices = /* @__PURE__ */ new Set();
|
|
411
|
-
const links = [];
|
|
412
|
-
for (const entity of entities) {
|
|
413
|
-
if (entity instanceof import_telegram.Api.MessageEntityTextUrl) {
|
|
414
|
-
links.push({
|
|
415
|
-
start: entity.offset,
|
|
416
|
-
end: entity.offset + entity.length,
|
|
417
|
-
entity
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const formatEntities = entities.filter(
|
|
422
|
-
(e) => e instanceof import_telegram.Api.MessageEntityBold || e instanceof import_telegram.Api.MessageEntityItalic
|
|
423
|
-
);
|
|
424
|
-
for (let i = 0; i < formatEntities.length; i++) {
|
|
425
|
-
if (processedIndices.has(entities.indexOf(formatEntities[i]))) continue;
|
|
426
|
-
const current = formatEntities[i];
|
|
427
|
-
const currentEnd = current.offset + current.length;
|
|
428
|
-
const bridgingLink = links.find((l) => l.start === currentEnd);
|
|
429
|
-
if (bridgingLink) {
|
|
430
|
-
const nextEntity = formatEntities.find(
|
|
431
|
-
(e) => e !== current && e.constructor === current.constructor && e.offset === bridgingLink.end
|
|
432
|
-
);
|
|
433
|
-
if (nextEntity) {
|
|
434
|
-
const mergedLength = nextEntity.offset + nextEntity.length - current.offset;
|
|
435
|
-
if (current instanceof import_telegram.Api.MessageEntityBold) {
|
|
436
|
-
mergedEntities.push(new import_telegram.Api.MessageEntityBold({ offset: current.offset, length: mergedLength }));
|
|
437
|
-
} else if (current instanceof import_telegram.Api.MessageEntityItalic) {
|
|
438
|
-
mergedEntities.push(new import_telegram.Api.MessageEntityItalic({ offset: current.offset, length: mergedLength }));
|
|
439
|
-
}
|
|
440
|
-
processedIndices.add(entities.indexOf(current));
|
|
441
|
-
processedIndices.add(entities.indexOf(nextEntity));
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
if (!processedIndices.has(entities.indexOf(current))) {
|
|
446
|
-
mergedEntities.push(current);
|
|
447
|
-
processedIndices.add(entities.indexOf(current));
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
for (let i = 0; i < entities.length; i++) {
|
|
451
|
-
if (processedIndices.has(i)) continue;
|
|
452
|
-
const entity = entities[i];
|
|
453
|
-
if (!(entity instanceof import_telegram.Api.MessageEntityBold) && !(entity instanceof import_telegram.Api.MessageEntityItalic)) {
|
|
454
|
-
mergedEntities.push(entity);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
const sorted = [...mergedEntities].sort((a, b) => {
|
|
458
|
-
if (a.offset !== b.offset) return a.offset - b.offset;
|
|
459
|
-
return b.length - a.length;
|
|
460
|
-
});
|
|
461
409
|
const markers = [];
|
|
462
|
-
for (const entity of
|
|
463
|
-
|
|
464
|
-
|
|
410
|
+
for (const entity of entities) {
|
|
411
|
+
let start = entity.offset;
|
|
412
|
+
let end = entity.offset + entity.length;
|
|
413
|
+
const entityText = text.substring(start, end);
|
|
414
|
+
const leadingWs = entityText.match(/^\s*/)?.[0].length || 0;
|
|
415
|
+
const trailingWs = entityText.match(/\s*$/)?.[0].length || 0;
|
|
416
|
+
if (leadingWs > 0 && leadingWs < entityText.length) start += leadingWs;
|
|
417
|
+
if (trailingWs > 0 && trailingWs < entityText.length) end -= trailingWs;
|
|
465
418
|
let startMark = "";
|
|
466
419
|
let endMark = "";
|
|
467
|
-
let priority = 0;
|
|
468
420
|
if (entity instanceof import_telegram.Api.MessageEntityBold) {
|
|
469
421
|
startMark = "**";
|
|
470
422
|
endMark = "**";
|
|
471
|
-
priority = 1;
|
|
472
|
-
} else if (entity instanceof import_telegram.Api.MessageEntityItalic) {
|
|
473
|
-
startMark = "*";
|
|
474
|
-
endMark = "*";
|
|
475
|
-
priority = 1;
|
|
476
423
|
} else if (entity instanceof import_telegram.Api.MessageEntityCode) {
|
|
477
424
|
startMark = "`";
|
|
478
425
|
endMark = "`";
|
|
479
|
-
priority = 2;
|
|
480
426
|
} else if (entity instanceof import_telegram.Api.MessageEntityPre) {
|
|
481
427
|
startMark = "```\n";
|
|
482
428
|
endMark = "\n```";
|
|
483
|
-
priority = 2;
|
|
484
429
|
} else if (entity instanceof import_telegram.Api.MessageEntityStrike) {
|
|
485
430
|
startMark = "~~";
|
|
486
431
|
endMark = "~~";
|
|
487
|
-
priority = 1;
|
|
488
|
-
} else if (entity instanceof import_telegram.Api.MessageEntityUnderline) {
|
|
489
|
-
startMark = "**";
|
|
490
|
-
endMark = "**";
|
|
491
|
-
priority = 1;
|
|
492
432
|
} else if (entity instanceof import_telegram.Api.MessageEntityTextUrl) {
|
|
493
433
|
startMark = "[";
|
|
494
434
|
endMark = `](${entity.url})`;
|
|
495
|
-
priority = 10;
|
|
496
435
|
}
|
|
497
436
|
if (startMark) {
|
|
498
|
-
markers.push({ pos: start, insert: startMark,
|
|
499
|
-
markers.push({ pos: end, insert: endMark,
|
|
437
|
+
markers.push({ pos: start, insert: startMark, isEnd: false });
|
|
438
|
+
markers.push({ pos: end, insert: endMark, isEnd: true });
|
|
500
439
|
}
|
|
501
440
|
}
|
|
502
441
|
markers.sort((a, b) => {
|
|
503
442
|
if (a.pos !== b.pos) return a.pos - b.pos;
|
|
504
|
-
if (a.
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
if (a.priority > 0 && b.priority > 0) {
|
|
508
|
-
return b.priority - a.priority;
|
|
509
|
-
}
|
|
510
|
-
return a.priority - b.priority;
|
|
443
|
+
if (a.isEnd !== b.isEnd) return a.isEnd ? -1 : 1;
|
|
444
|
+
return 0;
|
|
511
445
|
});
|
|
512
446
|
let result = "";
|
|
513
447
|
let lastPos = 0;
|
|
@@ -516,7 +450,7 @@ function entitiesToMarkdown(text, entities) {
|
|
|
516
450
|
lastPos = marker.pos;
|
|
517
451
|
}
|
|
518
452
|
result += text.substring(lastPos);
|
|
519
|
-
result = result.replace(
|
|
453
|
+
result = result.replace(/\*\*\s*\*\*/g, " ").replace(/\*{4,}/g, "").replace(/\*{3}/g, "").replace(/\n{3,}/g, "\n\n");
|
|
520
454
|
return result;
|
|
521
455
|
}
|
|
522
456
|
async function defaultReadline(prompt) {
|
package/dist/node.mjs
CHANGED
|
@@ -52,108 +52,42 @@ function compressVideo(inputPath, outputPath) {
|
|
|
52
52
|
}
|
|
53
53
|
function entitiesToMarkdown(text, entities) {
|
|
54
54
|
if (!entities || entities.length === 0) return text;
|
|
55
|
-
const mergedEntities = [];
|
|
56
|
-
const processedIndices = /* @__PURE__ */ new Set();
|
|
57
|
-
const links = [];
|
|
58
|
-
for (const entity of entities) {
|
|
59
|
-
if (entity instanceof Api.MessageEntityTextUrl) {
|
|
60
|
-
links.push({
|
|
61
|
-
start: entity.offset,
|
|
62
|
-
end: entity.offset + entity.length,
|
|
63
|
-
entity
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const formatEntities = entities.filter(
|
|
68
|
-
(e) => e instanceof Api.MessageEntityBold || e instanceof Api.MessageEntityItalic
|
|
69
|
-
);
|
|
70
|
-
for (let i = 0; i < formatEntities.length; i++) {
|
|
71
|
-
if (processedIndices.has(entities.indexOf(formatEntities[i]))) continue;
|
|
72
|
-
const current = formatEntities[i];
|
|
73
|
-
const currentEnd = current.offset + current.length;
|
|
74
|
-
const bridgingLink = links.find((l) => l.start === currentEnd);
|
|
75
|
-
if (bridgingLink) {
|
|
76
|
-
const nextEntity = formatEntities.find(
|
|
77
|
-
(e) => e !== current && e.constructor === current.constructor && e.offset === bridgingLink.end
|
|
78
|
-
);
|
|
79
|
-
if (nextEntity) {
|
|
80
|
-
const mergedLength = nextEntity.offset + nextEntity.length - current.offset;
|
|
81
|
-
if (current instanceof Api.MessageEntityBold) {
|
|
82
|
-
mergedEntities.push(new Api.MessageEntityBold({ offset: current.offset, length: mergedLength }));
|
|
83
|
-
} else if (current instanceof Api.MessageEntityItalic) {
|
|
84
|
-
mergedEntities.push(new Api.MessageEntityItalic({ offset: current.offset, length: mergedLength }));
|
|
85
|
-
}
|
|
86
|
-
processedIndices.add(entities.indexOf(current));
|
|
87
|
-
processedIndices.add(entities.indexOf(nextEntity));
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (!processedIndices.has(entities.indexOf(current))) {
|
|
92
|
-
mergedEntities.push(current);
|
|
93
|
-
processedIndices.add(entities.indexOf(current));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
for (let i = 0; i < entities.length; i++) {
|
|
97
|
-
if (processedIndices.has(i)) continue;
|
|
98
|
-
const entity = entities[i];
|
|
99
|
-
if (!(entity instanceof Api.MessageEntityBold) && !(entity instanceof Api.MessageEntityItalic)) {
|
|
100
|
-
mergedEntities.push(entity);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const sorted = [...mergedEntities].sort((a, b) => {
|
|
104
|
-
if (a.offset !== b.offset) return a.offset - b.offset;
|
|
105
|
-
return b.length - a.length;
|
|
106
|
-
});
|
|
107
55
|
const markers = [];
|
|
108
|
-
for (const entity of
|
|
109
|
-
|
|
110
|
-
|
|
56
|
+
for (const entity of entities) {
|
|
57
|
+
let start = entity.offset;
|
|
58
|
+
let end = entity.offset + entity.length;
|
|
59
|
+
const entityText = text.substring(start, end);
|
|
60
|
+
const leadingWs = entityText.match(/^\s*/)?.[0].length || 0;
|
|
61
|
+
const trailingWs = entityText.match(/\s*$/)?.[0].length || 0;
|
|
62
|
+
if (leadingWs > 0 && leadingWs < entityText.length) start += leadingWs;
|
|
63
|
+
if (trailingWs > 0 && trailingWs < entityText.length) end -= trailingWs;
|
|
111
64
|
let startMark = "";
|
|
112
65
|
let endMark = "";
|
|
113
|
-
let priority = 0;
|
|
114
66
|
if (entity instanceof Api.MessageEntityBold) {
|
|
115
67
|
startMark = "**";
|
|
116
68
|
endMark = "**";
|
|
117
|
-
priority = 1;
|
|
118
|
-
} else if (entity instanceof Api.MessageEntityItalic) {
|
|
119
|
-
startMark = "*";
|
|
120
|
-
endMark = "*";
|
|
121
|
-
priority = 1;
|
|
122
69
|
} else if (entity instanceof Api.MessageEntityCode) {
|
|
123
70
|
startMark = "`";
|
|
124
71
|
endMark = "`";
|
|
125
|
-
priority = 2;
|
|
126
72
|
} else if (entity instanceof Api.MessageEntityPre) {
|
|
127
73
|
startMark = "```\n";
|
|
128
74
|
endMark = "\n```";
|
|
129
|
-
priority = 2;
|
|
130
75
|
} else if (entity instanceof Api.MessageEntityStrike) {
|
|
131
76
|
startMark = "~~";
|
|
132
77
|
endMark = "~~";
|
|
133
|
-
priority = 1;
|
|
134
|
-
} else if (entity instanceof Api.MessageEntityUnderline) {
|
|
135
|
-
startMark = "**";
|
|
136
|
-
endMark = "**";
|
|
137
|
-
priority = 1;
|
|
138
78
|
} else if (entity instanceof Api.MessageEntityTextUrl) {
|
|
139
79
|
startMark = "[";
|
|
140
80
|
endMark = `](${entity.url})`;
|
|
141
|
-
priority = 10;
|
|
142
81
|
}
|
|
143
82
|
if (startMark) {
|
|
144
|
-
markers.push({ pos: start, insert: startMark,
|
|
145
|
-
markers.push({ pos: end, insert: endMark,
|
|
83
|
+
markers.push({ pos: start, insert: startMark, isEnd: false });
|
|
84
|
+
markers.push({ pos: end, insert: endMark, isEnd: true });
|
|
146
85
|
}
|
|
147
86
|
}
|
|
148
87
|
markers.sort((a, b) => {
|
|
149
88
|
if (a.pos !== b.pos) return a.pos - b.pos;
|
|
150
|
-
if (a.
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
if (a.priority > 0 && b.priority > 0) {
|
|
154
|
-
return b.priority - a.priority;
|
|
155
|
-
}
|
|
156
|
-
return a.priority - b.priority;
|
|
89
|
+
if (a.isEnd !== b.isEnd) return a.isEnd ? -1 : 1;
|
|
90
|
+
return 0;
|
|
157
91
|
});
|
|
158
92
|
let result = "";
|
|
159
93
|
let lastPos = 0;
|
|
@@ -162,7 +96,7 @@ function entitiesToMarkdown(text, entities) {
|
|
|
162
96
|
lastPos = marker.pos;
|
|
163
97
|
}
|
|
164
98
|
result += text.substring(lastPos);
|
|
165
|
-
result = result.replace(
|
|
99
|
+
result = result.replace(/\*\*\s*\*\*/g, " ").replace(/\*{4,}/g, "").replace(/\*{3}/g, "").replace(/\n{3,}/g, "\n\n");
|
|
166
100
|
return result;
|
|
167
101
|
}
|
|
168
102
|
async function defaultReadline(prompt) {
|