koishi-plugin-nitter 0.0.1 → 0.0.2
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 +7 -8
- package/lib/translate.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -73,7 +73,7 @@ function setGoogleTranslate(key, proxy) {
|
|
|
73
73
|
}, "translate");
|
|
74
74
|
}
|
|
75
75
|
__name(setGoogleTranslate, "setGoogleTranslate");
|
|
76
|
-
function setSiliconTranslate(key, model, prompt) {
|
|
76
|
+
function setSiliconTranslate(key, model, prompt, timeout = 6e4) {
|
|
77
77
|
translate = /* @__PURE__ */ __name(async (texts) => {
|
|
78
78
|
const url = "https://api.siliconflow.cn/v1/chat/completions";
|
|
79
79
|
let data;
|
|
@@ -86,7 +86,7 @@ function setSiliconTranslate(key, model, prompt) {
|
|
|
86
86
|
"Content-Type": "application/json"
|
|
87
87
|
},
|
|
88
88
|
data: {
|
|
89
|
-
model
|
|
89
|
+
model,
|
|
90
90
|
messages: [
|
|
91
91
|
{
|
|
92
92
|
role: "system",
|
|
@@ -104,8 +104,7 @@ ${JSON.stringify(texts)}`
|
|
|
104
104
|
// 较低的温度值使翻译更稳定
|
|
105
105
|
response_format: { type: "json_object" }
|
|
106
106
|
},
|
|
107
|
-
timeout
|
|
108
|
-
// 30秒超时
|
|
107
|
+
timeout
|
|
109
108
|
});
|
|
110
109
|
if (response.data && response.data.choices && response.data.choices[0]) {
|
|
111
110
|
const content = response.data.choices[0].message.content;
|
|
@@ -172,7 +171,8 @@ var Config = import_koishi.Schema.intersect([
|
|
|
172
171
|
enableTranslate: import_koishi.Schema.const("silicon").required(),
|
|
173
172
|
siliconApiKey: import_koishi.Schema.string().required().description("访问https://www.siliconflow.cn/获取"),
|
|
174
173
|
model: import_koishi.Schema.string().required().description("模型名称"),
|
|
175
|
-
prompt: import_koishi.Schema.string().required().default("你是一个专业的HTML翻译助手。请将一个HTML数组翻译为中文,严格遵循以下规则:\n1. 翻译文本内容,包括链接标签(如<a>)内的显示文本\n2.保持所有HTML标签、属性、class、id,以及结构和格式,URL链接完全不变\n3. 返回一个严格的由html文本组成的JSON数组,包含与输入数量完全相同的翻译结果,不要添加任何额外说明").role("textarea").description("提示词")
|
|
174
|
+
prompt: import_koishi.Schema.string().required().default("你是一个专业的HTML翻译助手。请将一个HTML数组翻译为中文,严格遵循以下规则:\n1. 翻译文本内容,包括链接标签(如<a>)内的显示文本\n2.保持所有HTML标签、属性、class、id,以及结构和格式,URL链接完全不变\n3. 返回一个严格的由html文本组成的JSON数组,包含与输入数量完全相同的翻译结果,不要添加任何额外说明").role("textarea").description("提示词"),
|
|
175
|
+
timeout: import_koishi.Schema.number().default(6e4).description("等待翻译时长")
|
|
176
176
|
}),
|
|
177
177
|
import_koishi.Schema.object({})
|
|
178
178
|
]),
|
|
@@ -196,7 +196,7 @@ function apply(ctx, config) {
|
|
|
196
196
|
if (config.enableTranslate == "google") {
|
|
197
197
|
setGoogleTranslate(config.googleApiKey, config.proxy);
|
|
198
198
|
} else if (config.enableTranslate == "silicon") {
|
|
199
|
-
setSiliconTranslate(config.siliconApiKey, config.model, config.prompt);
|
|
199
|
+
setSiliconTranslate(config.siliconApiKey, config.model, config.prompt, config.timeout);
|
|
200
200
|
}
|
|
201
201
|
const tweetList = await getFollowedFeed();
|
|
202
202
|
for (const data of tweetList) {
|
|
@@ -249,7 +249,6 @@ function apply(ctx, config) {
|
|
|
249
249
|
});
|
|
250
250
|
async function broadcast(account, tweetId) {
|
|
251
251
|
try {
|
|
252
|
-
console.log(1);
|
|
253
252
|
const [screenshot, imageUrls] = await renderTweetScreenshot(ctx, tweetId, config);
|
|
254
253
|
const screenshotMsg = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: "data:image/png;base64," + screenshot.toString("base64") });
|
|
255
254
|
ctx.subscription.broadcast(config.app, account, screenshotMsg);
|
|
@@ -258,7 +257,7 @@ function apply(ctx, config) {
|
|
|
258
257
|
ctx.subscription.broadcastForward(config.app, account, picsForward);
|
|
259
258
|
}
|
|
260
259
|
} catch (error) {
|
|
261
|
-
ctx.logger("
|
|
260
|
+
ctx.logger("nitter").error("获取推文失败:", error);
|
|
262
261
|
}
|
|
263
262
|
}
|
|
264
263
|
__name(broadcast, "broadcast");
|
package/lib/translate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Page } from 'puppeteer-core';
|
|
2
2
|
export declare function retry(retries: number, fn: () => any, delay?: number): any;
|
|
3
3
|
export declare function setGoogleTranslate(key: string, proxy: string): void;
|
|
4
|
-
export declare function setSiliconTranslate(key: string, model: string, prompt: string): void;
|
|
4
|
+
export declare function setSiliconTranslate(key: string, model: string, prompt: string, timeout?: number): void;
|
|
5
5
|
export declare function addTranslate(page: Page, className: string): Promise<void>;
|