koishi-plugin-rina-llevents 0.0.1

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,3 @@
1
+ import { Context } from 'koishi';
2
+ import { LlEventService } from './service';
3
+ export declare function registerCommands(ctx: Context, service: LlEventService): void;
@@ -0,0 +1,19 @@
1
+ import { Schema } from 'koishi';
2
+ export interface BroadcastTarget {
3
+ enabled: boolean;
4
+ platform: string;
5
+ selfId: string;
6
+ channelId: string;
7
+ }
8
+ export interface Config {
9
+ requestTimeout: number;
10
+ listIntervalMinutes: number;
11
+ lookaheadDays: number;
12
+ reminderMinutes: number;
13
+ expectedDurationMinutes: number;
14
+ setlistPollIntervalMinutes: number;
15
+ setlistPollHours: number;
16
+ syncOnStart: boolean;
17
+ targets: BroadcastTarget[];
18
+ }
19
+ export declare const Config: Schema<Config>;
@@ -0,0 +1,3 @@
1
+ import { LlConcert, LlEvent, LlPerformance } from './model';
2
+ export declare function formatReminder(event: LlEvent | undefined, concert: LlConcert | undefined, performance: LlPerformance, start: Date, minutes: number): string;
3
+ export declare function formatSetlistCaption(event: LlEvent | undefined, concert: LlConcert | undefined, performance: LlPerformance, updated: boolean): string;
@@ -0,0 +1,49 @@
1
+ import { Context } from 'koishi';
2
+ export interface TourSummary {
3
+ id: string;
4
+ name: string;
5
+ startsOn?: string;
6
+ endsOn?: string;
7
+ }
8
+ export interface TourDetail extends TourSummary {
9
+ concerts?: Array<{
10
+ id: string;
11
+ name?: string;
12
+ venue?: {
13
+ name?: string;
14
+ };
15
+ performances?: Array<{
16
+ id: string;
17
+ name?: string;
18
+ }>;
19
+ }>;
20
+ }
21
+ export interface SetlistItem {
22
+ id: string;
23
+ indexPrefix?: string;
24
+ indexNumber?: number;
25
+ content?: {
26
+ __typename?: string;
27
+ name?: string;
28
+ };
29
+ contentTypeOther?: string;
30
+ note?: string;
31
+ premiere?: boolean;
32
+ }
33
+ export interface PerformanceDetail {
34
+ id: string;
35
+ canceled?: boolean;
36
+ date?: string;
37
+ openTime?: string;
38
+ startTime?: string;
39
+ setlists?: SetlistItem[];
40
+ }
41
+ export declare class LlFansClient {
42
+ private ctx;
43
+ private timeout;
44
+ constructor(ctx: Context, timeout: number);
45
+ private query;
46
+ listTours(): Promise<TourSummary[]>;
47
+ getTour(id: string): Promise<TourDetail>;
48
+ getPerformance(id: string): Promise<PerformanceDetail>;
49
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { Context } from 'koishi';
2
+ import 'koishi-plugin-cron';
3
+ import { Config as ConfigSchema, Config as PluginConfig } from './config';
4
+ export declare const name = "rina-llevents";
5
+ export declare const inject: {
6
+ required: string[];
7
+ optional: string[];
8
+ };
9
+ export type Config = PluginConfig;
10
+ export declare const Config: import("schemastery")<ConfigSchema>;
11
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js ADDED
@@ -0,0 +1,760 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Config: () => Config2,
24
+ apply: () => apply,
25
+ inject: () => inject,
26
+ name: () => name
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+ var import_koishi_plugin_cron = require("koishi-plugin-cron");
30
+
31
+ // src/config.ts
32
+ var import_koishi = require("koishi");
33
+ var Target = import_koishi.Schema.object({
34
+ enabled: import_koishi.Schema.boolean().default(true).description("启用此群推送目标"),
35
+ platform: import_koishi.Schema.string().required().description("平台名,例如 onebot、qq、telegram"),
36
+ selfId: import_koishi.Schema.string().required().description("发送消息的机器人 ID"),
37
+ channelId: import_koishi.Schema.string().required().description("群组或频道 ID")
38
+ });
39
+ var Config = import_koishi.Schema.object({
40
+ requestTimeout: import_koishi.Schema.number().min(1e3).max(6e4).default(15e3).description("LL-Fans 请求超时(毫秒)"),
41
+ listIntervalMinutes: import_koishi.Schema.number().min(5).max(1440).default(30).description("活动列表同步间隔(分钟)"),
42
+ lookaheadDays: import_koishi.Schema.number().min(1).max(730).default(365).description("缓存和变更检查的未来活动范围(天)"),
43
+ reminderMinutes: import_koishi.Schema.number().min(1).max(120).default(10).description("开演前提醒分钟数"),
44
+ expectedDurationMinutes: import_koishi.Schema.number().min(30).max(720).default(210).description("未提供结束时间时用于开始歌单轮询的预计时长"),
45
+ setlistPollIntervalMinutes: import_koishi.Schema.number().min(1).max(60).default(5).description("演出后歌单轮询间隔(分钟)"),
46
+ setlistPollHours: import_koishi.Schema.number().min(1).max(72).default(24).description("演出后歌单轮询最长时长"),
47
+ syncOnStart: import_koishi.Schema.boolean().default(true).description("配置了推送目标时,插件启动后立即同步活动列表"),
48
+ targets: import_koishi.Schema.array(Target).default([]).description("提醒与歌单推送目标")
49
+ });
50
+
51
+ // src/commands.ts
52
+ var import_koishi2 = require("koishi");
53
+
54
+ // src/service.ts
55
+ var import_node_crypto = require("node:crypto");
56
+ var DAY = 24 * 60 * 60 * 1e3;
57
+ function hash(value) {
58
+ return (0, import_node_crypto.createHash)("sha256").update(JSON.stringify(value)).digest("hex");
59
+ }
60
+ __name(hash, "hash");
61
+ var EMPTY_SETLIST_HASH = hash([]);
62
+ function dateAtEnd(date) {
63
+ return date ? /* @__PURE__ */ new Date(`${date}T23:59:59+09:00`) : void 0;
64
+ }
65
+ __name(dateAtEnd, "dateAtEnd");
66
+ function performanceStart(performance) {
67
+ if (!performance.date || !performance.startTime) return;
68
+ const time = /^\d{2}:\d{2}$/.test(performance.startTime) ? `${performance.startTime}:00` : performance.startTime;
69
+ const value = /* @__PURE__ */ new Date(`${performance.date}T${time}+09:00`);
70
+ return Number.isNaN(value.getTime()) ? void 0 : value;
71
+ }
72
+ __name(performanceStart, "performanceStart");
73
+ function canonicalUrl(eventId, concertId, performanceId) {
74
+ const query = new URLSearchParams();
75
+ if (concertId) query.set("concert", concertId);
76
+ if (performanceId) query.set("performance", performanceId);
77
+ const suffix = query.size ? `?${query}` : "";
78
+ return `https://ll-fans.jp/data/event/${eventId}${suffix}`;
79
+ }
80
+ __name(canonicalUrl, "canonicalUrl");
81
+ function normalizeSetlist(items = []) {
82
+ return items.map((item) => ({
83
+ index: `${item.indexPrefix || ""}${item.indexNumber == null ? "" : String(item.indexNumber).padStart(2, "0")}` || "—",
84
+ name: item.content?.name || item.contentTypeOther || item.content?.__typename || "未命名项目",
85
+ note: item.note || "",
86
+ premiere: !!item.premiere
87
+ }));
88
+ }
89
+ __name(normalizeSetlist, "normalizeSetlist");
90
+ function isWithinLookahead(tour, now, days) {
91
+ const end = dateAtEnd(tour.endsOn || tour.startsOn);
92
+ const start = tour.startsOn ? /* @__PURE__ */ new Date(`${tour.startsOn}T00:00:00+09:00`) : void 0;
93
+ if (!start || !end || Number.isNaN(start.getTime()) || Number.isNaN(end.getTime())) return false;
94
+ return end.getTime() >= now.getTime() - DAY && start.getTime() <= now.getTime() + days * DAY;
95
+ }
96
+ __name(isWithinLookahead, "isWithinLookahead");
97
+ var LlEventService = class {
98
+ constructor(ctx, logger, client, config) {
99
+ this.ctx = ctx;
100
+ this.logger = logger;
101
+ this.client = client;
102
+ this.config = config;
103
+ }
104
+ static {
105
+ __name(this, "LlEventService");
106
+ }
107
+ syncing = false;
108
+ lastListSyncAt = 0;
109
+ async syncIfDue(force = false) {
110
+ if (!force && Date.now() - this.lastListSyncAt < this.config.listIntervalMinutes * 6e4) return false;
111
+ await this.sync(force);
112
+ return true;
113
+ }
114
+ async sync(force = false) {
115
+ if (this.syncing) return;
116
+ this.syncing = true;
117
+ try {
118
+ const now = /* @__PURE__ */ new Date();
119
+ const tours = await this.client.listTours();
120
+ const existing = await this.ctx.database.get("rina_llevent_event", {});
121
+ const existingById = new Map(existing.map((event) => [event.id, event]));
122
+ const seen = new Set(tours.map((tour) => tour.id));
123
+ let details = 0;
124
+ for (const tour of tours) {
125
+ const previous = existingById.get(tour.id);
126
+ const changed = await this.upsertEvent(tour, previous, now);
127
+ if (!isWithinLookahead(tour, now, this.config.lookaheadDays)) continue;
128
+ if (force || changed || this.shouldRefreshEvent(previous, now)) {
129
+ try {
130
+ await this.syncTour(tour.id, now, force);
131
+ details++;
132
+ } catch (error) {
133
+ this.logger.warn(`活动 ${tour.id} 详情同步失败:${String(error)}`);
134
+ }
135
+ }
136
+ }
137
+ for (const event of existing) {
138
+ if (!event.active || seen.has(event.id)) continue;
139
+ const end = dateAtEnd(event.endsOn || event.startsOn);
140
+ if (!end || end.getTime() < now.getTime() - DAY) continue;
141
+ await this.ctx.database.set("rina_llevent_event", event.id, { active: false, syncedAt: now });
142
+ this.logger.warn(`活动 ${event.id} 已从 LL-Fans 列表移除,标记为待确认`);
143
+ }
144
+ this.lastListSyncAt = Date.now();
145
+ this.logger.debug(`活动列表同步完成:${tours.length} 条,刷新 ${details} 个详情`);
146
+ } finally {
147
+ this.syncing = false;
148
+ }
149
+ }
150
+ /** Loads one event regardless of date range. Used when a historical event is queried on demand. */
151
+ async syncEventDetails(eventId) {
152
+ await this.syncTour(eventId, /* @__PURE__ */ new Date(), true);
153
+ }
154
+ async upsertEvent(tour, previous, now) {
155
+ const source = {
156
+ name: tour.name || "",
157
+ startsOn: tour.startsOn || "",
158
+ endsOn: tour.endsOn || ""
159
+ };
160
+ const sourceHash = hash(source);
161
+ const value = { id: tour.id, ...source, active: true, sourceHash, syncedAt: now };
162
+ if (!previous) {
163
+ await this.ctx.database.create("rina_llevent_event", value);
164
+ return true;
165
+ }
166
+ const changed = previous.sourceHash !== sourceHash || !previous.active;
167
+ await this.ctx.database.set("rina_llevent_event", tour.id, {
168
+ ...source,
169
+ active: true,
170
+ sourceHash,
171
+ syncedAt: now
172
+ });
173
+ return changed;
174
+ }
175
+ shouldRefreshEvent(event, now) {
176
+ if (!event) return true;
177
+ const start = event.startsOn ? /* @__PURE__ */ new Date(`${event.startsOn}T00:00:00+09:00`) : void 0;
178
+ if (!start || Number.isNaN(start.getTime())) return false;
179
+ const days = (start.getTime() - now.getTime()) / DAY;
180
+ const interval = days <= 2 ? 5 : days <= 7 ? 60 : days <= 30 ? 6 * 60 : 24 * 60;
181
+ return now.getTime() - event.syncedAt.getTime() >= interval * 6e4;
182
+ }
183
+ async syncTour(id, now, force) {
184
+ const tour = await this.client.getTour(id);
185
+ if (!tour) throw new Error(`LL-Fans 活动 ${id} 不存在`);
186
+ await this.applyTourDetail(tour, now);
187
+ const performances = await this.ctx.database.get("rina_llevent_performance", { eventId: id });
188
+ const known = new Map(performances.map((performance) => [performance.id, performance]));
189
+ for (const concert of tour.concerts || []) {
190
+ for (const item of concert.performances || []) {
191
+ const previous = known.get(item.id);
192
+ if (!previous || force || this.shouldRefreshPerformance(previous, now)) {
193
+ await this.refreshPerformance(item.id, id, concert.id, item.name || "", now);
194
+ }
195
+ }
196
+ }
197
+ }
198
+ async applyTourDetail(tour, now) {
199
+ const event = (await this.ctx.database.get("rina_llevent_event", { id: tour.id }))[0];
200
+ if (event) {
201
+ await this.ctx.database.set("rina_llevent_event", tour.id, {
202
+ name: tour.name || event.name,
203
+ startsOn: tour.startsOn || "",
204
+ endsOn: tour.endsOn || "",
205
+ active: true,
206
+ syncedAt: now
207
+ });
208
+ }
209
+ for (const concert of tour.concerts || []) {
210
+ const record = {
211
+ id: concert.id,
212
+ eventId: tour.id,
213
+ name: concert.name || "",
214
+ venue: concert.venue?.name || ""
215
+ };
216
+ const current = (await this.ctx.database.get("rina_llevent_concert", { id: concert.id }))[0];
217
+ if (current) {
218
+ const { id: _id, ...update } = record;
219
+ await this.ctx.database.set("rina_llevent_concert", concert.id, update);
220
+ } else await this.ctx.database.create("rina_llevent_concert", record);
221
+ }
222
+ }
223
+ shouldRefreshPerformance(performance, now) {
224
+ const start = performanceStart(performance);
225
+ if (!start) return now.getTime() - performance.syncedAt.getTime() >= 24 * 60 * 6e4;
226
+ const days = (start.getTime() - now.getTime()) / DAY;
227
+ if (days < -1) return false;
228
+ const interval = days <= 2 ? 5 : days <= 7 ? 60 : days <= 30 ? 6 * 60 : 24 * 60;
229
+ return now.getTime() - performance.syncedAt.getTime() >= interval * 6e4;
230
+ }
231
+ async refreshPerformance(id, eventId, concertId, name2, now) {
232
+ const detail = await this.client.getPerformance(id);
233
+ if (!detail) throw new Error(`LL-Fans 场次 ${id} 不存在`);
234
+ await this.persistPerformance(detail, eventId, concertId, name2, now);
235
+ }
236
+ async persistPerformance(detail, eventId, concertId, name2, now) {
237
+ const old = (await this.ctx.database.get("rina_llevent_performance", { id: detail.id }))[0];
238
+ const setlist = normalizeSetlist(detail.setlists);
239
+ const record = {
240
+ id: detail.id,
241
+ eventId,
242
+ concertId,
243
+ name: name2 || old?.name || "",
244
+ date: detail.date || "",
245
+ openTime: detail.openTime || "",
246
+ startTime: detail.startTime || "",
247
+ canceled: !!detail.canceled,
248
+ setlistHash: hash(setlist),
249
+ syncedAt: now,
250
+ setlistCheckedAt: old?.setlistCheckedAt
251
+ };
252
+ if (old) {
253
+ const { id: _id, ...update } = record;
254
+ await this.ctx.database.set("rina_llevent_performance", detail.id, update);
255
+ } else await this.ctx.database.create("rina_llevent_performance", record);
256
+ }
257
+ async refreshSetlist(performance) {
258
+ const now = /* @__PURE__ */ new Date();
259
+ const detail = await this.client.getPerformance(performance.id);
260
+ if (!detail) throw new Error(`LL-Fans 场次 ${performance.id} 不存在`);
261
+ const setlist = normalizeSetlist(detail.setlists);
262
+ await this.persistPerformance(detail, performance.eventId, performance.concertId, performance.name, now);
263
+ await this.ctx.database.set("rina_llevent_performance", performance.id, { setlistCheckedAt: now });
264
+ const refreshed = (await this.ctx.database.get("rina_llevent_performance", { id: performance.id }))[0];
265
+ return refreshed && { performance: refreshed, setlist };
266
+ }
267
+ async upcoming(days = 30) {
268
+ const now = /* @__PURE__ */ new Date();
269
+ const performances = await this.ctx.database.get("rina_llevent_performance", { canceled: false });
270
+ const events = new Map((await this.ctx.database.get("rina_llevent_event", { active: true })).map((event) => [event.id, event]));
271
+ const concerts = new Map((await this.ctx.database.get("rina_llevent_concert", {})).map((concert) => [concert.id, concert]));
272
+ return performances.map((performance) => ({ performance, start: performanceStart(performance), event: events.get(performance.eventId), concert: concerts.get(performance.concertId) })).filter((item) => !!item.start && item.start >= now && item.start.getTime() <= now.getTime() + days * DAY).sort((left, right) => left.start.getTime() - right.start.getTime());
273
+ }
274
+ };
275
+
276
+ // src/formatter.ts
277
+ function formatTime(value) {
278
+ return new Intl.DateTimeFormat("zh-CN", {
279
+ timeZone: "Asia/Tokyo",
280
+ month: "2-digit",
281
+ day: "2-digit",
282
+ hour: "2-digit",
283
+ minute: "2-digit",
284
+ hour12: false
285
+ }).format(value).replace(",", "");
286
+ }
287
+ __name(formatTime, "formatTime");
288
+ function title(event, concert, performance) {
289
+ return [event?.name, concert?.name, performance?.name].filter(Boolean).join(" · ");
290
+ }
291
+ __name(title, "title");
292
+ function formatReminder(event, concert, performance, start, minutes) {
293
+ return [
294
+ `【演出还有 ${minutes} 分钟】`,
295
+ title(event, concert, performance),
296
+ `开演:${formatTime(start)}(日本时间)`,
297
+ performance.openTime ? `开场:${performance.openTime}(日本时间)` : "",
298
+ concert?.venue ? `会场:${concert.venue}` : "",
299
+ canonicalUrl(performance.eventId, performance.concertId, performance.id)
300
+ ].filter(Boolean).join("\n");
301
+ }
302
+ __name(formatReminder, "formatReminder");
303
+ function formatSetlistCaption(event, concert, performance, updated) {
304
+ return [
305
+ updated ? "【歌单更新】" : "【演出歌单】",
306
+ title(event, concert, performance),
307
+ performance.date && performance.startTime ? `开演:${performance.date} ${performance.startTime}(日本时间)` : "",
308
+ canonicalUrl(performance.eventId, performance.concertId, performance.id)
309
+ ].filter(Boolean).join("\n");
310
+ }
311
+ __name(formatSetlistCaption, "formatSetlistCaption");
312
+
313
+ // src/renderer.ts
314
+ var import_koishi_plugin_puppeteer = require("koishi-plugin-puppeteer");
315
+ function escapeHtml(value) {
316
+ return value.replace(/[&<>'"]/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;" })[char]);
317
+ }
318
+ __name(escapeHtml, "escapeHtml");
319
+ async function captureSetlistPage(ctx, url) {
320
+ if (!ctx.puppeteer) throw new Error("未启用 puppeteer 服务,无法截取 LL-Fans 歌单页面");
321
+ const page = await ctx.puppeteer.page();
322
+ try {
323
+ await page.setViewport({ width: 1440, height: 1e3, deviceScaleFactor: 1 });
324
+ await page.goto(url, { waitUntil: "networkidle2", timeout: 6e4 });
325
+ await page.waitForFunction(() => document.body.innerText.includes("セットリスト"), { timeout: 15e3 });
326
+ const main = await page.$("main");
327
+ return await (main || page).screenshot({ type: "png" });
328
+ } finally {
329
+ await page.close();
330
+ }
331
+ }
332
+ __name(captureSetlistPage, "captureSetlistPage");
333
+ async function captureEventDetailPage(ctx, url) {
334
+ if (!ctx.puppeteer) throw new Error("未启用 puppeteer 服务,无法截取 LL-Fans 详情页");
335
+ const page = await ctx.puppeteer.page();
336
+ try {
337
+ await page.setViewport({ width: 1440, height: 1e3, deviceScaleFactor: 1 });
338
+ await page.goto(url, { waitUntil: "networkidle2", timeout: 6e4 });
339
+ await page.waitForSelector("main", { timeout: 15e3 });
340
+ const main = await page.$("main");
341
+ return await (main || page).screenshot({ type: "png" });
342
+ } finally {
343
+ await page.close();
344
+ }
345
+ }
346
+ __name(captureEventDetailPage, "captureEventDetailPage");
347
+ async function renderChoiceList(ctx, title2, lines, instruction = "请在 60 秒内回复序号") {
348
+ if (!ctx.puppeteer) throw new Error("未启用 puppeteer 服务,无法渲染候选列表");
349
+ const page = await ctx.puppeteer.page();
350
+ try {
351
+ await page.setViewport({ width: 1180, height: 900, deviceScaleFactor: 1 });
352
+ const rows = lines.map((line) => `<li>${escapeHtml(line)}</li>`).join("");
353
+ const hint = instruction ? `<p>${escapeHtml(instruction)}</p>` : "";
354
+ await page.setContent(`<!doctype html><html><head><meta charset="utf-8"><style>
355
+ * { box-sizing: border-box; }
356
+ body { margin: 0; background: transparent; font-family: "Noto Sans CJK JP", "Microsoft YaHei", sans-serif; }
357
+ #card { width: 1180px; padding: 32px 38px 34px; color: #f5f1f7; background: linear-gradient(135deg, #29242d, #19171c); border: 2px solid #f200b5; border-radius: 18px; }
358
+ h1 { margin: 0 0 22px; color: #ff6bd4; font-size: 31px; font-weight: 800; }
359
+ p { margin: 0 0 20px; color: #cbc3cc; font-size: 22px; }
360
+ ol { margin: 0; padding-left: 42px; }
361
+ li { padding: 9px 0 9px 8px; font-size: 22px; line-height: 1.42; border-bottom: 1px solid rgba(255,255,255,.12); word-break: break-word; }
362
+ li:last-child { border-bottom: 0; }
363
+ li::marker { color: #ff55c8; font-weight: 800; }
364
+ footer { margin-top: 23px; color: #ff8cdb; font-size: 20px; }
365
+ </style></head><body><main id="card"><h1>${escapeHtml(title2)}</h1>${hint}<ol>${rows}</ol><footer>LL-Fans 演出查询</footer></main></body></html>`);
366
+ const card = await page.$("#card");
367
+ if (!card) throw new Error("候选列表渲染失败");
368
+ return await card.screenshot({ type: "png" });
369
+ } finally {
370
+ await page.close();
371
+ }
372
+ }
373
+ __name(renderChoiceList, "renderChoiceList");
374
+
375
+ // src/commands.ts
376
+ function normalize(value) {
377
+ return value.normalize("NFKC").toLocaleLowerCase().replace(/day\s*[.]?\s*0*(\d+)/g, "d$1").replace(/第\s*0*(\d+)\s*日目/g, "d$1").replace(/[ヶケ]/g, "").replace(/[^a-z0-9\u3040-\u30ff\u3400-\u9fffμ]/g, "");
378
+ }
379
+ __name(normalize, "normalize");
380
+ function tokens(value) {
381
+ return normalize(value).match(/[a-z]+\d*|\d+(?:st|nd|rd|th)?|[\u3040-\u30ff\u3400-\u9fffμ]+/g) || [];
382
+ }
383
+ __name(tokens, "tokens");
384
+ function eventScore(query, event) {
385
+ const source = normalize(event.name);
386
+ const key = normalize(query);
387
+ if (source.includes(key)) return 100 + key.length;
388
+ return tokens(query).filter((token) => source.includes(token)).length;
389
+ }
390
+ __name(eventScore, "eventScore");
391
+ function matchesCandidate(query, candidate) {
392
+ const source = normalize(candidateName(candidate));
393
+ const key = normalize(query);
394
+ return source.includes(key) || tokens(query).every((token) => source.includes(token));
395
+ }
396
+ __name(matchesCandidate, "matchesCandidate");
397
+ async function cachedCandidates(ctx) {
398
+ const [events, concerts, performances] = await Promise.all([
399
+ ctx.database.get("rina_llevent_event", {}),
400
+ ctx.database.get("rina_llevent_concert", {}),
401
+ ctx.database.get("rina_llevent_performance", {})
402
+ ]);
403
+ const eventMap = new Map(events.map((event) => [event.id, event]));
404
+ const concertMap = new Map(concerts.map((concert) => [concert.id, concert]));
405
+ const candidates = performances.map((performance) => ({
406
+ performance,
407
+ event: eventMap.get(performance.eventId),
408
+ concert: concertMap.get(performance.concertId)
409
+ }));
410
+ return { events, candidates };
411
+ }
412
+ __name(cachedCandidates, "cachedCandidates");
413
+ function candidateName(candidate) {
414
+ return [candidate.event?.name, candidate.concert?.name, candidate.performance.name].filter(Boolean).join(" · ");
415
+ }
416
+ __name(candidateName, "candidateName");
417
+ function candidateLine(candidate, index) {
418
+ const time = [candidate.performance.date, candidate.performance.startTime].filter(Boolean).join(" ");
419
+ return `${index + 1}. ${candidateName(candidate)}${time ? `(${time})` : ""}${candidate.performance.canceled ? "(已取消)" : ""}`;
420
+ }
421
+ __name(candidateLine, "candidateLine");
422
+ function eventLine(event, index) {
423
+ const date = [event.startsOn, event.endsOn].filter(Boolean).join(" ~ ");
424
+ return `${index + 1}. ${event.name}${date ? `(${date})` : ""}`;
425
+ }
426
+ __name(eventLine, "eventLine");
427
+ async function choose(ctx, session, values, title2, line) {
428
+ if (values.length === 1) return values[0];
429
+ const lines = values.map(line);
430
+ await session.send(`${title2},请在 60 秒内回复序号。`);
431
+ try {
432
+ await session.send(import_koishi2.h.image(await renderChoiceList(ctx, title2, lines), "image/png"));
433
+ } catch {
434
+ await session.send(lines.join("\n"));
435
+ }
436
+ const choice = await session.prompt((input) => {
437
+ const value = Number(input.content?.trim());
438
+ return Number.isInteger(value) && value >= 1 && value <= values.length ? value : void 0;
439
+ }, { timeout: 6e4 });
440
+ return choice ? values[choice - 1] : void 0;
441
+ }
442
+ __name(choose, "choose");
443
+ function registerCommands(ctx, service) {
444
+ ctx.command("ll演出近期 [days:number]", "查询近期已缓存的 LoveLive! 演出").alias("ll近期演出").action(async ({ session }, days) => {
445
+ const items = await service.upcoming(Math.min(Math.max(days || 30, 1), 365));
446
+ if (!items.length) return "暂无近期已缓存的、具有明确开演时间的演出。";
447
+ const lines = items.slice(0, 20).map(({ event, concert, performance, start }) => [
448
+ new Intl.DateTimeFormat("zh-CN", { timeZone: "Asia/Tokyo", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: false }).format(start),
449
+ [event?.name, concert?.name, performance.name].filter(Boolean).join(" · "),
450
+ performance.canceled ? "(已取消)" : ""
451
+ ].filter(Boolean).join(" ")).join("\n");
452
+ if (!session) return lines;
453
+ const shownDays = Math.min(Math.max(days || 30, 1), 365);
454
+ await session.send(`未来 ${shownDays} 天内有 ${items.length} 个已缓存场次(日本时间)。`);
455
+ try {
456
+ await session.send(import_koishi2.h.image(await renderChoiceList(ctx, `近期演出 · ${shownDays} 天`, lines.split("\n"), ""), "image/png"));
457
+ } catch {
458
+ await session.send(lines);
459
+ }
460
+ });
461
+ ctx.command("ll演出下场", "查询下一场已缓存的 LoveLive! 演出").action(async ({ session }) => {
462
+ const next = (await service.upcoming(365))[0];
463
+ if (!next) return "暂无下一场已缓存的、具有明确开演时间的演出。";
464
+ const sourceUrl = canonicalUrl(next.performance.eventId, next.performance.concertId, next.performance.id);
465
+ const title2 = [next.event?.name, next.concert?.name, next.performance.name].filter(Boolean).join(" · ");
466
+ if (!session) return [title2, sourceUrl].join("\n");
467
+ await session.send(`【下一场演出】
468
+ ${title2}
469
+ ${sourceUrl}`);
470
+ try {
471
+ await session.send(import_koishi2.h.image(await captureEventDetailPage(ctx, sourceUrl), "image/png"));
472
+ } catch (error) {
473
+ return `详情页截图失败:${String(error)}
474
+ ${sourceUrl}`;
475
+ }
476
+ });
477
+ ctx.command("ll歌单 <keyword:text>", "模糊查找活动或场次并截取 LL-Fans 原页面歌单").action(async ({ session }, keyword = "") => {
478
+ const needle = keyword.trim().toLocaleLowerCase();
479
+ if (!needle) return "请输入活动、公演或场次关键词。";
480
+ if (!session) return "请在群聊或私聊中使用 ll歌单,以便选择匹配的场次。";
481
+ let cached = await cachedCandidates(ctx);
482
+ const scoredEvents = cached.events.map((event) => ({ event, score: eventScore(needle, event) })).filter((item) => item.score > 0).sort((left, right) => right.score - left.score || right.event.startsOn.localeCompare(left.event.startsOn));
483
+ const bestScore = scoredEvents[0]?.score || 0;
484
+ const eventMatches = scoredEvents.filter((item) => item.score === bestScore);
485
+ if (eventMatches.length > 20) return `关键词过宽,匹配到 ${eventMatches.length} 个活动;请补充团体、届次或地点,例如“虹咲8th大阪”。`;
486
+ let candidates;
487
+ if (eventMatches.length) {
488
+ const event = await choose(ctx, session, eventMatches.map((item) => item.event), `找到 ${eventMatches.length} 个活动`, eventLine);
489
+ if (!event) return "未收到有效序号,已取消歌单查询。";
490
+ await service.syncEventDetails(event.id);
491
+ cached = await cachedCandidates(ctx);
492
+ const allPerformances = cached.candidates.filter((candidate) => candidate.performance.eventId === event.id);
493
+ candidates = allPerformances.filter((candidate) => matchesCandidate(needle, candidate));
494
+ if (!candidates.length) candidates = allPerformances;
495
+ } else {
496
+ candidates = cached.candidates.filter((candidate) => matchesCandidate(needle, candidate));
497
+ }
498
+ if (!candidates.length) return "未找到匹配场次;可先执行 ll演出同步,或使用更具体的活动名称。";
499
+ if (candidates.length > 20) return `找到 ${candidates.length} 个场次,请补充公演地点或 Day,例如“大阪d1”。`;
500
+ const selected = await choose(ctx, session, candidates, `找到 ${candidates.length} 个场次`, candidateLine);
501
+ if (!selected) return "未收到有效序号,已取消歌单查询。";
502
+ const result = await service.refreshSetlist(selected.performance);
503
+ const sourceUrl = canonicalUrl(selected.performance.eventId, selected.performance.concertId, selected.performance.id);
504
+ if (!result?.setlist.length) return `LL-Fans 尚未收录该场次歌单:
505
+ ${sourceUrl}`;
506
+ const caption = formatSetlistCaption(selected.event, selected.concert, result.performance, false);
507
+ await session.send(caption);
508
+ try {
509
+ const image = await captureSetlistPage(ctx, sourceUrl);
510
+ await session.send(import_koishi2.h.image(image, "image/png"));
511
+ } catch (error) {
512
+ return `歌单已确认,但原页面截图失败:${String(error)}
513
+ ${sourceUrl}`;
514
+ }
515
+ });
516
+ ctx.command("ll演出同步", "立即同步 LL-Fans 活动列表与近期详情").action(async () => {
517
+ await service.sync(true);
518
+ return "LL-Fans 活动列表与近期详情已同步。";
519
+ });
520
+ }
521
+ __name(registerCommands, "registerCommands");
522
+
523
+ // src/graphql.ts
524
+ var ENDPOINT = "https://ll-fans.jp/api/graphql";
525
+ var LIST_QUERY = `query TourListPage($first: Int!, $page: Int!) {
526
+ tours(orderBy: [{column: STARTS_ON, order: DESC}, {column: ID, order: DESC}], first: $first, page: $page) {
527
+ paginatorInfo { hasMorePages total }
528
+ data { id name startsOn endsOn }
529
+ }
530
+ }`;
531
+ var DETAIL_QUERY = `query EventDetailPage($id: ID!) {
532
+ tour(id: $id) {
533
+ id name startsOn endsOn
534
+ concerts(orderBy: [{column: STARTS_ON, order: ASC}]) {
535
+ id name venue { name }
536
+ performances(orderBy: [{column: DATE, order: ASC}, {column: START_TIME, order: ASC}]) { id name }
537
+ }
538
+ }
539
+ }`;
540
+ var PERFORMANCE_QUERY = `query EventDetailPage_PerformanceDetail($id: ID!) {
541
+ performance(id: $id) {
542
+ id canceled date openTime startTime
543
+ setlists(orderBy: [{column: ORDER, order: ASC}, {column: ID, order: ASC}]) {
544
+ id indexPrefix indexNumber contentTypeOther note premiere
545
+ content { __typename ... on Song { id name } ... on CollaborationSong { name } }
546
+ }
547
+ }
548
+ }`;
549
+ var LlFansClient = class {
550
+ constructor(ctx, timeout) {
551
+ this.ctx = ctx;
552
+ this.timeout = timeout;
553
+ }
554
+ static {
555
+ __name(this, "LlFansClient");
556
+ }
557
+ async query(operationName, query, variables) {
558
+ const response = await this.ctx.http.post(ENDPOINT, {
559
+ operationName,
560
+ query,
561
+ variables
562
+ }, {
563
+ timeout: this.timeout,
564
+ headers: { "user-agent": "koishi-plugin-rina-llevents/0.1", accept: "application/json" }
565
+ });
566
+ if (response.errors?.length) throw new Error(response.errors.map((error) => error.message).join("; "));
567
+ if (!response.data) throw new Error(`LL-Fans ${operationName} returned no data`);
568
+ return response.data;
569
+ }
570
+ async listTours() {
571
+ const all = [];
572
+ for (let page = 1; page <= 10; page++) {
573
+ const data = await this.query("TourListPage", LIST_QUERY, { first: 1e3, page });
574
+ all.push(...data.tours.data);
575
+ if (!data.tours.paginatorInfo.hasMorePages) break;
576
+ }
577
+ return all;
578
+ }
579
+ async getTour(id) {
580
+ return (await this.query("EventDetailPage", DETAIL_QUERY, { id })).tour;
581
+ }
582
+ async getPerformance(id) {
583
+ return (await this.query("EventDetailPage_PerformanceDetail", PERFORMANCE_QUERY, { id })).performance;
584
+ }
585
+ };
586
+
587
+ // src/model.ts
588
+ function extendModel(ctx) {
589
+ ctx.model.extend("rina_llevent_event", {
590
+ id: "string",
591
+ name: "string",
592
+ startsOn: "string",
593
+ endsOn: "string",
594
+ active: "boolean",
595
+ sourceHash: "string",
596
+ syncedAt: "timestamp"
597
+ }, { primary: "id" });
598
+ ctx.model.extend("rina_llevent_concert", {
599
+ id: "string",
600
+ eventId: "string",
601
+ name: "string",
602
+ venue: "string"
603
+ }, { primary: "id" });
604
+ ctx.model.extend("rina_llevent_performance", {
605
+ id: "string",
606
+ eventId: "string",
607
+ concertId: "string",
608
+ name: "string",
609
+ date: "string",
610
+ openTime: "string",
611
+ startTime: "string",
612
+ canceled: "boolean",
613
+ setlistHash: "string",
614
+ syncedAt: "timestamp",
615
+ setlistCheckedAt: "timestamp"
616
+ }, { primary: "id" });
617
+ ctx.model.extend("rina_llevent_delivery", {
618
+ id: "string",
619
+ contentHash: "string",
620
+ sentAt: "timestamp"
621
+ }, { primary: "id" });
622
+ }
623
+ __name(extendModel, "extendModel");
624
+
625
+ // src/scheduler.ts
626
+ var import_koishi3 = require("koishi");
627
+ var Scheduler = class {
628
+ constructor(ctx, logger, service, config) {
629
+ this.ctx = ctx;
630
+ this.logger = logger;
631
+ this.service = service;
632
+ this.config = config;
633
+ }
634
+ static {
635
+ __name(this, "Scheduler");
636
+ }
637
+ running = false;
638
+ start() {
639
+ this.ctx.on("ready", async () => {
640
+ if (this.config.syncOnStart && this.activeTargets().length) {
641
+ await this.service.syncIfDue(true).catch((error) => this.logger.warn(`初始活动同步失败:${String(error)}`));
642
+ }
643
+ this.ctx.cron("* * * * *", () => void this.run());
644
+ });
645
+ }
646
+ async run() {
647
+ if (this.running) return;
648
+ this.running = true;
649
+ try {
650
+ if (!this.activeTargets().length) return;
651
+ await this.service.syncIfDue().catch((error) => this.logger.warn(`活动列表同步失败:${String(error)}`));
652
+ await this.sendReminders();
653
+ await this.pollSetlists();
654
+ } finally {
655
+ this.running = false;
656
+ }
657
+ }
658
+ activeTargets() {
659
+ return this.config.targets.filter((target) => target.enabled);
660
+ }
661
+ targetKey(target) {
662
+ return `${target.platform}:${target.selfId}:${target.channelId}`;
663
+ }
664
+ async send(target, content, image) {
665
+ const bot = this.ctx.bots.find((bot2) => bot2.platform === target.platform && bot2.selfId === target.selfId);
666
+ if (!bot) throw new Error(`找不到机器人 ${target.platform}:${target.selfId}`);
667
+ await bot.sendMessage(target.channelId, content);
668
+ if (image) await bot.sendMessage(target.channelId, import_koishi3.h.image(image, "image/png"));
669
+ }
670
+ async sendOnce(target, performanceId, kind, contentHash, content, image) {
671
+ const targetKey = this.targetKey(target);
672
+ const id = `${performanceId}:${targetKey}:${kind}`;
673
+ const old = (await this.ctx.database.get("rina_llevent_delivery", { id }))[0];
674
+ if (old?.contentHash === contentHash) return false;
675
+ await this.send(target, content, image);
676
+ if (old) await this.ctx.database.set("rina_llevent_delivery", id, { contentHash, sentAt: /* @__PURE__ */ new Date() });
677
+ else await this.ctx.database.create("rina_llevent_delivery", { id, contentHash, sentAt: /* @__PURE__ */ new Date() });
678
+ return true;
679
+ }
680
+ async maps() {
681
+ const [events, concerts] = await Promise.all([
682
+ this.ctx.database.get("rina_llevent_event", {}),
683
+ this.ctx.database.get("rina_llevent_concert", {})
684
+ ]);
685
+ return {
686
+ events: new Map(events.map((event) => [event.id, event])),
687
+ concerts: new Map(concerts.map((concert) => [concert.id, concert]))
688
+ };
689
+ }
690
+ async sendReminders() {
691
+ const targets = this.activeTargets();
692
+ if (!targets.length) return;
693
+ const now = /* @__PURE__ */ new Date();
694
+ const performances = await this.ctx.database.get("rina_llevent_performance", { canceled: false });
695
+ const { events, concerts } = await this.maps();
696
+ for (const performance of performances) {
697
+ const start = performanceStart(performance);
698
+ if (!start) continue;
699
+ const due = start.getTime() - this.config.reminderMinutes * 6e4;
700
+ if (now.getTime() < due || now.getTime() >= due + 2 * 6e4) continue;
701
+ const content = formatReminder(events.get(performance.eventId), concerts.get(performance.concertId), performance, start, this.config.reminderMinutes);
702
+ for (const target of targets) {
703
+ try {
704
+ await this.sendOnce(target, performance.id, "reminder", String(due), content);
705
+ } catch (error) {
706
+ this.logger.warn(`发送开演提醒失败:${String(error)}`);
707
+ }
708
+ }
709
+ }
710
+ }
711
+ async pollSetlists() {
712
+ const targets = this.activeTargets();
713
+ if (!targets.length) return;
714
+ const now = /* @__PURE__ */ new Date();
715
+ const performances = await this.ctx.database.get("rina_llevent_performance", { canceled: false });
716
+ const { events, concerts } = await this.maps();
717
+ for (const performance of performances) {
718
+ const start = performanceStart(performance);
719
+ if (!start) continue;
720
+ const pollStart = start.getTime() + this.config.expectedDurationMinutes * 6e4;
721
+ const pollEnd = pollStart + this.config.setlistPollHours * 60 * 6e4;
722
+ const last = performance.setlistCheckedAt?.getTime() || 0;
723
+ if (now.getTime() < pollStart || now.getTime() > pollEnd || now.getTime() - last < this.config.setlistPollIntervalMinutes * 6e4) continue;
724
+ try {
725
+ const oldHash = performance.setlistHash;
726
+ const result = await this.service.refreshSetlist(performance);
727
+ if (!result?.setlist.length) continue;
728
+ const refreshed = result.performance;
729
+ const updated = oldHash !== refreshed.setlistHash && oldHash !== EMPTY_SETLIST_HASH;
730
+ const content = formatSetlistCaption(events.get(refreshed.eventId), concerts.get(refreshed.concertId), refreshed, updated);
731
+ const image = await captureSetlistPage(this.ctx, canonicalUrl(refreshed.eventId, refreshed.concertId, refreshed.id));
732
+ for (const target of targets) {
733
+ await this.sendOnce(target, refreshed.id, updated ? "setlist-update" : "setlist", refreshed.setlistHash, content, image);
734
+ }
735
+ } catch (error) {
736
+ this.logger.warn(`轮询歌单失败(${performance.id}):${String(error)}`);
737
+ }
738
+ }
739
+ }
740
+ };
741
+
742
+ // src/index.ts
743
+ var name = "rina-llevents";
744
+ var inject = { required: ["database", "cron", "http"], optional: ["puppeteer"] };
745
+ var Config2 = Config;
746
+ function apply(ctx, config) {
747
+ extendModel(ctx);
748
+ const logger = ctx.logger(name);
749
+ const service = new LlEventService(ctx, logger, new LlFansClient(ctx, config.requestTimeout), config);
750
+ registerCommands(ctx, service);
751
+ new Scheduler(ctx, logger, service, config).start();
752
+ }
753
+ __name(apply, "apply");
754
+ // Annotate the CommonJS export names for ESM import in node:
755
+ 0 && (module.exports = {
756
+ Config,
757
+ apply,
758
+ inject,
759
+ name
760
+ });
package/lib/model.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { Context } from 'koishi';
2
+ export interface LlEvent {
3
+ id: string;
4
+ name: string;
5
+ startsOn: string;
6
+ endsOn: string;
7
+ active: boolean;
8
+ sourceHash: string;
9
+ syncedAt: Date;
10
+ }
11
+ export interface LlConcert {
12
+ id: string;
13
+ eventId: string;
14
+ name: string;
15
+ venue: string;
16
+ }
17
+ export interface LlPerformance {
18
+ id: string;
19
+ eventId: string;
20
+ concertId: string;
21
+ name: string;
22
+ date: string;
23
+ openTime: string;
24
+ startTime: string;
25
+ canceled: boolean;
26
+ setlistHash: string;
27
+ syncedAt: Date;
28
+ setlistCheckedAt?: Date;
29
+ }
30
+ export interface LlDelivery {
31
+ id: string;
32
+ contentHash: string;
33
+ sentAt: Date;
34
+ }
35
+ declare module 'koishi' {
36
+ interface Tables {
37
+ rina_llevent_event: LlEvent;
38
+ rina_llevent_concert: LlConcert;
39
+ rina_llevent_performance: LlPerformance;
40
+ rina_llevent_delivery: LlDelivery;
41
+ }
42
+ }
43
+ export declare function extendModel(ctx: Context): void;
@@ -0,0 +1,8 @@
1
+ import { Context } from 'koishi';
2
+ import 'koishi-plugin-puppeteer';
3
+ /** Captures LL-Fans' own rendered setlist page, rather than reproducing its layout. */
4
+ export declare function captureSetlistPage(ctx: Context, url: string): Promise<Buffer<ArrayBufferLike>>;
5
+ /** Captures an event detail page even when its setlist has not been published yet. */
6
+ export declare function captureEventDetailPage(ctx: Context, url: string): Promise<Buffer<ArrayBufferLike>>;
7
+ /** Renders a selectable result list into one compact image for mobile chats. */
8
+ export declare function renderChoiceList(ctx: Context, title: string, lines: string[], instruction?: string): Promise<Buffer<ArrayBufferLike>>;
@@ -0,0 +1,20 @@
1
+ import { Context, Logger } from 'koishi';
2
+ import { Config } from './config';
3
+ import { LlEventService } from './service';
4
+ export declare class Scheduler {
5
+ private ctx;
6
+ private logger;
7
+ private service;
8
+ private config;
9
+ private running;
10
+ constructor(ctx: Context, logger: Logger, service: LlEventService, config: Config);
11
+ start(): void;
12
+ private run;
13
+ private activeTargets;
14
+ private targetKey;
15
+ private send;
16
+ private sendOnce;
17
+ private maps;
18
+ private sendReminders;
19
+ private pollSetlists;
20
+ }
@@ -0,0 +1,43 @@
1
+ import { Context, Logger } from 'koishi';
2
+ import { Config } from './config';
3
+ import { LlFansClient } from './graphql';
4
+ import { LlConcert, LlEvent, LlPerformance } from './model';
5
+ export interface StoredSetlistItem {
6
+ index: string;
7
+ name: string;
8
+ note: string;
9
+ premiere: boolean;
10
+ }
11
+ export declare const EMPTY_SETLIST_HASH: string;
12
+ export declare function performanceStart(performance: Pick<LlPerformance, 'date' | 'startTime'>): Date;
13
+ export declare function canonicalUrl(eventId: string, concertId?: string, performanceId?: string): string;
14
+ export declare class LlEventService {
15
+ private ctx;
16
+ private logger;
17
+ private client;
18
+ private config;
19
+ private syncing;
20
+ private lastListSyncAt;
21
+ constructor(ctx: Context, logger: Logger, client: LlFansClient, config: Config);
22
+ syncIfDue(force?: boolean): Promise<boolean>;
23
+ sync(force?: boolean): Promise<void>;
24
+ /** Loads one event regardless of date range. Used when a historical event is queried on demand. */
25
+ syncEventDetails(eventId: string): Promise<void>;
26
+ private upsertEvent;
27
+ private shouldRefreshEvent;
28
+ private syncTour;
29
+ private applyTourDetail;
30
+ private shouldRefreshPerformance;
31
+ private refreshPerformance;
32
+ private persistPerformance;
33
+ refreshSetlist(performance: LlPerformance): Promise<{
34
+ performance: LlPerformance;
35
+ setlist: StoredSetlistItem[];
36
+ }>;
37
+ upcoming(days?: number): Promise<{
38
+ performance: LlPerformance;
39
+ start: Date;
40
+ event: LlEvent | undefined;
41
+ concert: LlConcert | undefined;
42
+ }[]>;
43
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "koishi-plugin-rina-llevents",
3
+ "description": "LoveLive活动信息订阅",
4
+ "version": "0.0.1",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "dist"
10
+ ],
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "chatbot",
14
+ "koishi",
15
+ "plugin"
16
+ ],
17
+ "peerDependencies": {
18
+ "koishi": "^4.18.7"
19
+ },
20
+ "dependencies": {
21
+ "koishi-plugin-cron": "^3.1.0",
22
+ "koishi-plugin-puppeteer": "^3.9.0"
23
+ }
24
+ }
package/readme.md ADDED
@@ -0,0 +1,51 @@
1
+ # koishi-plugin-rina-llevents
2
+
3
+ 基于 LL-Fans 活动数据库的 LoveLive! 演出提醒与演出后歌单推送插件。
4
+
5
+ 插件直接请求 LL-Fans 网页所使用的公开 GraphQL 端点,并以三层数据建档:
6
+
7
+ - 活动:`eventId`,例如 `288`。
8
+ - 公演:`concertId`,例如大阪公演 `427`。
9
+ - 场次:`performanceId`,例如 Day.2 `731`。
10
+
11
+ 因此缓存后的场次可直达:
12
+
13
+ ```text
14
+ https://ll-fans.jp/data/event/288?concert=427&performance=731
15
+ ```
16
+
17
+ ## 行为
18
+
19
+ - 定时轮询活动列表,发现新增、名称或日期变动,及近期一年内的活动详情变动。
20
+ - 仅缓存未来一年内的详情;越接近开演检查越频繁。
21
+ - 在 `performance.date + startTime`(日本时区)前 10 分钟发送一次提醒。
22
+ - 从预计结束时刻开始轮询该场次歌单;首次出现时推送,随后变化时发送更新。
23
+ - 歌单正文不入库;推送和 `ll歌单` 都使用 Puppeteer 截取 LL-Fans 原页面。
24
+ - `performance.canceled` 会阻止提醒和歌单轮询;未来活动从列表消失只标为“待确认”,不会误判为取消。
25
+
26
+ ## 配置示例
27
+
28
+ 在 `koishi.yml` 中启用插件并填入实际机器人与群号:
29
+
30
+ ```yaml
31
+ rina-llevents:example:
32
+ targets:
33
+ - platform: onebot
34
+ selfId: '123456'
35
+ channelId: '987654'
36
+ reminderMinutes: 10
37
+ expectedDurationMinutes: 180
38
+
39
+ puppeteer:example: {}
40
+ ```
41
+
42
+ 没有启用的推送目标时,插件不会自动访问 LL-Fans;可通过 `ll演出同步` 手动建立缓存。
43
+
44
+ ## 指令
45
+
46
+ - `ll演出近期 [天数]`
47
+ - `ll演出下场`
48
+ - `ll歌单 <活动、公演或场次关键词>`(历史活动会按需抓取详情;多结果时回复序号选择)
49
+ - `ll演出同步`
50
+
51
+ LL-Fans 的 GraphQL 端点为网页内部接口,未承诺稳定性。插件会保留本地快照,并在请求失败时记录告警而不清空已有数据。