cortico-world-bili-watch 0.2.8 → 0.2.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/CHANGELOG.md +35 -1
- package/package.json +1 -1
- package/src/core/types.ts +256 -250
- package/src/social/service.ts +39 -13
- package/src/social/videoHistory.ts +3 -3
- package/src/world.ts +24 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,43 @@
|
|
|
3
3
|
桌宠的市场按本文件的 `## <版本号>` 分段显示更新说明,
|
|
4
4
|
标题里的版本号必须和 `package.json` 的 `version` 一致。
|
|
5
5
|
|
|
6
|
+
## 0.2.9
|
|
7
|
+
|
|
8
|
+
两个真 bug,都是她实测撞出来的。
|
|
9
|
+
|
|
10
|
+
**① 回复通知发不出去:「暂未取得对方平台账号身份」**
|
|
11
|
+
|
|
12
|
+
只带 `briefId` 去 publish 时,`input.inboxId` 是空的,代码就把它当成"手填 target 的接楼",
|
|
13
|
+
回头去楼中楼里找父评论作者(为了算每人每日上限)。可楼中楼按时间正序分页,
|
|
14
|
+
**刚回复的那条永远在最后一页** —— 只读第 1 页等于永远找不到,于是明明能回的楼被卡死。
|
|
15
|
+
|
|
16
|
+
讽刺的是这个信息收件箱里本来就有(`authorId`),只差没存进凭据。
|
|
17
|
+
|
|
18
|
+
- `prepare` 时把 `recipientId`(收件箱的 authorId)写进凭据
|
|
19
|
+
- `publish` 优先用它,不再盲读楼中楼
|
|
20
|
+
- `parentAuthor` 改成最多翻 3 页(给纯 target 接楼兜底)
|
|
21
|
+
- 离线验证:凭据带 recipientId → 发送前 0 次读取、直接 POST 成功;
|
|
22
|
+
不带 → 仍然明确拒绝(保护没丢)
|
|
23
|
+
|
|
24
|
+
**② 同一条视频被推荐两次**
|
|
25
|
+
|
|
26
|
+
11/06 06:35 和 11/08 00:23 把《免费live2D模型》推了两次,主人连着收两条 @。
|
|
27
|
+
四层防重一层都拦不住:推荐的 requestId 从 briefId 派生,**每次 prepare 都是新键**,
|
|
28
|
+
每次都算"新操作"。
|
|
29
|
+
|
|
30
|
+
- 新增 `recommendAlreadySent()`:按 oid 查成功的推荐记录
|
|
31
|
+
- `bili_recommend({ action: "prepare" })` 命中就拒绝,报「这条视频 11/06 06:35 已经
|
|
32
|
+
推荐给主人了,不重复推」
|
|
33
|
+
- 离线验证:推过的能查到并拦下,没推过的不误拦
|
|
34
|
+
|
|
35
|
+
**顺带**
|
|
36
|
+
|
|
37
|
+
- 删掉一处张冠李戴的注释(`parseVideoRef` 的说明残留在 `normalizeTargetArg` 头上)
|
|
38
|
+
- ENV_PROMPT 补一句:推荐前可以先 `bili_roam({ action: "video" })` 看一眼推没推过
|
|
39
|
+
|
|
6
40
|
## 0.2.8
|
|
7
41
|
|
|
8
|
-
按视频查历史 +
|
|
42
|
+
按视频查历史 + 长内容不再硬夹断。这一版全是她实测提的(2026-11-07 一整天)。
|
|
9
43
|
|
|
10
44
|
**新:`bili_roam({ action: "video", video: "BV…" })`**
|
|
11
45
|
|
package/package.json
CHANGED
package/src/core/types.ts
CHANGED
|
@@ -1,250 +1,256 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* core/types.ts — B 站插件里的所有 ID 与目标类型。
|
|
3
|
-
*
|
|
4
|
-
* ## 为什么 ID 全是字符串
|
|
5
|
-
*
|
|
6
|
-
* B 站的 `aid` / `cid` / `avid` 真的会超过 JS 的安全整数(2^53)。
|
|
7
|
-
* `JSON.parse` 遇到它们会**静默变成一个看起来正常但已经错的值** —— 而且不报错。
|
|
8
|
-
* 所以:**解析前先把 16 位以上的整数转成字符串**(见 `parsePlatformJson`),
|
|
9
|
-
* 之后全程当字符串走,只在需要参与 API 调用时拼成 URL 参数。
|
|
10
|
-
*
|
|
11
|
-
* 这一条不是洁癖:`cid` 错一位就会取到**另一个视频的流**,而画面看起来完全正常。
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/** 视频标识:BV 号或 av 号,统一成 `BV…` / `av…` 两种前缀写法。 */
|
|
15
|
-
export type VideoId = string;
|
|
16
|
-
|
|
17
|
-
/** 分P 的 cid(字符串形式的数字)。 */
|
|
18
|
-
export type Cid = string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 评论区目标。
|
|
22
|
-
*
|
|
23
|
-
* - `oid`:视频 aid / 动态 id(**不是** BV 号 —— B 站评论接口只认数字)
|
|
24
|
-
* - `type`:`1`=视频、`11`=动态、`17`=动态评论
|
|
25
|
-
* - `root`:顶层楼层的 rpid;新评论为 `'0'`
|
|
26
|
-
* - `parent`:要回复的那条评论的 rpid;新评论为 `'0'`
|
|
27
|
-
*
|
|
28
|
-
* **`root` 和 `parent` 必须同时为 `'0'` 或同时非 `'0'`** —— 只给一个是错的,
|
|
29
|
-
* B 站会把它当成"回复到某个不存在的楼层"。这个校验放在 `normalizeTarget()` 里。
|
|
30
|
-
*/
|
|
31
|
-
export interface CommentTarget {
|
|
32
|
-
oid: string;
|
|
33
|
-
type: 1 | 11 | 17;
|
|
34
|
-
root: string;
|
|
35
|
-
parent: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface VideoPart {
|
|
39
|
-
cid: Cid;
|
|
40
|
-
page: number;
|
|
41
|
-
title: string;
|
|
42
|
-
durationSec: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface Video {
|
|
46
|
-
/** BV 号。 */
|
|
47
|
-
id: VideoId;
|
|
48
|
-
aid: string;
|
|
49
|
-
/** 当前选中分P 的 cid。 */
|
|
50
|
-
cid: Cid;
|
|
51
|
-
title: string;
|
|
52
|
-
description: string;
|
|
53
|
-
author: string;
|
|
54
|
-
ownerId: string;
|
|
55
|
-
durationSec: number;
|
|
56
|
-
cover: string;
|
|
57
|
-
url: string;
|
|
58
|
-
parts: VideoPart[];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface Account {
|
|
62
|
-
/** DedeUserID */
|
|
63
|
-
id: string;
|
|
64
|
-
name: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface PublicComment {
|
|
68
|
-
id: string;
|
|
69
|
-
authorId: string;
|
|
70
|
-
author: string;
|
|
71
|
-
text: string;
|
|
72
|
-
createdAt?: number;
|
|
73
|
-
target: CommentTarget;
|
|
74
|
-
replies: PublicComment[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** 一次通知(别人回复我 / @ 我 / 主人评论区)。 */
|
|
78
|
-
export interface InboxItem {
|
|
79
|
-
/** `bilibili:<accountId>:<parent>` —— 用它去重,同一楼重复通知只留一条。 */
|
|
80
|
-
id: string;
|
|
81
|
-
/**
|
|
82
|
-
* 单平台,但**必须写**。
|
|
83
|
-
*
|
|
84
|
-
* `store.rememberContact()` 曾经因为没有这个字段,`item.platform !== 'bilibili'`
|
|
85
|
-
* 恒真、联系人表永远是空的 —— 真机验证「迁移后 contacts 为 0」才发现。
|
|
86
|
-
* 现在统一由 service 填 `'bilibili'`,别再靠 `?? 'bilibili'` 兜底。
|
|
87
|
-
*/
|
|
88
|
-
platform?: string;
|
|
89
|
-
accountId: string;
|
|
90
|
-
authorId: string;
|
|
91
|
-
author: string;
|
|
92
|
-
text: string;
|
|
93
|
-
target: CommentTarget;
|
|
94
|
-
occurredAt: number;
|
|
95
|
-
status: 'pending' | 'handled';
|
|
96
|
-
notificationType: 'reply' | 'mention' | 'focus-video' | 'focus-comment';
|
|
97
|
-
url?: string;
|
|
98
|
-
/** 什么时候该再看(`defer` 用)。 */
|
|
99
|
-
retryAt?: string;
|
|
100
|
-
/** 已经投给模型了没有。**没有它就会每轮重投同一条待办**。 */
|
|
101
|
-
delivered?: boolean;
|
|
102
|
-
deliveredAt?: string;
|
|
103
|
-
/** 这条来自特别关注(主人评论区),有值就走 `focus` 那本账。 */
|
|
104
|
-
focusOwnerId?: string;
|
|
105
|
-
/** 主人评论区自动回应:单独计账,不占普通额度。 */
|
|
106
|
-
ownerAutoReply?: boolean;
|
|
107
|
-
/** 被本机规则直接收尾时的原因(`skip` / `limit` 等),面板会显示。 */
|
|
108
|
-
handling?: { kind: 'unsafe' | 'resource' | 'limit' | 'skip'; reason: string };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** 一次发送的结局。**这五个状态不能混** —— 弄混就是重发或漏发。 */
|
|
112
|
-
export type SendStatus = 'sending' | 'sent' | 'unknown' | 'rejected';
|
|
113
|
-
|
|
114
|
-
export interface VisibilityReport {
|
|
115
|
-
/** `public` = 访客看得到;`self-only` = 平台判定仅自己可见;`unconfirmed` = 核不了。 */
|
|
116
|
-
status: 'public' | 'self-only' | 'unconfirmed';
|
|
117
|
-
detail: string;
|
|
118
|
-
checkedAt: string;
|
|
119
|
-
platformState?: number;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface SendReceipt {
|
|
123
|
-
receiptId: string;
|
|
124
|
-
transport: 'api' | 'browser';
|
|
125
|
-
platformState?: number;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface SendRecord {
|
|
129
|
-
id: string;
|
|
130
|
-
/**
|
|
131
|
-
* 防重主键:`bilibili:<accountId>:<requestId>`。
|
|
132
|
-
*
|
|
133
|
-
* **必须落盘**。`store.operationSends()` 用 `(r.operationId ?? r.id) === id` 比对,
|
|
134
|
-
* 而新记录的 `id` 是随机 UUID —— 只写 `requestId` 不写 `operationId` 的话,
|
|
135
|
-
* 第一层防重会永远查不到(实测:reserve 一条后 `operationSends` 返回 `[]`),
|
|
136
|
-
* 同一 requestId 可以重复发同一条评论。
|
|
137
|
-
*/
|
|
138
|
-
operationId?: string;
|
|
139
|
-
/** 单平台,但要写:`hasSend()` 早先因为缺这个字段恒返回 false。 */
|
|
140
|
-
platform?: string;
|
|
141
|
-
/** 稳定的防重键。**同一个 requestId 只能有一次发送**。 */
|
|
142
|
-
requestId: string;
|
|
143
|
-
accountId: string;
|
|
144
|
-
/** 回给谁(同一个人每日配额按这个算)。 */
|
|
145
|
-
recipientId?: string;
|
|
146
|
-
target: CommentTarget;
|
|
147
|
-
text: string;
|
|
148
|
-
status: SendStatus;
|
|
149
|
-
createdAt: string;
|
|
150
|
-
receiptId?: string;
|
|
151
|
-
transport?: 'api' | 'browser';
|
|
152
|
-
visibility?: VisibilityReport;
|
|
153
|
-
detail?: string;
|
|
154
|
-
platformState?: number;
|
|
155
|
-
inboxId?: string;
|
|
156
|
-
roamId?: string;
|
|
157
|
-
/** 这条是回复通知 / 主动发言 / 特别关注 / 推荐给主人 —— 四本账靠它分开。 */
|
|
158
|
-
kind: 'reply' | 'proactive' | 'focus' | 'recommend';
|
|
159
|
-
/** 主人评论区自动回应单独计账。 */
|
|
160
|
-
focusOwnerId?: string;
|
|
161
|
-
ownerAutoReply?: boolean;
|
|
162
|
-
/** 这条发言里 @ 了谁(有就说明用掉了 @ 额度)。 */
|
|
163
|
-
mention?: { id: string; name: string };
|
|
164
|
-
/** prepare 留下的凭据摘要(审计用)。 */
|
|
165
|
-
preparation?: PreparationNote;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** B 站错误分类。**分类决定模型下一步做什么**,所以不能糊成一个 Error。 */
|
|
169
|
-
export class BiliError extends Error {
|
|
170
|
-
constructor(
|
|
171
|
-
message: string,
|
|
172
|
-
readonly kind: 'auth' | 'rate' | 'rejected' | 'network' | 'invalid' = 'invalid',
|
|
173
|
-
) {
|
|
174
|
-
super(message);
|
|
175
|
-
this.name = 'BiliError';
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** 通知的一页。`cursor` 为空表示没有下一页。 */
|
|
180
|
-
export interface NotificationPage {
|
|
181
|
-
items: InboxItem[];
|
|
182
|
-
cursor?: { id: string; time: number };
|
|
183
|
-
done: boolean;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/* ------------------------------------------------------------------ 社交侧 */
|
|
187
|
-
/* 下面这几个原本定义在 `core/platform.ts`(多平台版本带过来的)。 */
|
|
188
|
-
/* 现在统一放这里,`platform.ts` 只做 re-export —— 两份同名类型已经 */
|
|
189
|
-
/* 造成过一次真实 bug(`InboxItem.platform` 缺失导致联系人表恒为空)。 */
|
|
190
|
-
|
|
191
|
-
/** 归档过的作品(面板按它显示卡片标题)。 */
|
|
192
|
-
export interface PublicVideo {
|
|
193
|
-
ownerId?: string;
|
|
194
|
-
publishedAt?: number;
|
|
195
|
-
aid: string;
|
|
196
|
-
id: string;
|
|
197
|
-
title: string;
|
|
198
|
-
url: string;
|
|
199
|
-
author?: string;
|
|
200
|
-
description?: string;
|
|
201
|
-
updatedAt: string;
|
|
202
|
-
observation?: string;
|
|
203
|
-
unavailable?: boolean;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** 被 @ 的对象。**必须是核验过的 UID**,不靠文本 @。 */
|
|
207
|
-
export interface FocusMention {
|
|
208
|
-
id: string;
|
|
209
|
-
name: string;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** prepare 产出的凭据摘要。 */
|
|
213
|
-
export interface PreparationNote {
|
|
214
|
-
mention?: FocusMention;
|
|
215
|
-
judgment?: import('../social/judgment.ts').ParticipationJudgment;
|
|
216
|
-
briefId: string;
|
|
217
|
-
purpose: string;
|
|
218
|
-
advice: string[];
|
|
219
|
-
parent?: PublicComment;
|
|
220
|
-
video?: PublicVideo;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** 一份完整的接话凭据(存进 `briefs[]`)。 */
|
|
224
|
-
export interface ConversationBrief {
|
|
225
|
-
id: string;
|
|
226
|
-
platform?: string;
|
|
227
|
-
accountId: string;
|
|
228
|
-
target: CommentTarget;
|
|
229
|
-
createdAt: string;
|
|
230
|
-
purpose: string;
|
|
231
|
-
draft: string;
|
|
232
|
-
/** prepare 时明确要 @ 谁(`mentionFocus`)。publish 只认这一份。 */
|
|
233
|
-
mention?: FocusMention;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
1
|
+
/**
|
|
2
|
+
* core/types.ts — B 站插件里的所有 ID 与目标类型。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么 ID 全是字符串
|
|
5
|
+
*
|
|
6
|
+
* B 站的 `aid` / `cid` / `avid` 真的会超过 JS 的安全整数(2^53)。
|
|
7
|
+
* `JSON.parse` 遇到它们会**静默变成一个看起来正常但已经错的值** —— 而且不报错。
|
|
8
|
+
* 所以:**解析前先把 16 位以上的整数转成字符串**(见 `parsePlatformJson`),
|
|
9
|
+
* 之后全程当字符串走,只在需要参与 API 调用时拼成 URL 参数。
|
|
10
|
+
*
|
|
11
|
+
* 这一条不是洁癖:`cid` 错一位就会取到**另一个视频的流**,而画面看起来完全正常。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** 视频标识:BV 号或 av 号,统一成 `BV…` / `av…` 两种前缀写法。 */
|
|
15
|
+
export type VideoId = string;
|
|
16
|
+
|
|
17
|
+
/** 分P 的 cid(字符串形式的数字)。 */
|
|
18
|
+
export type Cid = string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 评论区目标。
|
|
22
|
+
*
|
|
23
|
+
* - `oid`:视频 aid / 动态 id(**不是** BV 号 —— B 站评论接口只认数字)
|
|
24
|
+
* - `type`:`1`=视频、`11`=动态、`17`=动态评论
|
|
25
|
+
* - `root`:顶层楼层的 rpid;新评论为 `'0'`
|
|
26
|
+
* - `parent`:要回复的那条评论的 rpid;新评论为 `'0'`
|
|
27
|
+
*
|
|
28
|
+
* **`root` 和 `parent` 必须同时为 `'0'` 或同时非 `'0'`** —— 只给一个是错的,
|
|
29
|
+
* B 站会把它当成"回复到某个不存在的楼层"。这个校验放在 `normalizeTarget()` 里。
|
|
30
|
+
*/
|
|
31
|
+
export interface CommentTarget {
|
|
32
|
+
oid: string;
|
|
33
|
+
type: 1 | 11 | 17;
|
|
34
|
+
root: string;
|
|
35
|
+
parent: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface VideoPart {
|
|
39
|
+
cid: Cid;
|
|
40
|
+
page: number;
|
|
41
|
+
title: string;
|
|
42
|
+
durationSec: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Video {
|
|
46
|
+
/** BV 号。 */
|
|
47
|
+
id: VideoId;
|
|
48
|
+
aid: string;
|
|
49
|
+
/** 当前选中分P 的 cid。 */
|
|
50
|
+
cid: Cid;
|
|
51
|
+
title: string;
|
|
52
|
+
description: string;
|
|
53
|
+
author: string;
|
|
54
|
+
ownerId: string;
|
|
55
|
+
durationSec: number;
|
|
56
|
+
cover: string;
|
|
57
|
+
url: string;
|
|
58
|
+
parts: VideoPart[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Account {
|
|
62
|
+
/** DedeUserID */
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface PublicComment {
|
|
68
|
+
id: string;
|
|
69
|
+
authorId: string;
|
|
70
|
+
author: string;
|
|
71
|
+
text: string;
|
|
72
|
+
createdAt?: number;
|
|
73
|
+
target: CommentTarget;
|
|
74
|
+
replies: PublicComment[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 一次通知(别人回复我 / @ 我 / 主人评论区)。 */
|
|
78
|
+
export interface InboxItem {
|
|
79
|
+
/** `bilibili:<accountId>:<parent>` —— 用它去重,同一楼重复通知只留一条。 */
|
|
80
|
+
id: string;
|
|
81
|
+
/**
|
|
82
|
+
* 单平台,但**必须写**。
|
|
83
|
+
*
|
|
84
|
+
* `store.rememberContact()` 曾经因为没有这个字段,`item.platform !== 'bilibili'`
|
|
85
|
+
* 恒真、联系人表永远是空的 —— 真机验证「迁移后 contacts 为 0」才发现。
|
|
86
|
+
* 现在统一由 service 填 `'bilibili'`,别再靠 `?? 'bilibili'` 兜底。
|
|
87
|
+
*/
|
|
88
|
+
platform?: string;
|
|
89
|
+
accountId: string;
|
|
90
|
+
authorId: string;
|
|
91
|
+
author: string;
|
|
92
|
+
text: string;
|
|
93
|
+
target: CommentTarget;
|
|
94
|
+
occurredAt: number;
|
|
95
|
+
status: 'pending' | 'handled';
|
|
96
|
+
notificationType: 'reply' | 'mention' | 'focus-video' | 'focus-comment';
|
|
97
|
+
url?: string;
|
|
98
|
+
/** 什么时候该再看(`defer` 用)。 */
|
|
99
|
+
retryAt?: string;
|
|
100
|
+
/** 已经投给模型了没有。**没有它就会每轮重投同一条待办**。 */
|
|
101
|
+
delivered?: boolean;
|
|
102
|
+
deliveredAt?: string;
|
|
103
|
+
/** 这条来自特别关注(主人评论区),有值就走 `focus` 那本账。 */
|
|
104
|
+
focusOwnerId?: string;
|
|
105
|
+
/** 主人评论区自动回应:单独计账,不占普通额度。 */
|
|
106
|
+
ownerAutoReply?: boolean;
|
|
107
|
+
/** 被本机规则直接收尾时的原因(`skip` / `limit` 等),面板会显示。 */
|
|
108
|
+
handling?: { kind: 'unsafe' | 'resource' | 'limit' | 'skip'; reason: string };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 一次发送的结局。**这五个状态不能混** —— 弄混就是重发或漏发。 */
|
|
112
|
+
export type SendStatus = 'sending' | 'sent' | 'unknown' | 'rejected';
|
|
113
|
+
|
|
114
|
+
export interface VisibilityReport {
|
|
115
|
+
/** `public` = 访客看得到;`self-only` = 平台判定仅自己可见;`unconfirmed` = 核不了。 */
|
|
116
|
+
status: 'public' | 'self-only' | 'unconfirmed';
|
|
117
|
+
detail: string;
|
|
118
|
+
checkedAt: string;
|
|
119
|
+
platformState?: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface SendReceipt {
|
|
123
|
+
receiptId: string;
|
|
124
|
+
transport: 'api' | 'browser';
|
|
125
|
+
platformState?: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface SendRecord {
|
|
129
|
+
id: string;
|
|
130
|
+
/**
|
|
131
|
+
* 防重主键:`bilibili:<accountId>:<requestId>`。
|
|
132
|
+
*
|
|
133
|
+
* **必须落盘**。`store.operationSends()` 用 `(r.operationId ?? r.id) === id` 比对,
|
|
134
|
+
* 而新记录的 `id` 是随机 UUID —— 只写 `requestId` 不写 `operationId` 的话,
|
|
135
|
+
* 第一层防重会永远查不到(实测:reserve 一条后 `operationSends` 返回 `[]`),
|
|
136
|
+
* 同一 requestId 可以重复发同一条评论。
|
|
137
|
+
*/
|
|
138
|
+
operationId?: string;
|
|
139
|
+
/** 单平台,但要写:`hasSend()` 早先因为缺这个字段恒返回 false。 */
|
|
140
|
+
platform?: string;
|
|
141
|
+
/** 稳定的防重键。**同一个 requestId 只能有一次发送**。 */
|
|
142
|
+
requestId: string;
|
|
143
|
+
accountId: string;
|
|
144
|
+
/** 回给谁(同一个人每日配额按这个算)。 */
|
|
145
|
+
recipientId?: string;
|
|
146
|
+
target: CommentTarget;
|
|
147
|
+
text: string;
|
|
148
|
+
status: SendStatus;
|
|
149
|
+
createdAt: string;
|
|
150
|
+
receiptId?: string;
|
|
151
|
+
transport?: 'api' | 'browser';
|
|
152
|
+
visibility?: VisibilityReport;
|
|
153
|
+
detail?: string;
|
|
154
|
+
platformState?: number;
|
|
155
|
+
inboxId?: string;
|
|
156
|
+
roamId?: string;
|
|
157
|
+
/** 这条是回复通知 / 主动发言 / 特别关注 / 推荐给主人 —— 四本账靠它分开。 */
|
|
158
|
+
kind: 'reply' | 'proactive' | 'focus' | 'recommend';
|
|
159
|
+
/** 主人评论区自动回应单独计账。 */
|
|
160
|
+
focusOwnerId?: string;
|
|
161
|
+
ownerAutoReply?: boolean;
|
|
162
|
+
/** 这条发言里 @ 了谁(有就说明用掉了 @ 额度)。 */
|
|
163
|
+
mention?: { id: string; name: string };
|
|
164
|
+
/** prepare 留下的凭据摘要(审计用)。 */
|
|
165
|
+
preparation?: PreparationNote;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** B 站错误分类。**分类决定模型下一步做什么**,所以不能糊成一个 Error。 */
|
|
169
|
+
export class BiliError extends Error {
|
|
170
|
+
constructor(
|
|
171
|
+
message: string,
|
|
172
|
+
readonly kind: 'auth' | 'rate' | 'rejected' | 'network' | 'invalid' = 'invalid',
|
|
173
|
+
) {
|
|
174
|
+
super(message);
|
|
175
|
+
this.name = 'BiliError';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 通知的一页。`cursor` 为空表示没有下一页。 */
|
|
180
|
+
export interface NotificationPage {
|
|
181
|
+
items: InboxItem[];
|
|
182
|
+
cursor?: { id: string; time: number };
|
|
183
|
+
done: boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* ------------------------------------------------------------------ 社交侧 */
|
|
187
|
+
/* 下面这几个原本定义在 `core/platform.ts`(多平台版本带过来的)。 */
|
|
188
|
+
/* 现在统一放这里,`platform.ts` 只做 re-export —— 两份同名类型已经 */
|
|
189
|
+
/* 造成过一次真实 bug(`InboxItem.platform` 缺失导致联系人表恒为空)。 */
|
|
190
|
+
|
|
191
|
+
/** 归档过的作品(面板按它显示卡片标题)。 */
|
|
192
|
+
export interface PublicVideo {
|
|
193
|
+
ownerId?: string;
|
|
194
|
+
publishedAt?: number;
|
|
195
|
+
aid: string;
|
|
196
|
+
id: string;
|
|
197
|
+
title: string;
|
|
198
|
+
url: string;
|
|
199
|
+
author?: string;
|
|
200
|
+
description?: string;
|
|
201
|
+
updatedAt: string;
|
|
202
|
+
observation?: string;
|
|
203
|
+
unavailable?: boolean;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** 被 @ 的对象。**必须是核验过的 UID**,不靠文本 @。 */
|
|
207
|
+
export interface FocusMention {
|
|
208
|
+
id: string;
|
|
209
|
+
name: string;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** prepare 产出的凭据摘要。 */
|
|
213
|
+
export interface PreparationNote {
|
|
214
|
+
mention?: FocusMention;
|
|
215
|
+
judgment?: import('../social/judgment.ts').ParticipationJudgment;
|
|
216
|
+
briefId: string;
|
|
217
|
+
purpose: string;
|
|
218
|
+
advice: string[];
|
|
219
|
+
parent?: PublicComment;
|
|
220
|
+
video?: PublicVideo;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** 一份完整的接话凭据(存进 `briefs[]`)。 */
|
|
224
|
+
export interface ConversationBrief {
|
|
225
|
+
id: string;
|
|
226
|
+
platform?: string;
|
|
227
|
+
accountId: string;
|
|
228
|
+
target: CommentTarget;
|
|
229
|
+
createdAt: string;
|
|
230
|
+
purpose: string;
|
|
231
|
+
draft: string;
|
|
232
|
+
/** prepare 时明确要 @ 谁(`mentionFocus`)。publish 只认这一份。 */
|
|
233
|
+
mention?: FocusMention;
|
|
234
|
+
/**
|
|
235
|
+
* 该回给谁(平台账号 id)。来自收件箱的 authorId —— 收到通知那一刻就确定了。
|
|
236
|
+
* 存进凭据是因为 publish 常常只带 briefId:那时回头读楼中楼找父评论作者
|
|
237
|
+
* 经常找不到(父评论排在最后一页),会把能回的楼卡成「暂未取得身份」。
|
|
238
|
+
*/
|
|
239
|
+
recipientId?: string;
|
|
240
|
+
video?: PublicVideo;
|
|
241
|
+
videoTitle?: string;
|
|
242
|
+
parent?: PublicComment;
|
|
243
|
+
nearby: Array<Pick<PublicComment, 'author' | 'text'>>;
|
|
244
|
+
recentOwn: string[];
|
|
245
|
+
advice: string[];
|
|
246
|
+
guidance: string[];
|
|
247
|
+
judgment?: import('../social/judgment.ts').ParticipationJudgment;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export const isHttpUrl = (v: string): boolean => /^https?:\/\//i.test(String(v ?? '').trim());
|
|
251
|
+
|
|
252
|
+
/** 像不像一个 B 站视频标识(BV 号 / av 号 / 站内链接)。 */
|
|
253
|
+
export const looksLikeBiliVideo = (v: string): boolean => {
|
|
254
|
+
const s = String(v ?? '').trim();
|
|
255
|
+
return /bilibili\.com/i.test(s) || /^(BV[0-9A-Za-z]{10}|av\d{1,20})$/i.test(s);
|
|
256
|
+
};
|
package/src/social/service.ts
CHANGED
|
@@ -199,6 +199,26 @@ export class BiliService {
|
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* 这条视频是否已经推荐给主人(只算成功发出的)。
|
|
204
|
+
*
|
|
205
|
+
* 为什么要单独查:推荐的 requestId 从 briefId 派生,每次 prepare 都是新键 ——
|
|
206
|
+
* 四层防重一层都命中不了。实测 11-06 06:35 和 11-08 00:23 把同一条
|
|
207
|
+
* 《免费live2D模型》推了两次,主人连收两条 @。
|
|
208
|
+
*/
|
|
209
|
+
recommendAlreadySent(accountId: string, oid: string) {
|
|
210
|
+
return this.d.store
|
|
211
|
+
.outbox()
|
|
212
|
+
.filter(
|
|
213
|
+
(r) =>
|
|
214
|
+
r.accountId === accountId &&
|
|
215
|
+
r.kind === 'recommend' &&
|
|
216
|
+
r.target.oid === oid &&
|
|
217
|
+
r.status !== 'rejected',
|
|
218
|
+
)
|
|
219
|
+
.at(-1);
|
|
220
|
+
}
|
|
221
|
+
|
|
202
222
|
/* ---------------------------------------------------------------- 连接 */
|
|
203
223
|
|
|
204
224
|
/** 连上并核对账号。 */
|
|
@@ -556,19 +576,21 @@ export class BiliService {
|
|
|
556
576
|
const cached = this.d.store.comment(target)?.authorId;
|
|
557
577
|
if (cached) return cached;
|
|
558
578
|
if (target.parent === '0') return undefined;
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
579
|
+
// 楼中楼按时间正序分页 —— 刚回复的那条(也就是我们要找的 parent)
|
|
580
|
+
// **永远在最后一页**。只读第 1 页等于永远找不到,所以往下翻几页。
|
|
581
|
+
for (let page = 1; page <= 3; page++) {
|
|
582
|
+
try {
|
|
583
|
+
const r = await readComments(this.d.client(), { ...target, parent: '0' }, page, signal);
|
|
584
|
+
this.d.store.rememberComments(r);
|
|
585
|
+
const hit = this.d.store.comment(target)?.authorId;
|
|
586
|
+
if (hit) return hit;
|
|
587
|
+
if (!r.items?.length) break;
|
|
588
|
+
} catch {
|
|
589
|
+
// 读不到父楼不是"不能发"的理由,调用方会用 recipientId 兜底或明确拒绝
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
571
592
|
}
|
|
593
|
+
return this.d.store.comment(target)?.authorId;
|
|
572
594
|
}
|
|
573
595
|
|
|
574
596
|
private assertQuota(
|
|
@@ -700,7 +722,11 @@ export class BiliService {
|
|
|
700
722
|
|
|
701
723
|
// 接楼必须有 recipientId:拿不到就不发,绝不绕过单人上限
|
|
702
724
|
if (!input.inboxId && target.parent !== '0') {
|
|
703
|
-
|
|
725
|
+
// 凭据里记着"回给谁"就先信它(来自收件箱的 authorId,收到通知那刻就确定了)。
|
|
726
|
+
// 只拿 briefId 来发时,这里会回头读楼中楼找父评论作者 —— 而父评论通常是
|
|
727
|
+
// **最新的那条,排在最后一页**,第一页永远读不到,于是明明能回的楼被卡成
|
|
728
|
+
// 「暂未取得对方平台账号身份」(实测:2026-11-08 01:2x 缘梦幻境那条)。
|
|
729
|
+
recipientId = brief?.recipientId ?? (await this.parentAuthor(target, signal));
|
|
704
730
|
if (!recipientId || !/^[1-9]\d*$/.test(recipientId)) {
|
|
705
731
|
throw new PublicReplySkipped(
|
|
706
732
|
'暂未取得对方平台账号身份,本次不发;先读清原楼层(bili_comments)再来,不换目标绕过每人上限。',
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 这里把同一份 state 反过来索引:**一条视频一行** ——
|
|
8
8
|
* 看过没、什么时候、哪一轮、发过哪几条什么状态、写过没有。
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* 三条来自她的实测反馈(2026-11-07):
|
|
11
11
|
* 1. **评论不要截断**:她发的都短,截了就认不出是自己哪句。
|
|
12
12
|
* 2. **草稿不是"说过的话"**:全塞进「写过」会显得她话多 —— 所以心得和草稿
|
|
13
13
|
* 分成 `notes` / `drafts` 两类,草稿明确标发没发出去。
|
|
@@ -73,7 +73,7 @@ function breakBefore(s: string, from: number, back: number): number {
|
|
|
73
73
|
/**
|
|
74
74
|
* 长文本折叠:**头留七成、尾留三成**,中间标明省略了多少字。
|
|
75
75
|
*
|
|
76
|
-
*
|
|
76
|
+
* 比硬夹断好的地方(她 2026-11-07 定的规矩):
|
|
77
77
|
* - 认出是哪句靠**开头**,所以头占大头;
|
|
78
78
|
* - 结尾常是梗/态度,尾那三成不能砍没;
|
|
79
79
|
* - **宁可少截**:长度没超阈值就原样返回,大多数评论根本不该被碰;
|
|
@@ -124,7 +124,7 @@ export function foldText(
|
|
|
124
124
|
/**
|
|
125
125
|
* 把一个视频标识拆成 `{ bvid }` 或 `{ aid }`。
|
|
126
126
|
*
|
|
127
|
-
*
|
|
127
|
+
* 她习惯直接给 BV 号,但链接、av 号、裸 aid 也都该认 ——
|
|
128
128
|
* 认不出来就返回 null,由调用方按"原样字符串"再比对一次。
|
|
129
129
|
*/
|
|
130
130
|
export function parseVideoRef(input: string): { bvid?: string; aid?: string } | null {
|
package/src/world.ts
CHANGED
|
@@ -1825,6 +1825,11 @@ export class BiliWatchWorld implements World {
|
|
|
1825
1825
|
let parentText = '';
|
|
1826
1826
|
let parentWriter = '';
|
|
1827
1827
|
let focusOwnerId: string | undefined;
|
|
1828
|
+
// 通知回复的"回给谁"在收到通知那一刻就是确定的(item.authorId)。
|
|
1829
|
+
// 必须存进凭据:publish 只拿 briefId 时已经没有 inbox 了,以前只能
|
|
1830
|
+
// 回头去读楼中楼找父评论作者 —— 而父评论经常排在最后一页,第一页读不到,
|
|
1831
|
+
// 于是发不出去(实测:缘梦幻境那条报「暂未取得对方平台账号身份」)。
|
|
1832
|
+
let recipientId: string | undefined;
|
|
1828
1833
|
if (args.inboxId) {
|
|
1829
1834
|
const item = this.store.getInbox(String(args.inboxId));
|
|
1830
1835
|
if (!item) throw new Error('收件箱消息不存在');
|
|
@@ -1832,6 +1837,7 @@ export class BiliWatchWorld implements World {
|
|
|
1832
1837
|
parentText = item.text;
|
|
1833
1838
|
parentWriter = item.author;
|
|
1834
1839
|
focusOwnerId = item.focusOwnerId;
|
|
1840
|
+
recipientId = item.authorId || undefined;
|
|
1835
1841
|
} else {
|
|
1836
1842
|
target = normalizeTargetArg(args.target);
|
|
1837
1843
|
const cached = this.store.comment(target);
|
|
@@ -1905,6 +1911,7 @@ export class BiliWatchWorld implements World {
|
|
|
1905
1911
|
? { parent: { id: target.parent, authorId: '', author: parentWriter, text: parentText, target, replies: [] } }
|
|
1906
1912
|
: {}),
|
|
1907
1913
|
...(focusOwnerId ? { focusOwnerId } : {}),
|
|
1914
|
+
...(recipientId ? { recipientId } : {}),
|
|
1908
1915
|
};
|
|
1909
1916
|
this.store.saveBrief(brief as any);
|
|
1910
1917
|
|
|
@@ -2023,6 +2030,23 @@ export class BiliWatchWorld implements World {
|
|
|
2023
2030
|
|
|
2024
2031
|
const target = normalizeTargetArg(args.target);
|
|
2025
2032
|
if (target.parent !== '0') throw new Error('推荐只能在视频下新发一条评论,不能接楼。');
|
|
2033
|
+
|
|
2034
|
+
// 同一条视频只推一次。四层防重拦不住这个:requestId 从 briefId 派生,
|
|
2035
|
+
// 每次 prepare 都是新的,等于每次都算"新操作"。实测 11-06 06:35 和
|
|
2036
|
+
// 11-08 00:23 把《免费live2D模型》推了两次,主人连着收了两条 @。
|
|
2037
|
+
const prior = this.service.recommendAlreadySent(acc.id, target.oid);
|
|
2038
|
+
if (prior) {
|
|
2039
|
+
const at = new Date(prior.createdAt).toLocaleString('zh-CN', {
|
|
2040
|
+
timeZone: this.ctx.timezone,
|
|
2041
|
+
month: '2-digit',
|
|
2042
|
+
day: '2-digit',
|
|
2043
|
+
hour: '2-digit',
|
|
2044
|
+
minute: '2-digit',
|
|
2045
|
+
});
|
|
2046
|
+
throw new Error(
|
|
2047
|
+
`这条视频 ${at} 已经推荐给主人了,不重复推。换一条,或者干脆不推。`,
|
|
2048
|
+
);
|
|
2049
|
+
}
|
|
2026
2050
|
const draft = String(args.draft ?? '').trim().slice(0, 1000);
|
|
2027
2051
|
if (!draft) throw new Error('action=prepare 需要 draft(打算说什么)。');
|
|
2028
2052
|
// @ 由配置自动加,正文里不该自己写一遍 —— 免得像上轮那样 prepare 两次
|
|
@@ -3009,12 +3033,6 @@ function clean(v: unknown, max = 8000): string {
|
|
|
3009
3033
|
const isBili = (v: string): boolean =>
|
|
3010
3034
|
/bilibili\.com/i.test(v) || /^(BV[0-9A-Za-z]{10}|av\d{1,20})$/i.test(v.trim());
|
|
3011
3035
|
|
|
3012
|
-
/**
|
|
3013
|
-
* 把一个视频标识拆成 { bvid } 或 { aid }。
|
|
3014
|
-
*
|
|
3015
|
-
* 雅汐习惯直接给 BV 号,但链接、av 号、裸 aid 也都该认 —— 认不出来就返回 null,
|
|
3016
|
-
* 由调用方按"原样字符串"再比对一次。
|
|
3017
|
-
*/
|
|
3018
3036
|
function normalizeTargetArg(value: unknown): CommentTarget {
|
|
3019
3037
|
// 复用 core 的校验(root/parent 必须同时为 0 或同时非 0)
|
|
3020
3038
|
return require0(value);
|