dsh-shlr-bilitoolkit 0.1.5 → 0.1.7
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/README.md +1 -1
- package/dist/dsh.d.ts +7 -0
- package/dist/dsh.js +77 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ const [ups, _] = await client.space.videos(574115689, 1, 10);
|
|
|
72
72
|
- 包名 `dsh-shlr-bilitoolkit`(符合 `dsh-` 前缀约定),`package.json` 里声明了 `dsh.bundle.patch: ./cordis.patch.yml`,因此会被 dsh 识别为插件而非普通库。
|
|
73
73
|
- 入口 `src/dsh.ts` 导出 `apply(ctx)`,注册一组工具(读取为主,写操作明确标注「需登录 / 谨慎」):
|
|
74
74
|
- 读取:`bili_recommend` / `bili_video_detail` / `bili_video_subtitle` / `bili_search_video` / `bili_search_user` / `bili_space_info` / `bili_space_videos` / `bili_article_view` / `bili_article_list` / `bili_dynamic_feed` / `bili_dynamic_space` / `bili_comment_list` / `bili_relation_followings` / `bili_relation_followers` / `bili_notify_unread` / `bili_notify_replies` / `bili_fav_folders`
|
|
75
|
-
- 写操作:`bili_like` / `bili_follow` / `bili_favorite` / `bili_send_comment` / `bili_send_message` / `bili_triple`(均会真实修改账号状态,需登录)
|
|
75
|
+
- 写操作:`bili_like` / `bili_follow` / `bili_favorite` / `bili_send_comment` / `bili_send_message` / `bili_triple` / `bili_dynamic_publish` / `bili_dynamic_repost`(均会真实修改账号状态,需登录)
|
|
76
76
|
- 辅助:`bili_login_status`(查登录态)/ `bili_gen_qr`(生成扫码登录二维码)/ `bili_cache_clear`(清空本地缓存)
|
|
77
77
|
- 工具读取 `BILI_COOKIE_FILE`(默认 `bili_cookies.json`)作为登录态。
|
|
78
78
|
- **扫码登录(独立获取 Cookie)**:运行 `npm run login`,终端会打印 ASCII 二维码,用「哔哩哔哩」App 扫码并确认后,Cookie 自动写入 `bili_cookies.json`。也可在对话里先调 `bili_login_status` 查登录态、调 `bili_gen_qr` 拿二维码链接与可直接展示的 `ascii` 二维码。写操作(点赞 / 收藏 / 投币 / 关注 / 评论 / 私信 / 三连)都依赖该 Cookie 中的 `SESSDATA` / `bili_jct`。
|
package/dist/dsh.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ export interface DshTool {
|
|
|
22
22
|
presentationMeta?: (args: any, value: any) => unknown;
|
|
23
23
|
presentResult?: (args: any, result: any) => any;
|
|
24
24
|
}
|
|
25
|
+
/** 把任意返回值规整成「可无损序列化」的 JSON。
|
|
26
|
+
*
|
|
27
|
+
* dsh 要求工具的规范值必须能无损 JSON 序列化:对象里不能带 `undefined`
|
|
28
|
+
* (`JSON.stringify` 会静默丢键,导致 round-trip 丢失),也不能有 NaN/Infinity。
|
|
29
|
+
* 这里统一处理:丢 undefined、NaN/Infinity 转 null、bigint 转字符串。
|
|
30
|
+
*/
|
|
31
|
+
export declare function toLosslessJson(value: unknown): unknown;
|
|
25
32
|
export declare const TOOLS: DshTool[];
|
|
26
33
|
export declare function apply(ctx: any): void;
|
|
27
34
|
export * from "./index.js";
|
package/dist/dsh.js
CHANGED
|
@@ -64,6 +64,34 @@ function toDshParameters(schema) {
|
|
|
64
64
|
function textOf(value) {
|
|
65
65
|
return typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
66
66
|
}
|
|
67
|
+
/** 把任意返回值规整成「可无损序列化」的 JSON。
|
|
68
|
+
*
|
|
69
|
+
* dsh 要求工具的规范值必须能无损 JSON 序列化:对象里不能带 `undefined`
|
|
70
|
+
* (`JSON.stringify` 会静默丢键,导致 round-trip 丢失),也不能有 NaN/Infinity。
|
|
71
|
+
* 这里统一处理:丢 undefined、NaN/Infinity 转 null、bigint 转字符串。
|
|
72
|
+
*/
|
|
73
|
+
export function toLosslessJson(value) {
|
|
74
|
+
if (typeof value === "number")
|
|
75
|
+
return Number.isFinite(value) ? value : null;
|
|
76
|
+
if (typeof value === "bigint")
|
|
77
|
+
return value.toString();
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
return value.map((v) => {
|
|
80
|
+
const sv = toLosslessJson(v);
|
|
81
|
+
return sv === undefined ? null : sv;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (value && typeof value === "object") {
|
|
85
|
+
const out = {};
|
|
86
|
+
for (const [k, v] of Object.entries(value)) {
|
|
87
|
+
const sv = toLosslessJson(v);
|
|
88
|
+
if (sv !== undefined)
|
|
89
|
+
out[k] = sv;
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
return value; // string / boolean / null / undefined
|
|
94
|
+
}
|
|
67
95
|
export const TOOLS = [
|
|
68
96
|
{
|
|
69
97
|
id: "bili_recommend",
|
|
@@ -416,6 +444,53 @@ export const TOOLS = [
|
|
|
416
444
|
},
|
|
417
445
|
handler: async (a) => (await getClient()).interact.triple(a.bvid, Number(a.coinCount ?? 2)),
|
|
418
446
|
},
|
|
447
|
+
// ---- 动态(写操作,需登录,会公开展示在主页) ----
|
|
448
|
+
{
|
|
449
|
+
id: "bili_dynamic_publish",
|
|
450
|
+
description: "发布一条文字动态(写操作,需登录,会公开展示在你的主页)。返回动态 id 与链接。",
|
|
451
|
+
parameters: {
|
|
452
|
+
type: "object",
|
|
453
|
+
properties: {
|
|
454
|
+
content: { type: "string", description: "动态正文文字内容" },
|
|
455
|
+
atUids: {
|
|
456
|
+
type: "string",
|
|
457
|
+
description: "要 @ 的用户 uid,多个用逗号分隔(可选)",
|
|
458
|
+
},
|
|
459
|
+
closeComment: {
|
|
460
|
+
type: "boolean",
|
|
461
|
+
default: false,
|
|
462
|
+
description: "是否关闭评论",
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
required: ["content"],
|
|
466
|
+
},
|
|
467
|
+
handler: async (a) => {
|
|
468
|
+
const c = await getClient();
|
|
469
|
+
const atUids = String(a.atUids ?? "")
|
|
470
|
+
.split(/[,,\s]+/)
|
|
471
|
+
.map((s) => Number(s.trim()))
|
|
472
|
+
.filter((n) => Number.isFinite(n) && n > 0);
|
|
473
|
+
const id = await c.dynamic.publish(String(a.content ?? ""), atUids, undefined, Boolean(a.closeComment ?? false));
|
|
474
|
+
return { ok: true, dynamicId: id, url: `https://t.bilibili.com/${id}` };
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
id: "bili_dynamic_repost",
|
|
479
|
+
description: "转发一条动态(写操作,需登录)。返回新动态 id 与链接。",
|
|
480
|
+
parameters: {
|
|
481
|
+
type: "object",
|
|
482
|
+
properties: {
|
|
483
|
+
dynamicId: { type: "string", description: "被转发的动态 id" },
|
|
484
|
+
content: { type: "string", description: "转发时附言(可选)" },
|
|
485
|
+
},
|
|
486
|
+
required: ["dynamicId"],
|
|
487
|
+
},
|
|
488
|
+
handler: async (a) => {
|
|
489
|
+
const c = await getClient();
|
|
490
|
+
const id = await c.dynamic.repost(a.dynamicId, String(a.content ?? ""));
|
|
491
|
+
return { ok: true, dynamicId: id, url: `https://t.bilibili.com/${id}` };
|
|
492
|
+
},
|
|
493
|
+
},
|
|
419
494
|
// ---- 登录状态 ----
|
|
420
495
|
{
|
|
421
496
|
id: "bili_login_status",
|
|
@@ -567,7 +642,8 @@ export function apply(ctx) {
|
|
|
567
642
|
parameters: toDshParameters(tool.parameters),
|
|
568
643
|
output,
|
|
569
644
|
async execute(args) {
|
|
570
|
-
|
|
645
|
+
// 统一规整为无损 JSON,避免 toDict 里的 undefined / NaN 触发序列化错误
|
|
646
|
+
return toLosslessJson(await tool.handler(args));
|
|
571
647
|
},
|
|
572
648
|
};
|
|
573
649
|
if (tool.presentResult) {
|