@cmach_socket/opencode-qq-bot 0.9.0 → 0.9.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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "napcat": {
3
+ "url": "ws://127.0.0.1:3001"
4
+ },
5
+ "ownerQQ": 123456789,
6
+ "access": {
7
+ "allow": {
8
+ "groups": [123456789],
9
+ "users": [987654321]
10
+ }
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmach_socket/opencode-qq-bot",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "OpenCode V2 plugin bridging a QQ group chat (NapCat via NapLink) to an OpenCode session.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,6 +23,7 @@
23
23
  "src",
24
24
  "souls",
25
25
  "web/dist",
26
+ "config.example.json",
26
27
  "tool-profiles.example.json",
27
28
  "chat-overrides.example.json",
28
29
  "NOTICE",
@@ -292,7 +292,7 @@ export const CONFIG_FIELDS: readonly ConfigField[] = [
292
292
  group: "proactive",
293
293
  type: "numberList",
294
294
  label: "主动说话的群号",
295
- description: "留空表示不限制",
295
+ description: "留空表示一个都不主动说话",
296
296
  default: [],
297
297
  },
298
298
  {
@@ -300,7 +300,7 @@ export const CONFIG_FIELDS: readonly ConfigField[] = [
300
300
  group: "proactive",
301
301
  type: "numberList",
302
302
  label: "主动说话的私聊 QQ 号",
303
- description: "留空表示不限制",
303
+ description: "留空表示一个都不主动说话",
304
304
  default: [],
305
305
  },
306
306
 
@@ -742,8 +742,8 @@ export const CONFIG_FIELDS: readonly ConfigField[] = [
742
742
  group: "panel",
743
743
  type: "boolean",
744
744
  label: "启用状态面板",
745
- description: "面板自带 HTTP 服务,默认关闭",
746
- default: false,
745
+ description: "面板自带 HTTP 服务,默认开启",
746
+ default: true,
747
747
  hot: true,
748
748
  },
749
749
  {
@@ -1,3 +1,4 @@
1
+ import { randomBytes } from "node:crypto"
1
2
  import { applyHotFields, resolveConfig, type ConfigWarning, type QQBotConfig } from "../config"
2
3
  import { CONFIG_FIELDS } from "../config/fields"
3
4
  import { requiredFieldProblem } from "../config/registry"
@@ -71,9 +72,32 @@ export class ConfigController {
71
72
  async load(): Promise<QQBotConfig> {
72
73
  this.raw = await this.options.store.read()
73
74
  this.config = this.resolve(this.raw)
75
+ await this.ensureSecrets()
74
76
  return this.config
75
77
  }
76
78
 
79
+ /**
80
+ * 补齐缺失的随机凭据。
81
+ *
82
+ * 面板开着却没有令牌时生成一个并写回配置文件:令牌要留在文件里,
83
+ * 重启后不变,面板也才有得登录。写不进去只告警,不影响机器人本身。
84
+ */
85
+ private async ensureSecrets(): Promise<void> {
86
+ const live = this.config
87
+ if (!live?.panel.enabled) return
88
+ if (live.panel.token) {
89
+ if (live.panel.token.length < 16) this.warn("面板访问令牌太短,建议至少 16 个字符")
90
+ return
91
+ }
92
+ const token = randomBytes(32).toString("hex")
93
+ try {
94
+ await this.applyPatch({ "panel.token": token })
95
+ this.warn("面板访问令牌已生成,请查看 config.json 里的 panel.token")
96
+ } catch (error) {
97
+ this.warn(`面板访问令牌生成失败:${error instanceof Error ? error.message : String(error)}`)
98
+ }
99
+ }
100
+
77
101
  /** 解析文件内容;非法值告警并回退默认值。 */
78
102
  private resolve(raw: Record<string, unknown>): QQBotConfig {
79
103
  return resolveConfig(raw, this.options.agent, (message) => this.warn(message))
@@ -102,6 +126,8 @@ export class ConfigController {
102
126
  applyHotFields(live, next)
103
127
  this.config = live
104
128
  this.notify()
129
+ // 面板刚被打开时补一个令牌:补完会再通知一次,订阅者这时看到的配置是完整的。
130
+ await this.ensureSecrets()
105
131
  return {
106
132
  config: live,
107
133
  restartRequired: Object.keys(patch).filter((path) => !isHotField(path)),
@@ -132,6 +158,8 @@ export class ConfigController {
132
158
  applyHotFields(live, next)
133
159
  this.config = live
134
160
  this.notify()
161
+ // 面板刚被打开时补一个令牌:补完会再通知一次,订阅者这时看到的配置是完整的。
162
+ void this.ensureSecrets()
135
163
  })
136
164
  }
137
165
 
@@ -0,0 +1,289 @@
1
+ import { createHash } from "node:crypto"
2
+ import { chmod, copyFile, mkdir, open, readFile, unlink } from "node:fs/promises"
3
+ import { extname, join } from "node:path"
4
+ import { fileURLToPath } from "node:url"
5
+ import type { Plugin } from "@opencode/plugin"
6
+ import { Mutex } from "async-mutex"
7
+ import { type ChatTarget, targetKey } from "../chat"
8
+ import type { Logger } from "../logger"
9
+ import type { PromptFile } from "../naplink/media"
10
+
11
+ /** 收藏描述最长字数。 */
12
+ export const MAX_DESCRIPTION_LENGTH = 12
13
+
14
+ /** 收藏描述的规则说明;描述不合规时原样回给模型。 */
15
+ export const DESCRIPTION_RULES = `描述要是一个中文名字,最多 ${MAX_DESCRIPTION_LENGTH} 个字,只能用文字和数字,不要标点、空格、引号、解释。`
16
+
17
+ /** 描述校验结果。 */
18
+ export type DescriptionCheck = { ok: true; value: string } | { ok: false; reason: string }
19
+
20
+ /**
21
+ * 校验收藏描述。
22
+ *
23
+ * 描述会写进收藏列表,模型必须一次给出合规的名字:
24
+ * 只有文字和数字、不带空格标点、不超过 12 个字。
25
+ */
26
+ export function checkDescription(raw: unknown): DescriptionCheck {
27
+ if (typeof raw !== "string") return { ok: false, reason: "缺少 description(收藏描述)" }
28
+ const value = raw.trim()
29
+ if (!value) return { ok: false, reason: "缺少 description(收藏描述)" }
30
+ if (/\s/u.test(value)) return { ok: false, reason: "描述里不能有空格" }
31
+ const chars = Array.from(value)
32
+ if (chars.some((char) => !/[\p{L}\p{N}]/u.test(char))) {
33
+ return { ok: false, reason: "描述里只能有文字和数字" }
34
+ }
35
+ if (chars.length > MAX_DESCRIPTION_LENGTH) {
36
+ return { ok: false, reason: `描述最多 ${MAX_DESCRIPTION_LENGTH} 个字` }
37
+ }
38
+ return { ok: true, value }
39
+ }
40
+
41
+ /** 插件存储里收藏清单的键。 */
42
+ export const COLLECTION_KEY = "emoji-collection"
43
+ /** 收藏文件在媒体目录下的子目录名。 */
44
+ export const COLLECTION_DIR = "favorites"
45
+ /** 本机收藏的表情数量上限,超出后丢掉最早收藏的。 */
46
+ export const MAX_COLLECTED_STICKERS = 200
47
+
48
+ /** 本机收集的表情。 */
49
+ export type CollectedSticker = {
50
+ /** 图片 md5,作为身份键。 */
51
+ md5: string
52
+ /** 收藏描述。 */
53
+ description: string
54
+ /** 本地文件绝对路径。 */
55
+ file: string
56
+ /** 收藏时间(毫秒)。 */
57
+ createdAt: number
58
+ }
59
+
60
+ /** 收藏存储用到的插件存储接口。 */
61
+ export type CollectionStorage = Pick<Plugin.Context["storage"], "get" | "set">
62
+
63
+ /**
64
+ * 本机收集的表情清单。
65
+ *
66
+ * QQ 客户端的收藏表情只有 NapCat 能写,插件收集的动图只能自己存:
67
+ * 图片复制到媒体目录下的收藏子目录,元数据写在插件存储里。
68
+ */
69
+ export class CollectionStore {
70
+ private readonly mutex = new Mutex()
71
+ private items: CollectedSticker[] = []
72
+ private loaded = false
73
+ private loading: Promise<void> | undefined
74
+
75
+ constructor(
76
+ private readonly storage: CollectionStorage,
77
+ /** 媒体目录:收藏文件放在它的收藏子目录里。 */
78
+ private readonly root: string,
79
+ private readonly logger: Logger,
80
+ ) {}
81
+
82
+ /** 收藏清单,按收藏先后返回。 */
83
+ async list(): Promise<CollectedSticker[]> {
84
+ await this.ensureLoaded()
85
+ return [...this.items]
86
+ }
87
+
88
+ /**
89
+ * 收藏一张图片。
90
+ *
91
+ * 图片复制到收藏目录,元数据写进插件存储;
92
+ * 同一张图重复收藏只更新描述,文件不重复存。
93
+ */
94
+ async add(source: string, description: string): Promise<CollectedSticker> {
95
+ return this.mutex.runExclusive(async () => {
96
+ await this.ensureLoaded()
97
+ const bytes = await readFile(source)
98
+ const md5 = createHash("md5").update(bytes).digest("hex")
99
+ const ext = extname(source).replace(/^\./, "").toLowerCase() || "bin"
100
+ const dir = join(this.root, COLLECTION_DIR)
101
+ await mkdir(dir, { recursive: true, mode: 0o700 })
102
+ const file = join(dir, `${md5}.${ext}`)
103
+ await copyFile(source, file)
104
+ await chmod(file, 0o600)
105
+ const existing = this.items.find((item) => item.md5 === md5)
106
+ const sticker: CollectedSticker = {
107
+ md5,
108
+ description,
109
+ file,
110
+ createdAt: existing?.createdAt ?? Date.now(),
111
+ }
112
+ this.items = existing
113
+ ? this.items.map((item) => (item.md5 === md5 ? sticker : item))
114
+ : [...this.items, sticker]
115
+ await this.enforceLimit()
116
+ await this.persist()
117
+ return sticker
118
+ })
119
+ }
120
+
121
+ /** 超过上限时丢掉最早收藏的,连同它的文件一起删掉。 */
122
+ private async enforceLimit(): Promise<void> {
123
+ while (this.items.length > MAX_COLLECTED_STICKERS) {
124
+ const oldest = this.items.shift()
125
+ if (!oldest) break
126
+ try {
127
+ await unlink(oldest.file)
128
+ } catch {
129
+ // 文件可能已经被删掉,不影响清单。
130
+ }
131
+ }
132
+ }
133
+
134
+ /** 从插件存储恢复清单;读取失败下次重试。 */
135
+ private ensureLoaded(): Promise<void> {
136
+ if (this.loaded) return Promise.resolve()
137
+ this.loading ??= this.read()
138
+ .then(() => {
139
+ this.loaded = true
140
+ })
141
+ .catch((error: unknown) => {
142
+ this.logger.warn("读取收藏清单失败", error)
143
+ this.loading = undefined
144
+ })
145
+ return this.loading
146
+ }
147
+
148
+ private async read(): Promise<void> {
149
+ const stored = await this.storage.get(COLLECTION_KEY)
150
+ const raw = (stored as { items?: unknown } | undefined)?.items
151
+ if (!Array.isArray(raw)) return
152
+ const items: CollectedSticker[] = []
153
+ for (const entry of raw) {
154
+ if (!entry || typeof entry !== "object") continue
155
+ const { md5, description, file, createdAt } = entry as Record<string, unknown>
156
+ if (typeof md5 !== "string" || md5.length === 0) continue
157
+ if (typeof description !== "string" || description.length === 0) continue
158
+ if (typeof file !== "string" || file.length === 0) continue
159
+ items.push({
160
+ md5,
161
+ description,
162
+ file,
163
+ createdAt: typeof createdAt === "number" && Number.isFinite(createdAt) ? createdAt : 0,
164
+ })
165
+ }
166
+ this.items = items
167
+ }
168
+
169
+ /** 写回清单;失败只记日志。 */
170
+ private async persist(): Promise<void> {
171
+ try {
172
+ await this.storage.set(COLLECTION_KEY, { version: 1, items: this.items })
173
+ } catch (error) {
174
+ this.logger.error("保存收藏清单失败", error)
175
+ }
176
+ }
177
+ }
178
+
179
+ /** 最近收到的图片在内存里保留的时间。 */
180
+ export const RECENT_IMAGE_TTL_MS = 30 * 60 * 1000
181
+ /** 每个聊天最多保留多少张最近收到的图片。 */
182
+ export const MAX_RECENT_IMAGES = 12
183
+
184
+ /** 收到的一张图片。 */
185
+ export interface ReceivedImage {
186
+ /** 本地文件绝对路径。 */
187
+ file: string
188
+ /** 扩展名,不含点。 */
189
+ ext: string
190
+ /** 是否动图。 */
191
+ animated: boolean
192
+ /** 收到时间(毫秒)。 */
193
+ at: number
194
+ /** 来源消息 ID。 */
195
+ messageId?: string
196
+ }
197
+
198
+ /** 把附件引用还原成本地路径;不是本地文件时返回 undefined。 */
199
+ function localPath(uri: string): string | undefined {
200
+ if (uri.startsWith("file:")) {
201
+ try {
202
+ return fileURLToPath(uri)
203
+ } catch {
204
+ return undefined
205
+ }
206
+ }
207
+ return uri.startsWith("/") ? uri : undefined
208
+ }
209
+
210
+ /**
211
+ * 判断图片是不是动图。
212
+ *
213
+ * GIF 一律当动图;WebP 要看有没有 `ANIM` 块。
214
+ */
215
+ async function isAnimatedImage(file: string, ext: string): Promise<boolean> {
216
+ if (ext === "gif") return true
217
+ if (ext !== "webp") return false
218
+ try {
219
+ const handle = await open(file, "r")
220
+ try {
221
+ const buffer = Buffer.alloc(256)
222
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0)
223
+ return buffer.subarray(0, bytesRead).includes("ANIM")
224
+ } finally {
225
+ await handle.close()
226
+ }
227
+ } catch {
228
+ return false
229
+ }
230
+ }
231
+
232
+ /**
233
+ * 各聊天最近收到的图片。
234
+ *
235
+ * 收藏表情要有个来源:这个表记住每个聊天刚收到过哪些图片,
236
+ * 收藏时从中挑最近收到的那张动图。
237
+ */
238
+ export class RecentImages {
239
+ private readonly chats = new Map<string, ReceivedImage[]>()
240
+
241
+ constructor(private readonly ttlMs = RECENT_IMAGE_TTL_MS) {}
242
+
243
+ /** 记下一条消息里的图片。 */
244
+ async record(
245
+ target: ChatTarget,
246
+ files: readonly PromptFile[],
247
+ messageId?: string,
248
+ ): Promise<void> {
249
+ const images: ReceivedImage[] = []
250
+ for (const file of files) {
251
+ const path = localPath(file.uri)
252
+ if (!path) continue
253
+ const ext = extname(path).replace(/^\./, "").toLowerCase()
254
+ if (!ext) continue
255
+ images.push({
256
+ file: path,
257
+ ext,
258
+ animated: await isAnimatedImage(path, ext),
259
+ at: Date.now(),
260
+ ...(messageId ? { messageId } : {}),
261
+ })
262
+ }
263
+ if (images.length === 0) return
264
+ const key = targetKey(target)
265
+ const items = [...(this.chats.get(key) ?? []), ...images]
266
+ while (items.length > MAX_RECENT_IMAGES) items.shift()
267
+ this.chats.set(key, items)
268
+ }
269
+
270
+ /** 这个聊天最近收到的图片,只返回还在保留期内的。 */
271
+ list(target: ChatTarget): ReceivedImage[] {
272
+ const key = targetKey(target)
273
+ const now = Date.now()
274
+ const items = (this.chats.get(key) ?? []).filter((item) => now - item.at < this.ttlMs)
275
+ if (items.length > 0) this.chats.set(key, items)
276
+ return [...items]
277
+ }
278
+
279
+ /**
280
+ * 最近收到的一张图片。
281
+ *
282
+ * 要求动图时只在动图里找最新的那张。
283
+ */
284
+ latest(target: ChatTarget, options: { animated?: boolean } = {}): ReceivedImage | undefined {
285
+ const items = this.list(target)
286
+ const candidates = options.animated ? items.filter((item) => item.animated) : items
287
+ return candidates[candidates.length - 1]
288
+ }
289
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Plugin } from "@opencode/plugin"
2
2
  import { Mutex } from "async-mutex"
3
3
  import type { Logger } from "../logger"
4
+ import type { CollectedSticker } from "./collection"
4
5
  import { type CustomFace, faceTag, type FavoriteRow } from "./favorites"
5
6
 
6
7
  /** 插件存储里收藏表情编号索引的键。 */
@@ -31,6 +32,15 @@ interface StoredEntry {
31
32
  id: number
32
33
  }
33
34
 
35
+ /**
36
+ * 本机收集的表情的身份键。
37
+ *
38
+ * 和收藏表情一样以图片 md5 为准:同一张图只占一个编号。
39
+ */
40
+ export function collectedKey(sticker: CollectedSticker): string {
41
+ return `md5:${sticker.md5.trim().toLowerCase()}`
42
+ }
43
+
34
44
  /** 从插件存储里读回编号记录,格式不对就当没有。 */
35
45
  function parseEntries(stored: unknown): StoredEntry[] {
36
46
  if (!stored || typeof stored !== "object" || Array.isArray(stored)) return []
@@ -70,8 +80,12 @@ export class FavoriteIndex {
70
80
  * 读取收藏表情列表并给每个表情配上编号。
71
81
  *
72
82
  * 返回的顺序按编号从小到大;`md5` 相同的记录视为同一个表情,只保留一条。
83
+ * 本机收集的表情和 QQ 收藏表情共用一套编号,按图片 md5 认回同一个编号。
73
84
  */
74
- async sync(faces: readonly CustomFace[]): Promise<FavoriteRow[]> {
85
+ async sync(
86
+ faces: readonly CustomFace[],
87
+ collected: readonly CollectedSticker[] = [],
88
+ ): Promise<FavoriteRow[]> {
75
89
  await this.ensureLoaded()
76
90
  const rows: FavoriteRow[] = []
77
91
  const seen = new Set<string>()
@@ -94,14 +108,37 @@ export class FavoriteIndex {
94
108
  }
95
109
  rows.push({ id, face, tag: faceTag(face) })
96
110
  }
111
+ for (const sticker of collected) {
112
+ const key = collectedKey(sticker)
113
+ // 和 QQ 收藏表情撞上同一张图时以 QQ 收藏表情为准。
114
+ if (seen.has(key)) continue
115
+ seen.add(key)
116
+ let id = this.entries.get(key)
117
+ if (id === undefined) {
118
+ id = nextId
119
+ nextId += 1
120
+ this.entries.set(key, id)
121
+ changed = true
122
+ }
123
+ rows.push({
124
+ id,
125
+ face: { md5: sticker.md5, url: sticker.file, desc: sticker.description },
126
+ tag: sticker.description,
127
+ collected: sticker,
128
+ })
129
+ }
97
130
  rows.sort((left, right) => left.id - right.id)
98
131
  if (changed) await this.persist()
99
132
  return rows
100
133
  }
101
134
 
102
135
  /** 按编号找收藏表情;编号不存在时返回 undefined。 */
103
- async resolve(faces: readonly CustomFace[], id: number): Promise<FavoriteRow | undefined> {
104
- const rows = await this.sync(faces)
136
+ async resolve(
137
+ faces: readonly CustomFace[],
138
+ id: number,
139
+ collected: readonly CollectedSticker[] = [],
140
+ ): Promise<FavoriteRow | undefined> {
141
+ const rows = await this.sync(faces, collected)
105
142
  return rows.find((row) => row.id === id)
106
143
  }
107
144
 
@@ -1,6 +1,7 @@
1
1
  import { Mutex } from "async-mutex"
2
2
  import type { Logger } from "../logger"
3
3
  import { sanitizeUntrustedText } from "../model-view"
4
+ import type { CollectedSticker } from "./collection"
4
5
 
5
6
  /**
6
7
  * NapCat 收藏表情(自定义表情)的详情。
@@ -57,6 +58,8 @@ export interface FavoriteRow {
57
58
  face: CustomFace
58
59
  /** 收藏表情当前的标签。 */
59
60
  tag: string
61
+ /** 本机收集的表情;QQ 收藏表情没有这个字段。 */
62
+ collected?: CollectedSticker
60
63
  }
61
64
 
62
65
  /**
@@ -66,7 +69,10 @@ export interface FavoriteRow {
66
69
  */
67
70
  export function formatFavoriteList(rows: readonly FavoriteRow[]): string {
68
71
  if (rows.length === 0) return "没有读取到收藏表情。"
69
- const lines = rows.map((row) => `${row.id}. ${row.tag || "(未标注)"}`)
72
+ const lines = rows.map((row) => {
73
+ const tag = row.tag || "(未标注)"
74
+ return `${row.id}. ${tag}${row.collected ? "(本机收藏)" : ""}`
75
+ })
70
76
  return [`收藏表情(编号即发送用的 id,共 ${rows.length} 个)`, ...lines].join("\n")
71
77
  }
72
78
 
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { join, resolve } from "node:path"
2
- import { randomBytes } from "node:crypto"
3
2
  import { Plugin } from "@opencode/plugin"
4
3
  import type { GroupMessageEvent, MessageEvent, NoticeEvent } from "@naplink/naplink"
5
4
  import { Mutex } from "async-mutex"
@@ -73,6 +72,7 @@ import { registerTuiCommands } from "./tui-commands"
73
72
  import { pluginVersion } from "./version"
74
73
  import { FavoriteStore } from "./emoji/favorites"
75
74
  import { FavoriteIndex } from "./emoji/favorite-index"
75
+ import { CollectionStore, RecentImages } from "./emoji/collection"
76
76
  import { EmojiLabeler } from "./emoji/label"
77
77
 
78
78
  const RETRY_DELAY_MS = 1000
@@ -200,18 +200,7 @@ export default Plugin.define({
200
200
  logger.warn("未配置放行目标,插件不会响应任何消息(请在 config.json 里配置 access.allow)")
201
201
  }
202
202
 
203
- // 面板令牌:没配就随机生成,明文写回配置文件,之后重启不变。
204
- if (config.panel.enabled) {
205
- if (!config.panel.token) {
206
- const token = randomBytes(32).toString("hex")
207
- await controller.applyPatch({ "panel.token": token })
208
- logger.warn("面板访问令牌已生成,请查看 config.json 里的 panel.token")
209
- } else if (config.panel.token.length < 16) {
210
- logger.warn("面板访问令牌太短,建议至少 16 个字符")
211
- }
212
- }
213
-
214
- // 状态面板:默认关闭,启用后自带 HTTP 服务。
203
+ // 状态面板:默认开启,自带 HTTP 服务,只监听本机。
215
204
  const panelRuntime = new PanelRuntime({ config, home, logger })
216
205
  panelRuntime.version = version
217
206
  panelRuntime.agent = config.agent
@@ -519,6 +508,10 @@ export default Plugin.define({
519
508
  logger,
520
509
  )
521
510
  const favoriteIndex = new FavoriteIndex(ctx.storage, logger)
511
+ // 本机收集的表情:QQ 收藏表情写不进 NapCat,收集的动图自己存在媒体目录里。
512
+ const collection = new CollectionStore(ctx.storage, mediaDir, logger)
513
+ // 各聊天最近收到的图片:收藏表情时从中挑素材。
514
+ const recentImages = new RecentImages()
522
515
  const labeler = new EmojiLabeler({ ctx, config, home, logger, media, favorites })
523
516
  cleanup.add("注销表情标注", () => labeler.dispose(), CleanupOrder.labeler)
524
517
  // 日记:素材累积在 raw/ 下,成品是按天一个的 Markdown 文件。
@@ -571,6 +564,8 @@ export default Plugin.define({
571
564
  client,
572
565
  favorites,
573
566
  favoriteIndex,
567
+ collection,
568
+ recentImages,
574
569
  limiter,
575
570
  sensitive,
576
571
  outbound,
@@ -842,6 +837,8 @@ export default Plugin.define({
842
837
  const renderCtx = renderContext(target, selfId)
843
838
  const rendered = await renderMessage(renderCtx, event)
844
839
  if (!rendered.text.trim()) return
840
+ // 记下这张消息里的图片:收藏表情时从中挑最近收到的那张动图。
841
+ await recentImages.record(target, rendered.files, String(event.message_id))
845
842
 
846
843
  const senderRole = roleOf(config, String(event.user_id))
847
844
  const userName = await resolveUserName(renderCtx, String(event.user_id))