koishi-plugin-codex-reset 0.1.5 → 0.1.6

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 CHANGED
@@ -24,11 +24,15 @@
24
24
 
25
25
  概率、最近重置、日历和历史时间线命令始终启用;安装并启用 `koishi-plugin-puppeteer` 后会发送对应图片,没有 Puppeteer 时概率和最近重置会回退为纯文本,日历和历史时间线会提示安装 Puppeteer。
26
26
 
27
- 日历、月度统计及右侧动态仅展示已确认且日期不晚于今天的事件,不展示预告。日期优先使用实际发生日期,缺失时使用北京时间的确认日期;两者均缺失时不展示,不使用预计时间窗口代替实际日期。
28
-
29
- 首次安装时的第一份快照只建立基线,不会把历史事件全部推送。插件将已见事件状态和待发送通知保存在 Koishi 工作目录的 `data/codex-reset/` 中;重启后继续去重并重试未成功的目标。API 暂时漏掉旧事件、随后又补回时,也不会把它再次当作新事件。只有最近 48 小时内发布的预告或确认事件才会新建推送;超过 48 小时仍未送达的通知会放弃。更改 API 地址或推送目标后会建立新的基线。
30
-
31
- 图片生成最多同时进行 2 项,新的图片任务至少间隔 3 秒;历史图片超过 120 条事件时会提示缩小查询范围。图片中的长篇来源文字会截短。API 响应上限为 4 MiB。
27
+ 日历、月度统计及右侧动态仅展示已确认且日期不晚于今天的事件,不展示预告。日期优先使用实际发生日期,缺失时使用北京时间的确认日期;两者均缺失时不展示,不使用预计时间窗口代替实际日期。
28
+
29
+ 首次安装时的第一份快照只建立基线,不会把历史事件全部推送。插件将已见事件状态和待发送通知保存在 Koishi 工作目录的 `data/codex-reset/` 中;重启后继续去重并重试未成功的目标。API 暂时漏掉旧事件、随后又补回时,也不会把它再次当作新事件。只有最近 48 小时内发布的预告或确认事件才会新建推送;超过 48 小时仍未送达的通知会放弃。更改 API 地址或推送目标后会建立新的基线。
30
+
31
+ 从 0.1.6 起,需要启用 Koishi 数据库服务(例如 SQLite、MySQL 或 PostgreSQL)。完整 API 快照、ETag、最近同步时间和下次允许请求的时间保存在 `codex_reset_cache` 表中,相同 API 地址共用一份记录。所有查询命令只读数据库,不直接请求上游;首次同步尚未成功时会提示稍后再试。重启、重载插件后仍可查询已保存的数据,并继续遵守冷却时间。同步失败时保留上次成功的数据,可能暂时不是最新状态。
32
+
33
+ 后台默认每 660 秒同步一次;旧配置小于 660 秒时,实际请求也不会快于 660 秒。请求前先保存冷却时间,收到 HTTP 429 或 503 时遵循 `Retry-After`(也支持响应正文的 `retryAfter` 秒数),冷却期间不会因重启或手动查询再次请求。数据库写入失败时不会继续发起新的上游请求。
34
+
35
+ 图片生成最多同时进行 2 项,新的图片任务至少间隔 3 秒;历史图片超过 120 条事件时会提示缩小查询范围。图片中的长篇来源文字会截短。API 响应上限为 4 MiB。
32
36
 
33
37
  ## 安装
34
38
 
@@ -36,12 +40,12 @@
36
40
  npm install koishi-plugin-codex-reset
37
41
  ```
38
42
 
39
- 如果需要概率卡片、最近重置卡片、日历或历史时间线图片,再安装并启用 `koishi-plugin-puppeteer`。不安装 Puppeteer 时,监控、最近重置和概率分析仍然可以使用,概率与最近重置命令回退为纯文本,日历和历史命令会给出提示。
43
+ 先在 Koishi 中启用一个数据库插件,再启用本插件;如果已经使用数据库服务,无需另建数据库。如果需要概率卡片、最近重置卡片、日历或历史时间线图片,再安装并启用 `koishi-plugin-puppeteer`。不安装 Puppeteer 时,监控、最近重置和概率分析仍然可以使用,概率与最近重置命令回退为纯文本,日历和历史命令会给出提示。
40
44
 
41
45
  ## 配置
42
46
 
43
47
  - `监控接口地址`:监控 API 地址,默认 `https://aihot.news/api/v1/codex-resets`。
44
- - `监控间隔`:轮询间隔,单位为秒,默认 300 秒。
48
+ - `监控间隔`:轮询间隔,单位为秒,默认 660 秒(11 分钟)。实际请求间隔至少 660 秒,并遵守服务端更长的缓存及重试等待时间。
45
49
  - `请求超时时间`:单次 API 请求超时时间,单位为毫秒,默认 15000 毫秒。
46
50
  - `推送目标`:推送目标表,填写“平台”和“频道或群组 ID”;平台留空会按频道尝试在线 Bot,同一平台/频道只发送一次。
47
51
  - `推送重置预告`:是否推送预告。
package/lib/cache.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { Context } from 'koishi';
2
+ import type { CodexResetsResponse } from './types';
3
+ export declare const MIN_POLL_INTERVAL_MS = 660000;
4
+ export interface SnapshotCache {
5
+ id: string;
6
+ snapshot: CodexResetsResponse | null;
7
+ etag: string | null;
8
+ fetchedAt: number;
9
+ nextFetchAt: number;
10
+ requestId: string;
11
+ }
12
+ declare module 'koishi' {
13
+ interface Tables {
14
+ codex_reset_cache: SnapshotCache;
15
+ }
16
+ }
17
+ export interface FetchResult {
18
+ snapshot: CodexResetsResponse | null;
19
+ etag: string | null;
20
+ notModified: boolean;
21
+ maxAgeMs: number;
22
+ }
23
+ export declare class SnapshotRequestError extends Error {
24
+ readonly retryAfterMs: number;
25
+ constructor(message: string, retryAfterMs: number);
26
+ }
27
+ export declare function extendCacheModel(ctx: Context): void;
28
+ export declare class SnapshotStore {
29
+ private readonly ctx;
30
+ private readonly validate;
31
+ private readonly id;
32
+ constructor(ctx: Context, apiUrl: string, validate: (value: unknown) => value is CodexResetsResponse);
33
+ read(): Promise<SnapshotCache>;
34
+ refresh(intervalMs: number, timeoutMs: number, fetchSnapshot: (cache: SnapshotCache) => Promise<FetchResult>): Promise<SnapshotCache>;
35
+ private performRefresh;
36
+ }
package/lib/cache.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapshotStore = exports.SnapshotRequestError = exports.MIN_POLL_INTERVAL_MS = void 0;
4
+ exports.extendCacheModel = extendCacheModel;
5
+ const node_crypto_1 = require("node:crypto");
6
+ // Leave a little room beyond AIHOT's ten-minute full-history limit.
7
+ exports.MIN_POLL_INTERVAL_MS = 660_000;
8
+ const TABLE = 'codex_reset_cache';
9
+ const inFlight = new WeakMap();
10
+ class SnapshotRequestError extends Error {
11
+ retryAfterMs;
12
+ constructor(message, retryAfterMs) {
13
+ super(message);
14
+ this.retryAfterMs = retryAfterMs;
15
+ }
16
+ }
17
+ exports.SnapshotRequestError = SnapshotRequestError;
18
+ function extendCacheModel(ctx) {
19
+ ctx.model.extend(TABLE, {
20
+ id: 'string',
21
+ snapshot: { type: 'json', nullable: true, initial: null },
22
+ etag: { type: 'string', nullable: true, initial: null },
23
+ fetchedAt: { type: 'double', initial: 0 },
24
+ nextFetchAt: { type: 'double', initial: 0 },
25
+ requestId: { type: 'string', initial: '' },
26
+ }, { primary: 'id' });
27
+ }
28
+ class SnapshotStore {
29
+ ctx;
30
+ validate;
31
+ id;
32
+ constructor(ctx, apiUrl, validate) {
33
+ this.ctx = ctx;
34
+ this.validate = validate;
35
+ // Targets do not affect API data or the upstream request quota.
36
+ this.id = (0, node_crypto_1.createHash)('sha256').update(new URL(apiUrl).href).digest('hex');
37
+ }
38
+ async read() {
39
+ let [cache] = await this.ctx.database.get(TABLE, this.id);
40
+ if (!cache) {
41
+ try {
42
+ cache = await this.ctx.database.create(TABLE, { id: this.id });
43
+ }
44
+ catch (error) {
45
+ // Another instance may have created the same API cache concurrently.
46
+ const existing = await this.ctx.database.get(TABLE, this.id);
47
+ cache = existing[0];
48
+ if (!cache)
49
+ throw error;
50
+ }
51
+ }
52
+ if (!this.validate(cache.snapshot))
53
+ return { ...cache, snapshot: null, etag: null };
54
+ return cache;
55
+ }
56
+ refresh(intervalMs, timeoutMs, fetchSnapshot) {
57
+ const root = this.ctx.root ?? this.ctx;
58
+ let requests = inFlight.get(root);
59
+ if (!requests)
60
+ inFlight.set(root, requests = new Map());
61
+ const pending = requests.get(this.id);
62
+ if (pending)
63
+ return pending;
64
+ const request = this.performRefresh(intervalMs, timeoutMs, fetchSnapshot)
65
+ .finally(() => requests.delete(this.id));
66
+ requests.set(this.id, request);
67
+ return request;
68
+ }
69
+ async performRefresh(intervalMs, timeoutMs, fetchSnapshot) {
70
+ const cache = await this.read();
71
+ const now = Date.now();
72
+ if (now < cache.nextFetchAt)
73
+ return cache;
74
+ const delay = Math.max(exports.MIN_POLL_INTERVAL_MS, intervalMs);
75
+ const requestId = (0, node_crypto_1.randomUUID)();
76
+ // Reserve the next request before network I/O. A restart or another plugin
77
+ // instance must observe this reservation, even if the request fails.
78
+ await this.ctx.database.set(TABLE, {
79
+ id: this.id,
80
+ nextFetchAt: cache.nextFetchAt,
81
+ requestId: cache.requestId,
82
+ }, {
83
+ requestId,
84
+ nextFetchAt: now + Math.max(delay, timeoutMs + 1000),
85
+ });
86
+ const reserved = await this.read();
87
+ if (reserved.requestId !== requestId)
88
+ return reserved;
89
+ try {
90
+ const result = await fetchSnapshot(cache);
91
+ await this.ctx.database.set(TABLE, { id: this.id, requestId }, {
92
+ snapshot: result.notModified ? cache.snapshot : result.snapshot,
93
+ etag: result.etag,
94
+ fetchedAt: Date.now(),
95
+ nextFetchAt: Math.max(now + delay, Date.now() + result.maxAgeMs),
96
+ });
97
+ }
98
+ catch (error) {
99
+ const retryAfterMs = error instanceof SnapshotRequestError ? error.retryAfterMs : 0;
100
+ await this.ctx.database.set(TABLE, { id: this.id, requestId }, {
101
+ nextFetchAt: Date.now() + Math.max(delay, retryAfterMs),
102
+ });
103
+ throw error;
104
+ }
105
+ return this.read();
106
+ }
107
+ }
108
+ exports.SnapshotStore = SnapshotStore;
package/lib/calendar.js CHANGED
@@ -175,7 +175,7 @@ function renderDetails(events) {
175
175
  const statusClass = event.status === 'confirmed' ? 'confirmed-state' : 'announced-state';
176
176
  return `<section class="event-group">
177
177
  <div class="event-state ${statusClass}"><span class="state-icon">${event.status === 'confirmed' ? '✓' : '◷'}</span>${status}</div>
178
- <h2>${escapeHtml(event.title.slice(0, 200))}</h2>
178
+ <h2>${escapeHtml(event.title.slice(0, 200))}</h2>
179
179
  ${renderPostCard(event, post)}
180
180
  </section>`;
181
181
  }).join('');
@@ -270,7 +270,7 @@ function renderCalendarHtml(events, now = new Date()) {
270
270
  </header>
271
271
  <div class="weekday-row">${WEEK_NAMES.map((name) => `<span>${name}</span>`).join('')}</div>
272
272
  <div class="calendar-grid">${renderCalendarGrid(month, marks, selectedDate, today)}</div>
273
- <div class="calendar-note">仅显示已确认事件;按北京时间记录实际发生日期,缺失时按确认日期展示;不含预告。</div>
273
+ <div class="calendar-note">仅显示已确认事件;按北京时间记录实际发生日期,缺失时按确认日期展示;不含预告。</div>
274
274
  </section>
275
275
  ${renderDetails(events)}
276
276
  </main>
package/lib/event.js CHANGED
@@ -121,7 +121,7 @@ function renderLatestResetHtml(summary, now = new Date()) {
121
121
  </section>
122
122
  <section class="source">
123
123
  <header class="source-header"><h2>事件来源</h2><span>北京时间</span></header>
124
- <h2 class="event-title">${escapeHtml(event.title.slice(0, 200))}</h2>
124
+ <h2 class="event-title">${escapeHtml(event.title.slice(0, 200))}</h2>
125
125
  ${renderSourcePost(summary)}
126
126
  <p class="source-note">${escapeHtml(event.scope ? `范围:${event.scope}` : '公开来源帖子记录')}</p>
127
127
  <div class="mark">RESET MONITOR</div>
package/lib/history.js CHANGED
@@ -114,7 +114,7 @@ function renderTimelineItem(event) {
114
114
  <div class="timeline-dot ${statusClass}"></div>
115
115
  <div class="event-card">
116
116
  <div class="event-meta"><span class="type-label">${typeLabel(event)}</span><span class="status ${statusClass}">${statusLabel(event)}</span></div>
117
- <h2>${escapeHtml(event.title.slice(0, 200))}</h2>
117
+ <h2>${escapeHtml(event.title.slice(0, 200))}</h2>
118
118
  ${schedule}
119
119
  ${renderPostPreview(event)}
120
120
  </div>
package/lib/index.d.ts CHANGED
@@ -2,8 +2,10 @@ import { Context, Schema } from 'koishi';
2
2
  import type { Config as PluginConfig } from './types';
3
3
  export declare const name = "codex-reset";
4
4
  export declare const inject: {
5
+ required: string[];
5
6
  optional: string[];
6
7
  };
7
8
  export type Config = PluginConfig;
9
+ export type { SnapshotCache } from './cache';
8
10
  export declare const Config: Schema<Config>;
9
11
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -10,6 +10,7 @@ const calendar_1 = require("./calendar");
10
10
  const history_1 = require("./history");
11
11
  const event_1 = require("./event");
12
12
  const probability_1 = require("./probability");
13
+ const cache_1 = require("./cache");
13
14
  const stats_1 = require("./stats");
14
15
  exports.name = 'codex-reset';
15
16
  const MAX_NOTIFICATION_AGE_MS = 48 * 60 * 60 * 1000;
@@ -21,6 +22,7 @@ const RENDER_START_INTERVAL_MS = 3000;
21
22
  class RenderBusyError extends Error {
22
23
  }
23
24
  exports.inject = {
25
+ required: ['database'],
24
26
  optional: ['puppeteer'],
25
27
  };
26
28
  exports.Config = koishi_1.Schema.object({
@@ -29,8 +31,8 @@ exports.Config = koishi_1.Schema.object({
29
31
  .description('监控接口地址。通常不需要修改。'),
30
32
  pollInterval: koishi_1.Schema.number()
31
33
  .min(60)
32
- .default(300)
33
- .description('监控间隔,单位为秒。AIHOT 推荐约 5 分钟轮询一次。'),
34
+ .default(660)
35
+ .description('监控间隔,单位为秒,默认 660 秒。兼容旧配置,实际请求间隔至少 660 秒;重启后继续遵守已保存的冷却时间。'),
34
36
  requestTimeout: koishi_1.Schema.number()
35
37
  .min(5000)
36
38
  .default(15000)
@@ -219,8 +221,7 @@ async function sendToTargets(ctx, targets, content, deliveredBindings, onDeliver
219
221
  class CodexResetMonitor {
220
222
  ctx;
221
223
  config;
222
- snapshot = null;
223
- etag = null;
224
+ snapshots;
224
225
  pollPromise = null;
225
226
  disposed = false;
226
227
  statePath;
@@ -233,22 +234,26 @@ class CodexResetMonitor {
233
234
  constructor(ctx, config) {
234
235
  this.ctx = ctx;
235
236
  this.config = config;
237
+ this.snapshots = new cache_1.SnapshotStore(ctx, config.apiUrl, isSnapshot);
236
238
  const instanceId = (0, node_crypto_1.createHash)('sha256')
237
239
  .update(JSON.stringify({ apiUrl: config.apiUrl, targets: config.targets }))
238
240
  .digest('hex').slice(0, 16);
239
241
  this.statePath = (0, node_path_1.join)(ctx.baseDir, 'data', 'codex-reset', `${instanceId}.json`);
240
242
  this.stateLoaded = this.loadState();
241
243
  }
242
- get currentSnapshot() {
243
- return this.snapshot;
244
- }
245
244
  get hasPuppeteer() {
246
245
  return Boolean(this.ctx.puppeteer);
247
246
  }
248
247
  async ensureSnapshot() {
249
- if (!this.snapshot)
250
- await this.poll();
251
- return this.snapshot;
248
+ // Commands only read the database. A missing snapshot must not turn every
249
+ // user command into another upstream request during a rate-limit window.
250
+ try {
251
+ return (await this.snapshots.read()).snapshot;
252
+ }
253
+ catch (error) {
254
+ this.ctx.logger('codex-reset').warn(`读取重置数据失败:${error instanceof Error ? error.message : String(error)}`);
255
+ return null;
256
+ }
252
257
  }
253
258
  async poll() {
254
259
  if (this.disposed)
@@ -263,24 +268,32 @@ class CodexResetMonitor {
263
268
  this.pollPromise = null;
264
269
  }
265
270
  }
271
+ async start() {
272
+ await this.poll();
273
+ if (!this.disposed) {
274
+ this.ctx.setInterval(() => this.poll(), Math.max(cache_1.MIN_POLL_INTERVAL_MS, this.config.pollInterval * 1000));
275
+ }
276
+ }
266
277
  dispose() {
267
278
  this.disposed = true;
268
279
  }
269
280
  async performPoll() {
270
281
  try {
271
282
  await this.stateLoaded;
272
- const result = await this.fetchSnapshot();
273
- if (!result.notModified && result.snapshot) {
274
- this.snapshot = result.snapshot;
275
- this.etag = result.etag ?? this.etag;
283
+ if (this.disposed)
284
+ return;
285
+ const cache = await this.snapshots.refresh(this.config.pollInterval * 1000, this.config.requestTimeout, (cached) => this.fetchSnapshot(cached));
286
+ if (this.disposed)
287
+ return;
288
+ if (cache.snapshot) {
276
289
  if (!this.initialized) {
277
290
  // A fresh installation starts with the entire current snapshot as its baseline.
278
- for (const event of result.snapshot.events)
291
+ for (const event of cache.snapshot.events)
279
292
  this.markSeen(event);
280
293
  this.initialized = true;
281
294
  }
282
295
  else {
283
- this.captureChanges(result.snapshot, Date.now());
296
+ this.captureChanges(cache.snapshot, Date.now());
284
297
  }
285
298
  }
286
299
  await this.flushPending();
@@ -428,67 +441,90 @@ class CodexResetMonitor {
428
441
  if (changed)
429
442
  await this.saveState();
430
443
  }
431
- async fetchSnapshot() {
444
+ async fetchSnapshot(cache) {
432
445
  const controller = new AbortController();
433
446
  const timeout = setTimeout(() => controller.abort(), this.config.requestTimeout);
434
447
  try {
435
448
  const headers = {
436
449
  Accept: 'application/json',
437
- 'User-Agent': 'koishi-plugin-codex-reset/0.1.5',
450
+ 'User-Agent': 'koishi-plugin-codex-reset/0.1.6',
438
451
  };
439
- if (this.etag && this.snapshot)
440
- headers['If-None-Match'] = this.etag;
452
+ if (cache.etag && cache.snapshot)
453
+ headers['If-None-Match'] = cache.etag;
441
454
  const response = await fetch(this.config.apiUrl, {
442
455
  method: 'GET',
443
456
  headers,
444
457
  signal: controller.signal,
445
458
  });
446
- if (response.status === 304 && this.snapshot) {
447
- return { snapshot: null, etag: this.etag, notModified: true };
459
+ const maxAgeMs = Math.max(0, ...Array.from((response.headers.get('cache-control') ?? '').matchAll(/(?:^|[,\s])(?:s-maxage|max-age)=(\d+)/gi), (match) => Number(match[1]) * 1000).filter(Number.isFinite));
460
+ if (response.status === 304 && cache.snapshot) {
461
+ return { snapshot: null, etag: response.headers.get('etag') ?? cache.etag, notModified: true, maxAgeMs };
448
462
  }
449
463
  if (response.status === 304)
450
464
  throw new Error('服务端在没有本地快照时返回了 304');
451
- if (!response.ok)
452
- throw new Error(`HTTP ${response.status}`);
453
- const declaredLength = Number(response.headers.get('content-length'));
454
- if (declaredLength > MAX_API_RESPONSE_BYTES)
455
- throw new Error('API 响应超过 4 MiB');
456
- if (!response.body)
457
- throw new Error('API 响应没有内容');
458
- const reader = response.body.getReader();
459
- const chunks = [];
460
- let size = 0;
461
- while (true) {
462
- const { done, value } = await reader.read();
463
- if (done)
464
- break;
465
- size += value.byteLength;
466
- if (size > MAX_API_RESPONSE_BYTES) {
467
- await reader.cancel();
468
- throw new Error('API 响应超过 4 MiB');
465
+ if (response.status === 429 || response.status === 503) {
466
+ const retryAfter = response.headers.get('retry-after');
467
+ let retryAfterMs = 0;
468
+ if (retryAfter) {
469
+ retryAfterMs = /^\d+$/.test(retryAfter.trim())
470
+ ? Number(retryAfter) * 1000
471
+ : Date.parse(retryAfter) - Date.now();
472
+ }
473
+ try {
474
+ const problem = await this.readResponseBody(response);
475
+ if (isRecord(problem) && typeof problem.retryAfter === 'number' && Number.isFinite(problem.retryAfter)) {
476
+ retryAfterMs = Math.max(Number.isFinite(retryAfterMs) ? retryAfterMs : 0, problem.retryAfter * 1000);
477
+ }
469
478
  }
470
- chunks.push(value);
479
+ catch {
480
+ // An HTML or malformed error body must still honor Retry-After.
481
+ }
482
+ retryAfterMs = Math.max(cache_1.MIN_POLL_INTERVAL_MS, Number.isFinite(retryAfterMs) ? retryAfterMs : 0);
483
+ throw new cache_1.SnapshotRequestError(`HTTP ${response.status},至少等待 ${Math.ceil(retryAfterMs / 1000)} 秒后重试`, retryAfterMs);
471
484
  }
472
- const body = JSON.parse(Buffer.concat(chunks).toString('utf8'));
485
+ if (!response.ok)
486
+ throw new Error(`HTTP ${response.status}`);
487
+ const body = await this.readResponseBody(response);
473
488
  if (!isSnapshot(body))
474
489
  throw new Error('响应格式不符合 Codex 重置 API v1');
475
490
  return {
476
491
  snapshot: body,
477
492
  etag: response.headers.get('etag'),
478
493
  notModified: false,
494
+ maxAgeMs,
479
495
  };
480
496
  }
481
497
  finally {
482
498
  clearTimeout(timeout);
483
499
  }
484
500
  }
501
+ async readResponseBody(response) {
502
+ const declaredLength = Number(response.headers.get('content-length'));
503
+ if (declaredLength > MAX_API_RESPONSE_BYTES)
504
+ throw new Error('API 响应超过 4 MiB');
505
+ if (!response.body)
506
+ throw new Error('API 响应没有内容');
507
+ const reader = response.body.getReader();
508
+ const chunks = [];
509
+ let size = 0;
510
+ while (true) {
511
+ const { done, value } = await reader.read();
512
+ if (done)
513
+ break;
514
+ size += value.byteLength;
515
+ if (size > MAX_API_RESPONSE_BYTES) {
516
+ await reader.cancel();
517
+ throw new Error('API 响应超过 4 MiB');
518
+ }
519
+ chunks.push(value);
520
+ }
521
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'));
522
+ }
485
523
  }
486
524
  function apply(ctx, config) {
525
+ (0, cache_1.extendCacheModel)(ctx);
487
526
  const monitor = new CodexResetMonitor(ctx, config);
488
- ctx.on('ready', () => {
489
- void monitor.poll();
490
- ctx.setInterval(() => void monitor.poll(), config.pollInterval * 1000);
491
- });
527
+ ctx.on('ready', () => monitor.start());
492
528
  ctx.on('dispose', () => monitor.dispose());
493
529
  ctx.command('codex.probability', '分析 Codex 重置事件的历史概率')
494
530
  .alias('重置概率')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-codex-reset",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Monitor AIHOT Codex reset events and notify Koishi channels.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -44,6 +44,7 @@
44
44
  }
45
45
  },
46
46
  "devDependencies": {
47
+ "@minatojs/driver-sqlite": "4.7.0",
47
48
  "@types/node": "^22.0.0",
48
49
  "koishi": "^4.18.9",
49
50
  "typescript": "^5.7.0"