koishi-plugin-nitter 0.0.8 → 0.0.10
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.d.ts +1 -0
- package/lib/index.js +30 -15
- package/lib/retry.d.ts +1 -0
- package/lib/translate.d.ts +0 -1
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -41,18 +41,21 @@ var import_koishi = require("koishi");
|
|
|
41
41
|
// src/translate.ts
|
|
42
42
|
var import_axios = __toESM(require("axios"));
|
|
43
43
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
44
|
+
|
|
45
|
+
// src/retry.ts
|
|
44
46
|
async function retry(retries, fn, delay = 500) {
|
|
45
47
|
try {
|
|
46
|
-
await fn();
|
|
47
|
-
return Promise.resolve();
|
|
48
|
+
return await fn();
|
|
48
49
|
} catch (err) {
|
|
49
50
|
console.log(`剩余${retries}次尝试`, err);
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
if (retries <= 1) throw err;
|
|
52
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
53
|
+
return retry(retries - 1, fn, delay * 2);
|
|
52
54
|
}
|
|
53
|
-
;
|
|
54
55
|
}
|
|
55
56
|
__name(retry, "retry");
|
|
57
|
+
|
|
58
|
+
// src/translate.ts
|
|
56
59
|
var translate;
|
|
57
60
|
function setGoogleTranslate(key, proxy) {
|
|
58
61
|
translate = /* @__PURE__ */ __name((texts) => {
|
|
@@ -142,8 +145,8 @@ async function addTranslate(page, className) {
|
|
|
142
145
|
tempDiv.innerHTML = translatedHTMLs2[index];
|
|
143
146
|
const newElement = tempDiv.firstElementChild;
|
|
144
147
|
if (newElement) {
|
|
145
|
-
element.insertAdjacentElement("
|
|
146
|
-
element.insertAdjacentHTML("
|
|
148
|
+
element.insertAdjacentElement("beforebegin", newElement);
|
|
149
|
+
element.insertAdjacentHTML("beforebegin", '<div style="height: 1px;background-color: #ccc; margin-top: 10px; margin-bottom: 10px;"></div>');
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
});
|
|
@@ -269,7 +272,8 @@ var Config = import_koishi.Schema.intersect([
|
|
|
269
272
|
}).description("订阅配置"),
|
|
270
273
|
import_koishi.Schema.object({
|
|
271
274
|
enableReTweet: import_koishi.Schema.boolean().default(false).description("是否发送转推"),
|
|
272
|
-
sendPic: import_koishi.Schema.boolean().default(false).description("是否单独发送推文中的图片")
|
|
275
|
+
sendPic: import_koishi.Schema.boolean().default(false).description("是否单独发送推文中的图片"),
|
|
276
|
+
cronString: import_koishi.Schema.string().default("15 */5 * * * *").description("使用cron表达式描述检查更新的时间,默认为每隔5分钟检查一次")
|
|
273
277
|
}).description("推送设置"),
|
|
274
278
|
import_koishi.Schema.union([
|
|
275
279
|
import_koishi.Schema.object({
|
|
@@ -289,7 +293,8 @@ function apply(ctx, config) {
|
|
|
289
293
|
config.nitterUrl = config.nitterUrl.replace(/\/+$/, "");
|
|
290
294
|
const twitterClient = new import_rettiwt_api.Rettiwt({
|
|
291
295
|
apiKey: config.apiKey,
|
|
292
|
-
proxyUrl: config.proxy ? new URL(config.proxy) : void 0
|
|
296
|
+
proxyUrl: config.proxy ? new URL(config.proxy) : void 0,
|
|
297
|
+
logging: true
|
|
293
298
|
});
|
|
294
299
|
let cronJob;
|
|
295
300
|
const queue = new taskQueue();
|
|
@@ -307,7 +312,7 @@ function apply(ctx, config) {
|
|
|
307
312
|
};
|
|
308
313
|
}));
|
|
309
314
|
queue.onProcess(broadcast);
|
|
310
|
-
cronJob = (0, import_node_cron.schedule)(
|
|
315
|
+
cronJob = (0, import_node_cron.schedule)(config.cronString, checkForUpdates);
|
|
311
316
|
ctx.on("dispose", () => {
|
|
312
317
|
cronJob.stop();
|
|
313
318
|
});
|
|
@@ -319,9 +324,14 @@ function apply(ctx, config) {
|
|
|
319
324
|
const followingIdList = followingList.map((user) => user.userName);
|
|
320
325
|
for (const id of whiteList) {
|
|
321
326
|
if (!followingIdList.includes(id)) {
|
|
322
|
-
|
|
327
|
+
let user;
|
|
328
|
+
await retry(3, async () => {
|
|
329
|
+
user = await twitterClient.user.details(id);
|
|
330
|
+
});
|
|
323
331
|
await new Promise((resolve) => setTimeout(resolve, 3 * 1e3));
|
|
324
|
-
await
|
|
332
|
+
await retry(3, async () => {
|
|
333
|
+
await twitterClient.user.follow(user.id);
|
|
334
|
+
}, 30 * 1e3);
|
|
325
335
|
console.log(`关注${id}成功`);
|
|
326
336
|
await new Promise((resolve) => setTimeout(resolve, 30 * 1e3));
|
|
327
337
|
}
|
|
@@ -360,8 +370,12 @@ function apply(ctx, config) {
|
|
|
360
370
|
try {
|
|
361
371
|
const [screenshot, imageUrls, hlsUrls] = await renderTweetScreenshot(tweetId);
|
|
362
372
|
const screenshotMsg = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: "data:image/png;base64," + screenshot.toString("base64") });
|
|
363
|
-
ctx.subscription.broadcast(config.app, account, screenshotMsg);
|
|
364
|
-
let forwardMsg = [
|
|
373
|
+
await ctx.subscription.broadcast(config.app, account, screenshotMsg);
|
|
374
|
+
let forwardMsg = [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("message", { children: [
|
|
375
|
+
ctx.subscription.getName(config.app, account),
|
|
376
|
+
" ",
|
|
377
|
+
ctx.subscription.getAccount(config.app, account)
|
|
378
|
+
] })];
|
|
365
379
|
const videoUrls = await downloadVideosToBase64(hlsUrls, config.maxSize);
|
|
366
380
|
if (imageUrls.length > 0) {
|
|
367
381
|
forwardMsg.push(...imageUrls.map((url) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: url }) })));
|
|
@@ -390,7 +404,7 @@ function apply(ctx, config) {
|
|
|
390
404
|
for (const data of tweetList) {
|
|
391
405
|
if (!config.enableReTweet && data.retweetedTweet)
|
|
392
406
|
continue;
|
|
393
|
-
if ((/* @__PURE__ */ new Date()).getTime() - new Date(data.createdAt).getTime() > 60 * 60 * 1e3)
|
|
407
|
+
if ((/* @__PURE__ */ new Date()).getTime() - new Date(data.createdAt).getTime() > 2 * 60 * 60 * 1e3)
|
|
394
408
|
continue;
|
|
395
409
|
if ((await ctx.database.get("nitter_records", { id: data.id })).length > 0)
|
|
396
410
|
continue;
|
|
@@ -412,6 +426,7 @@ function apply(ctx, config) {
|
|
|
412
426
|
}
|
|
413
427
|
const page = await puppeteer.page();
|
|
414
428
|
try {
|
|
429
|
+
await page.setCacheEnabled(false);
|
|
415
430
|
const tweetUrl = `${config.nitterUrl}/i/status/${tweetId}`;
|
|
416
431
|
await retry(3, async () => {
|
|
417
432
|
await page.goto(tweetUrl);
|
package/lib/retry.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function retry<T>(retries: number, fn: () => Promise<T> | T, delay?: number): Promise<T>;
|
package/lib/translate.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Page } from 'puppeteer-core';
|
|
2
|
-
export declare function retry(retries: number, fn: () => any, delay?: number): any;
|
|
3
2
|
export declare function setGoogleTranslate(key: string, proxy: string): void;
|
|
4
3
|
export declare function setOpenAiTranslate(url: string, key: string, model: string, prompt: string, temperature: number, timeout?: number): void;
|
|
5
4
|
export declare function addTranslate(page: Page, className: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-nitter",
|
|
3
3
|
"description": "使用Rettiwt-API订阅推文,并使用nitter渲染",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"axios": "^1.12.2",
|
|
20
20
|
"https-proxy-agent": "^7.0.6",
|
|
21
21
|
"koishi": "^4.18.9",
|
|
22
|
-
"koishi-plugin-subscription": "^0.0.
|
|
22
|
+
"koishi-plugin-subscription": "^0.0.6"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"fluent-ffmpeg": "^2.1.3",
|
|
26
26
|
"node-cron": "^4.2.1",
|
|
27
|
-
"rettiwt-api": "^6.1.
|
|
27
|
+
"rettiwt-api": "^6.1.7"
|
|
28
28
|
}
|
|
29
29
|
}
|