dsh-shlr-bilitoolkit 0.1.11 → 0.1.13
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/AGENTS.md +7 -40
- package/README.md +1 -1
- package/dist/apis/comment.d.ts +4 -0
- package/dist/apis/comment.js +21 -0
- package/dist/dsh.js +29 -0
- package/dist/endpoints.d.ts +1 -0
- package/dist/endpoints.js +1 -0
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -1,43 +1,10 @@
|
|
|
1
|
-
# AGENTS.md — dsh-bili-toolkit
|
|
1
|
+
# AGENTS.md — dsh-bili-toolkit(Agent 必读)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 登录(务必遵守)
|
|
4
|
+
用户要登录 B 站,或任何操作返回未登录(`-101` / `未登录` / `CookieError`)时:
|
|
5
|
+
**必须调用 `bili_gen_qr`,并把返回的二维码图片展示给用户扫码**——用 `qrDataUrl` 以 Markdown 图片 `` 渲染(或引用 `qrImageUrl` / `qrImagePath`)。
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
禁止:只给链接、用 ASCII/文本二维码、让用户自己跑命令。用户扫码确认后调用 `bili_login_status` 完成登录并保存 Cookie。
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
1. **必须调用 `bili_gen_qr`** —— 这是登录 B 站的唯一入口。它会返回二维码图片:
|
|
11
|
-
`qrDataUrl`(base64 data URL)、`qrImageUrl`(`file://` 链接)、`qrImagePath`(本地 PNG 绝对路径)。
|
|
12
|
-
2. **必须把二维码图片原样展示给用户**:用 Markdown 图片 ``
|
|
13
|
-
(或引用 `qrImageUrl` / `qrImagePath`),让用户能直接扫。
|
|
14
|
-
3. 提示用户用「哔哩哔哩」App 扫描该二维码,并在手机上点「确认登录」。
|
|
15
|
-
4. 用户确认后,调用 `bili_login_status` 轮询确认——成功后会自动把 Cookie 保存到
|
|
16
|
-
`bili_data/bili_cookies.json`。
|
|
17
|
-
|
|
18
|
-
**禁止事项:**
|
|
19
|
-
- 不要用 ASCII / 文本二维码代替图片。
|
|
20
|
-
- 不要只扔一个链接给用户、不展示图片。
|
|
21
|
-
- 不要让用户自己去终端跑 `npm run login`(除非明确处于终端 / CLI 环境)。
|
|
22
|
-
- 不要在未展示二维码的情况下就回复「请登录」。
|
|
23
|
-
|
|
24
|
-
## 数据位置
|
|
25
|
-
|
|
26
|
-
统一放在数据目录(默认 `bili_data/`,相对 dsh 工作目录,可用 `BILI_DATA_DIR` 改):
|
|
27
|
-
|
|
28
|
-
| 文件 | 用途 |
|
|
29
|
-
| --- | --- |
|
|
30
|
-
| `bili_cookies.json` | 登录 Cookie(SESSDATA / bili_jct) |
|
|
31
|
-
| `bili_cache.json` | WBI 签名密钥 + bvid→aid 缓存 |
|
|
32
|
-
| `bili_qrcode.png` | 最近一次生成的登录二维码 |
|
|
33
|
-
| `bili_device.json` | 私信设备号 dev_id(跨重启稳定,勿频繁变动) |
|
|
34
|
-
|
|
35
|
-
## 写操作需确认
|
|
36
|
-
|
|
37
|
-
点赞 / 收藏 / 投币 / 关注 / 评论 / 私信 / 三连 / 发动态 / 改资料等会**真实修改账号状态**,
|
|
38
|
-
执行前应先与用户确认。投币不可退回。
|
|
39
|
-
|
|
40
|
-
## 遇到签名失效
|
|
41
|
-
|
|
42
|
-
若请求报 `-403` / `-352`(WBI 签名失效),可调用 `bili_cache_clear` 清空缓存后重试;
|
|
43
|
-
不影响 Cookie / 登录态。
|
|
9
|
+
## 其它
|
|
10
|
+
全部能力见各 `bili_*` 工具描述;写操作会真实修改账号状态,执行前先与用户确认。
|
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` / `bili_video_pagelist` / `bili_video_subtitles` / `bili_video_playurl` / `bili_video_status` / `bili_space_collections` / `bili_space_collection` / `bili_fav_folder_videos` / `bili_dynamic_detail` / `bili_notify_ats` / `bili_notify_likes` / `bili_message_unread` / `bili_message_history` / `bili_relation_stat` / `bili_user_following` / `bili_profile_info` / `bili_comment_replies`
|
|
75
|
-
- 写操作:`bili_like` / `bili_follow` / `bili_favorite` / `bili_send_comment` / `bili_send_message` / `bili_triple` / `bili_dynamic_publish` / `bili_dynamic_repost` / `bili_coin` / `bili_unfavorite` / `bili_fav_folder_create` / `bili_fav_folder_delete` / `bili_dynamic_like` / `bili_dynamic_delete` / `bili_comment_send` / `bili_comment_reply` / `bili_comment_delete` / `bili_message_recall` / `bili_profile_update_sign` / `bili_profile_update`(均会真实修改账号状态,需登录)
|
|
75
|
+
- 写操作:`bili_like` / `bili_follow` / `bili_favorite` / `bili_send_comment` / `bili_send_message` / `bili_triple` / `bili_dynamic_publish` / `bili_dynamic_repost` / `bili_coin` / `bili_unfavorite` / `bili_fav_folder_create` / `bili_fav_folder_delete` / `bili_dynamic_like` / `bili_dynamic_delete` / `bili_comment_send` / `bili_comment_reply` / `bili_comment_delete` / `bili_comment_like` / `bili_message_recall` / `bili_profile_update_sign` / `bili_profile_update`(均会真实修改账号状态,需登录)
|
|
76
76
|
- 辅助:`bili_login_status`(查登录态)/ `bili_gen_qr`(生成扫码登录二维码)/ `bili_cache_clear`(清空本地缓存)
|
|
77
77
|
- 工具读取 `BILI_COOKIE_FILE`(默认 `bili_data/bili_cookies.json`)作为登录态。
|
|
78
78
|
- **数据目录**:Cookie / 缓存 / 二维码 / 设备号统一放在一个目录里,默认 `bili_data/`(相对 dsh 工作目录),避免散落污染工作目录。可用 `BILI_DATA_DIR` 改目录;`BILI_COOKIE_FILE` / `BILI_CACHE_FILE` / `BILI_QR_FILE` / `BILI_DEVICE_FILE` 可精确指定单个文件。设备号(私信 `dev_id`)会落盘到 `bili_data/bili_device.json`,跨重启保持稳定,避免被 B 站当成新设备触发风控。兼容旧版:若新目录还没有 Cookie、而旧位置(`./bili_cookies.json`)有,会继续沿用旧的。
|
package/dist/apis/comment.d.ts
CHANGED
|
@@ -19,19 +19,23 @@ export declare class CommentAPI {
|
|
|
19
19
|
private send;
|
|
20
20
|
private replies;
|
|
21
21
|
private delete;
|
|
22
|
+
private like;
|
|
22
23
|
listVideo(bvid: string, page?: number, pageSize?: number, sort?: string | number): Promise<[Comment[], number]>;
|
|
23
24
|
iterVideo(bvid: string, pageSize?: number, sort?: string | number, maxPages?: number): AsyncGenerator<Comment, any, any>;
|
|
24
25
|
sendVideo(bvid: string, message: string, root?: number | null, parent?: number | null): Promise<Comment>;
|
|
25
26
|
replyVideo(bvid: string, rootRpid: number, message: string, parentRpid?: number | null): Promise<Comment>;
|
|
26
27
|
repliesVideo(bvid: string, rootRpid: number, page?: number, pageSize?: number): Promise<[Comment[], number]>;
|
|
27
28
|
deleteVideo(bvid: string, rpid: number): Promise<void>;
|
|
29
|
+
likeVideo(bvid: string, rpid: number, liked?: boolean): Promise<void>;
|
|
28
30
|
listDynamic(dynamicId: string | number, page?: number, pageSize?: number, sort?: string | number): Promise<[Comment[], number]>;
|
|
29
31
|
iterDynamic(dynamicId: string | number, pageSize?: number, sort?: string | number, maxPages?: number): AsyncGenerator<Comment, any, any>;
|
|
30
32
|
sendDynamic(dynamicId: string | number, message: string, root?: number | null, parent?: number | null): Promise<Comment>;
|
|
31
33
|
repliesDynamic(dynamicId: string | number, rootRpid: number, page?: number, pageSize?: number): Promise<[Comment[], number]>;
|
|
32
34
|
deleteDynamic(dynamicId: string | number, rpid: number): Promise<void>;
|
|
35
|
+
likeDynamic(dynamicId: string | number, rpid: number, liked?: boolean): Promise<void>;
|
|
33
36
|
listArticle(articleId: unknown, page?: number, pageSize?: number, sort?: string | number): Promise<[Comment[], number]>;
|
|
34
37
|
sendArticle(articleId: unknown, message: string, root?: number | null, parent?: number | null): Promise<Comment>;
|
|
35
38
|
repliesArticle(articleId: unknown, rootRpid: number, page?: number, pageSize?: number): Promise<[Comment[], number]>;
|
|
36
39
|
deleteArticle(articleId: unknown, rpid: number): Promise<void>;
|
|
40
|
+
likeArticle(articleId: unknown, rpid: number, liked?: boolean): Promise<void>;
|
|
37
41
|
}
|
package/dist/apis/comment.js
CHANGED
|
@@ -90,6 +90,15 @@ export class CommentAPI {
|
|
|
90
90
|
async delete(oid, type, rpid, headers) {
|
|
91
91
|
await this.client.post(endpoints.REPLY_DEL, { type, oid, rpid, csrf: this.client.csrf }, headers);
|
|
92
92
|
}
|
|
93
|
+
async like(oid, type, rpid, liked = true, headers) {
|
|
94
|
+
await this.client.post(endpoints.REPLY_ACTION, {
|
|
95
|
+
oid,
|
|
96
|
+
type,
|
|
97
|
+
rpid: Number(rpid),
|
|
98
|
+
action: liked ? 1 : 2, // 1 点赞 / 2 取消
|
|
99
|
+
csrf: this.client.csrf,
|
|
100
|
+
}, headers);
|
|
101
|
+
}
|
|
93
102
|
// ------------------------------------------------------------------ 视频
|
|
94
103
|
async listVideo(bvid, page = 1, pageSize = 20, sort = "time") {
|
|
95
104
|
CommentAPI.sortValue(sort); // 先校验,避免参数错误时还去请求 aid
|
|
@@ -117,6 +126,10 @@ export class CommentAPI {
|
|
|
117
126
|
const aid = await this.client.video.resolveAid(bvid);
|
|
118
127
|
await this.delete(aid, 1, rpid, CommentAPI.videoHeaders(bvid));
|
|
119
128
|
}
|
|
129
|
+
async likeVideo(bvid, rpid, liked = true) {
|
|
130
|
+
const aid = await this.client.video.resolveAid(bvid);
|
|
131
|
+
await this.like(aid, 1, rpid, liked, CommentAPI.videoHeaders(bvid));
|
|
132
|
+
}
|
|
120
133
|
// ------------------------------------------------------------------ 动态
|
|
121
134
|
async listDynamic(dynamicId, page = 1, pageSize = 20, sort = "time") {
|
|
122
135
|
CommentAPI.sortValue(sort);
|
|
@@ -141,6 +154,10 @@ export class CommentAPI {
|
|
|
141
154
|
const [commentType, oid] = await this.dynamicTarget(dynamicId);
|
|
142
155
|
await this.delete(Number(oid), commentType, rpid, CommentAPI.dynamicHeaders(dynamicId));
|
|
143
156
|
}
|
|
157
|
+
async likeDynamic(dynamicId, rpid, liked = true) {
|
|
158
|
+
const [commentType, oid] = await this.dynamicTarget(dynamicId);
|
|
159
|
+
await this.like(Number(oid), commentType, rpid, liked, CommentAPI.dynamicHeaders(dynamicId));
|
|
160
|
+
}
|
|
144
161
|
// ------------------------------------------------------------------ 专栏
|
|
145
162
|
async listArticle(articleId, page = 1, pageSize = 20, sort = "time") {
|
|
146
163
|
CommentAPI.sortValue(sort);
|
|
@@ -161,4 +178,8 @@ export class CommentAPI {
|
|
|
161
178
|
const cvid = parseArticleId(articleId);
|
|
162
179
|
await this.delete(cvid, 12, rpid, CommentAPI.articleHeaders(cvid));
|
|
163
180
|
}
|
|
181
|
+
async likeArticle(articleId, rpid, liked = true) {
|
|
182
|
+
const cvid = parseArticleId(articleId);
|
|
183
|
+
await this.like(cvid, 12, rpid, liked, CommentAPI.articleHeaders(cvid));
|
|
184
|
+
}
|
|
164
185
|
}
|
package/dist/dsh.js
CHANGED
|
@@ -854,6 +854,35 @@ export const TOOLS = [
|
|
|
854
854
|
return { ok: true };
|
|
855
855
|
},
|
|
856
856
|
},
|
|
857
|
+
{
|
|
858
|
+
id: "bili_comment_like",
|
|
859
|
+
description: "给一条评论点赞或取消点赞(写操作,需登录)。",
|
|
860
|
+
parameters: {
|
|
861
|
+
type: "object",
|
|
862
|
+
properties: {
|
|
863
|
+
target: { type: "string", enum: ["video", "dynamic", "article"], default: "video" },
|
|
864
|
+
id: { type: "string" },
|
|
865
|
+
rpid: { type: "integer" },
|
|
866
|
+
liked: { type: "boolean", default: true },
|
|
867
|
+
},
|
|
868
|
+
required: ["id", "rpid"],
|
|
869
|
+
},
|
|
870
|
+
handler: async (a) => {
|
|
871
|
+
const c = await getClient();
|
|
872
|
+
const target = String(a.target ?? "video");
|
|
873
|
+
const rpid = Number(a.rpid);
|
|
874
|
+
const liked = Boolean(a.liked ?? true);
|
|
875
|
+
if (target === "video")
|
|
876
|
+
await c.comment.likeVideo(a.id, rpid, liked);
|
|
877
|
+
else if (target === "dynamic")
|
|
878
|
+
await c.comment.likeDynamic(a.id, rpid, liked);
|
|
879
|
+
else if (target === "article")
|
|
880
|
+
await c.comment.likeArticle(a.id, rpid, liked);
|
|
881
|
+
else
|
|
882
|
+
throw new Error("target 只支持 video / dynamic / article");
|
|
883
|
+
return { ok: true };
|
|
884
|
+
},
|
|
885
|
+
},
|
|
857
886
|
// ---- 消息中心补充 ----
|
|
858
887
|
{
|
|
859
888
|
id: "bili_notify_ats",
|
package/dist/endpoints.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare const REPLY_LIST = "https://api.bilibili.com/x/v2/reply";
|
|
|
50
50
|
export declare const REPLY_ADD = "https://api.bilibili.com/x/v2/reply/add";
|
|
51
51
|
export declare const REPLY_DEL = "https://api.bilibili.com/x/v2/reply/del";
|
|
52
52
|
export declare const REPLY_REPLY = "https://api.bilibili.com/x/v2/reply/reply";
|
|
53
|
+
export declare const REPLY_ACTION = "https://api.bilibili.com/x/v2/reply/action";
|
|
53
54
|
export declare const IM_SEND = "https://api.vc.bilibili.com/web_im/v1/web_im/send_msg";
|
|
54
55
|
export declare const IM_FETCH = "https://api.vc.bilibili.com/svr_sync/v1/svr_sync/fetch_session_msgs";
|
|
55
56
|
export declare const IM_UNREAD = "https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread";
|
package/dist/endpoints.js
CHANGED
|
@@ -63,6 +63,7 @@ export const REPLY_LIST = `${API_BASE}/x/v2/reply`;
|
|
|
63
63
|
export const REPLY_ADD = `${API_BASE}/x/v2/reply/add`;
|
|
64
64
|
export const REPLY_DEL = `${API_BASE}/x/v2/reply/del`;
|
|
65
65
|
export const REPLY_REPLY = `${API_BASE}/x/v2/reply/reply`;
|
|
66
|
+
export const REPLY_ACTION = `${API_BASE}/x/v2/reply/action`;
|
|
66
67
|
// ---- 私信 ----
|
|
67
68
|
export const IM_SEND = `${VC_BASE}/web_im/v1/web_im/send_msg`;
|
|
68
69
|
export const IM_FETCH = `${VC_BASE}/svr_sync/v1/svr_sync/fetch_session_msgs`;
|