koishi-plugin-oni-sync-bot 0.7.0 → 0.7.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.
package/lib/index.js CHANGED
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(src_exports);
38
38
  var import_koishi11 = require("koishi");
39
+ var import_path = require("path");
39
40
 
40
41
  // src/services/wikiBotService.ts
41
42
  var import_koishi2 = require("koishi");
@@ -275,23 +276,76 @@ var WikiBotService = class _WikiBotService extends import_koishi2.Service {
275
276
  }
276
277
  return { gg: ggSuccess, bwiki: bwikiSuccess };
277
278
  }
279
+ async reloginSite(site) {
280
+ const sitesConfig = this.getSitesConfig();
281
+ const siteConfig = site === "gg" ? sitesConfig.gg : sitesConfig.bwiki;
282
+ try {
283
+ const bot = await this.loginWithRetry(siteConfig);
284
+ if (site === "gg") {
285
+ this.ggbot = bot;
286
+ } else {
287
+ this.bwikibot = bot;
288
+ }
289
+ logger.info(`✅ ${siteConfig.name} 自动重新登录成功`);
290
+ } catch (error) {
291
+ const errorMsg = getErrorMessage(error);
292
+ if (site === "gg") {
293
+ this.ggbot = null;
294
+ } else {
295
+ this.bwikibot = null;
296
+ }
297
+ logger.error(`❌ ${siteConfig.name} 自动重新登录失败`, errorMsg);
298
+ throw error;
299
+ }
300
+ }
278
301
  isGGBotReady() {
279
302
  return this.ggbot !== null;
280
303
  }
281
304
  isBWikiBotReady() {
282
305
  return this.bwikibot !== null;
283
306
  }
307
+ createBotProxy(bot, site) {
308
+ const self = this;
309
+ return new Proxy(bot, {
310
+ get(target, prop) {
311
+ const originalMethod = target[prop];
312
+ if (typeof originalMethod !== "function") {
313
+ return originalMethod;
314
+ }
315
+ return async function(...args) {
316
+ try {
317
+ return await originalMethod.apply(target, args);
318
+ } catch (error) {
319
+ if (error.code === "assertuserfailed") {
320
+ logger.warn(
321
+ `检测到 ${site === "gg" ? "WIKIGG" : "bwiki"} 登录过期,正在自动重新登录...`
322
+ );
323
+ await self.reloginSite(site);
324
+ const newBot = site === "gg" ? self.ggbot : self.bwikibot;
325
+ if (!newBot) {
326
+ throw new Error(
327
+ `${site === "gg" ? "WIKIGG" : "bwiki"} 自动重新登录失败`
328
+ );
329
+ }
330
+ return await newBot[prop].apply(newBot, args);
331
+ }
332
+ throw error;
333
+ }
334
+ };
335
+ }
336
+ });
337
+ }
284
338
  getGGBot() {
285
339
  if (!this.ggbot) {
286
340
  throw new Error("WIKIGG bot 尚未就绪,请检查登录配置或查看日志");
287
341
  }
288
- return this.ggbot;
342
+ return this.createBotProxy(this.ggbot, "gg");
289
343
  }
290
344
  getBWikiBot() {
291
345
  if (!this.bwikibot) {
292
346
  throw new Error("bwiki bot 尚未就绪,请检查登录配置或查看日志");
293
347
  }
294
- return this.bwikibot;
348
+ return this.createBotProxy(this.bwikibot, "bwiki");
295
349
  }
296
350
  };
297
351
  ((WikiBotService2) => {
@@ -306,7 +360,6 @@ var WikiBotService = class _WikiBotService extends import_koishi2.Service {
306
360
  // src/plugins/consoleLogProvider.ts
307
361
  var import_koishi3 = require("koishi");
308
362
  var import_plugin_console = require("@koishijs/plugin-console");
309
- var import_path = require("path");
310
363
  var logBuffer = [];
311
364
  var PublicLogProvider = class extends import_plugin_console.DataService {
312
365
  static {
@@ -325,10 +378,6 @@ var ConsoleLogProvider = class {
325
378
  }
326
379
  static inject = ["console"];
327
380
  constructor(ctx) {
328
- ctx.console.addEntry({
329
- dev: (0, import_path.resolve)(__dirname, "../../client/index.ts"),
330
- prod: (0, import_path.resolve)(__dirname, "../../dist")
331
- });
332
381
  ctx.plugin(PublicLogProvider);
333
382
  const target = {
334
383
  colors: 0,
@@ -1591,6 +1640,12 @@ function apply(ctx, config) {
1591
1640
  ctx.plugin(SyncCommands, config);
1592
1641
  ctx.plugin(QueryCommands, config);
1593
1642
  ctx.plugin(UpdateCommands, config);
1643
+ ctx.inject(["console"], (ctx2) => {
1644
+ ctx2.console.addEntry({
1645
+ dev: (0, import_path.resolve)(__dirname, "../client/index.ts"),
1646
+ prod: (0, import_path.resolve)(__dirname, "../dist")
1647
+ });
1648
+ });
1594
1649
  }
1595
1650
  __name(apply, "apply");
1596
1651
  // Annotate the CommonJS export names for ESM import in node:
@@ -32,8 +32,10 @@ export declare class WikiBotService extends Service {
32
32
  gg: boolean;
33
33
  bwiki: boolean;
34
34
  }>;
35
+ private reloginSite;
35
36
  isGGBotReady(): boolean;
36
37
  isBWikiBotReady(): boolean;
38
+ private createBotProxy;
37
39
  getGGBot(): Mwn;
38
40
  getBWikiBot(): Mwn;
39
41
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-oni-sync-bot",
3
3
  "description": "缺氧Wiki站镜像点同步-测试",
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [