koishi-plugin-oni-sync-bot 0.3.0 → 0.3.3

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
@@ -101,15 +101,12 @@ async function login(siteConfig) {
101
101
  assert: "user"
102
102
  }
103
103
  });
104
- const customRequestOptions = {
105
- headers: {
106
- "User-Agent": siteConfig.userAgent
107
- }
108
- };
109
- if (siteConfig.uakey) {
110
- customRequestOptions.headers["X-authkey"] = siteConfig.uakey;
104
+ if (siteConfig.name === "bwiki") {
105
+ const cookieString = "SESSDATA=666; Domain=wiki.biligame.com; Path=/oni; HttpOnly; Secure";
106
+ bot.cookieJar.setCookie(cookieString, bot.options.apiUrl, (err) => {
107
+ if (err) console.error("Cookie 注入失败:", err);
108
+ });
111
109
  }
112
- bot.setRequestOptions(customRequestOptions);
113
110
  await bot.login();
114
111
  logger.info(`✅ 成功登录 ${siteConfig.name}`);
115
112
  return bot;
@@ -127,13 +124,12 @@ function getSitesConfig(config) {
127
124
  password: config.ggPassword,
128
125
  userAgent
129
126
  },
130
- huiji: {
131
- name: "灰机wiki",
132
- api: "https://oni.huijiwiki.com/api.php",
133
- username: config.huijiUsername,
134
- password: config.huijiPassword,
135
- userAgent,
136
- uakey: config.huijiUAKey
127
+ bwiki: {
128
+ name: "bwiki",
129
+ api: "https://wiki.biligame.com/oni/api.php",
130
+ username: config.bwikiusername,
131
+ password: config.bwikipassword,
132
+ userAgent
137
133
  }
138
134
  };
139
135
  }
@@ -226,8 +222,8 @@ async function syncSingleImage(sourceBot, targetBot, fileName, config) {
226
222
  url: targetBot.options.apiUrl,
227
223
  data: form,
228
224
  headers: {
229
- ...form.getHeaders(),
230
- "X-authkey": `${getSitesConfig(config).huiji.uakey}`
225
+ ...form.getHeaders()
226
+ // "X-authkey": `${getSitesConfig(config).huiji.uakey}`,
231
227
  }
232
228
  });
233
229
  const responseData = rawResponse.data;
@@ -759,15 +755,13 @@ var name = "oni-sync-bot";
759
755
  var inject = ["console", "database", "server", "cron"];
760
756
  var logBuffer = [];
761
757
  var Config = import_koishi5.Schema.object({
762
- ggUsername: import_koishi5.Schema.string().description("WIKIGG 用户名").default("${{ env.ggUsername }}"),
763
- ggPassword: import_koishi5.Schema.string().description("WIKIGG 密码").default("${{ env.ggPassword }}"),
764
- huijiUsername: import_koishi5.Schema.string().description("灰机wiki 用户名").default("${{ env.huijiUsername }}"),
765
- huijiPassword: import_koishi5.Schema.string().description("灰机wiki 密码").default("${{ env.huijiPassword }}"),
766
- huijiUAKey: import_koishi5.Schema.string().description("灰机wiki UAKey").default("${{ env.huijiUAKey }}"),
758
+ ggUsername: import_koishi5.Schema.string().description("WIKIGG 用户名").default("1"),
759
+ ggPassword: import_koishi5.Schema.string().description("WIKIGG 密码").default("1"),
760
+ bwikiusername: import_koishi5.Schema.string().description("bwiki用户名").default("1"),
761
+ bwikipassword: import_koishi5.Schema.string().description("bwiki密码").default("1"),
767
762
  domain: import_koishi5.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip"),
768
763
  main_site: import_koishi5.Schema.string().description("主站域名(必填,如:oxygennotincluded.wiki.gg)").default("oxygennotincluded.wiki.gg/zh"),
769
764
  bwiki_site: import_koishi5.Schema.string().description("镜像站域名(必填,如:wiki.biligame.com)").default("wiki.biligame.com/oni"),
770
- huiji_site: import_koishi5.Schema.string().description("灰机wiki域名(必填,如:oni.huijiwiki.com)").default("oni.huijiwiki.com/wiki/"),
771
765
  logsUrl: import_koishi5.Schema.string().description("日志查看地址").default("https://klei.vip/onilogs")
772
766
  });
773
767
  var PublicLogProvider = class extends import_plugin_console.DataService {
@@ -784,7 +778,7 @@ var PublicLogProvider = class extends import_plugin_console.DataService {
784
778
  function apply(ctx, config) {
785
779
  const log = ctx.logger("oni-sync");
786
780
  let ggbot;
787
- let huijibot;
781
+ let bwikibot;
788
782
  ctx.inject(["console"], (ctx2) => {
789
783
  ctx2.console.addEntry({
790
784
  dev: (0, import_path.resolve)(__dirname, "../client/index.ts"),
@@ -838,41 +832,30 @@ function apply(ctx, config) {
838
832
  )}`;
839
833
  router.redirect(targetUrl);
840
834
  });
841
- ctx.server.get("/hj/:id", async (router) => {
842
- const pageId = Number(router.params.id);
843
- if (isNaN(pageId)) return router.body = "❌ 无效的页面ID,必须为数字!";
844
- const [page] = await ctx.database.get("wikipages", { id: pageId });
845
- if (!page)
846
- return router.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
847
- const targetUrl = `https://${config.huiji_site}/${encodeURIComponent(
848
- page.title
849
- )}`;
850
- router.redirect(targetUrl);
851
- });
852
835
  ctx.on("ready", async () => {
853
836
  logger.info("初始化中...");
854
837
  const sitesConfig = getSitesConfig(config);
855
838
  ggbot = await login(sitesConfig.gg);
856
- huijibot = await login(sitesConfig.huiji);
857
- if (ggbot.login && huijibot.login) {
839
+ bwikibot = await login(sitesConfig.bwiki);
840
+ if (ggbot.login && bwikibot.login) {
858
841
  logger.info("登录成功,插件已准备就绪");
859
842
  } else {
860
843
  logger.error("登录失败,请检查配置");
861
844
  }
862
845
  ctx.cron("15 * * * *", async () => {
863
- await incrementalUpdate(ggbot, huijibot, config);
846
+ await incrementalUpdate(ggbot, bwikibot, config);
864
847
  });
865
848
  ctx.cron("30 8 * * 4", async () => {
866
- await syncPages(ggbot, huijibot).then(() => {
867
- logger.info("自动任务:尝试同步所有页面,从 WIKIGG 到 灰机wiki");
849
+ await syncPages(ggbot, bwikibot).then(() => {
850
+ logger.info("自动任务:尝试同步所有页面,从 WIKIGG 到 bwiki");
868
851
  }).catch((err) => {
869
852
  logger.error(`同步所有页面失败`);
870
853
  log.error(`,错误信息:${err}`);
871
854
  });
872
855
  });
873
856
  ctx.cron("30 8 * * 3", async () => {
874
- await syncAllImages(ggbot, huijibot, config).then(() => {
875
- logger.info("自动任务:尝试同步所有图片,从 WIKIGG 到 灰机wiki");
857
+ await syncAllImages(ggbot, bwikibot, config).then(() => {
858
+ logger.info("自动任务:尝试同步所有图片,从 WIKIGG 到 bwiki");
876
859
  }).catch((err) => {
877
860
  logger.error(`同步所有图片失败`);
878
861
  log.error(`,错误信息:${err}`);
@@ -880,7 +863,7 @@ function apply(ctx, config) {
880
863
  });
881
864
  });
882
865
  ctx.command("sync <pageTitle:string>", "同步指定页面", { authority: 2 }).action(async ({ session }, pageTitle) => {
883
- await syncSinglePage(ggbot, huijibot, pageTitle, "sync-bot").then(() => {
866
+ await syncSinglePage(ggbot, bwikibot, pageTitle, "sync-bot").then(() => {
884
867
  session.send(
885
868
  `✅ 已尝试同步页面:${pageTitle},请前往控制台查看:${config.logsUrl}`
886
869
  );
@@ -895,7 +878,7 @@ function apply(ctx, config) {
895
878
  session.send(
896
879
  `🚀 获取3h内的编辑并尝试更新,任务耗时可能较长,请前往控制台查看日志:${config.logsUrl}`
897
880
  );
898
- await incrementalUpdate(ggbot, huijibot, config).then(() => {
881
+ await incrementalUpdate(ggbot, bwikibot, config).then(() => {
899
882
  session.send(
900
883
  `✅ 已尝试获取三小时前的编辑并同步,请前往控制台查看:${config.logsUrl}`
901
884
  );
@@ -910,7 +893,7 @@ function apply(ctx, config) {
910
893
  session.send(
911
894
  `🚀 开始同步所有页面,任务耗时较长,请前往控制台查看日志:${config.logsUrl}`
912
895
  );
913
- await syncPages(ggbot, huijibot).then(() => {
896
+ await syncPages(ggbot, bwikibot).then(() => {
914
897
  session.send(
915
898
  `✅ 已尝试同步所有页面,请前往控制台查看:${config.logsUrl}`
916
899
  );
@@ -925,7 +908,7 @@ function apply(ctx, config) {
925
908
  authority: 2
926
909
  }).action(async ({ session }, moduleTitle) => {
927
910
  await session.send(`✅ 同步中,请前往控制台查看:${config.logsUrl}`);
928
- await syncSingleModule(ggbot, huijibot, moduleTitle, "sync-bot").then(() => {
911
+ await syncSingleModule(ggbot, bwikibot, moduleTitle, "sync-bot").then(() => {
929
912
  session.send(
930
913
  `✅ 已尝试同步模块:${moduleTitle},请前往控制台查看:${config.logsUrl}`
931
914
  );
@@ -938,7 +921,7 @@ function apply(ctx, config) {
938
921
  await session.send(
939
922
  `🚀 开始同步所有模块,任务耗时较长,请前往控制台查看:${config.logsUrl}`
940
923
  );
941
- await syncModules(ggbot, huijibot).then(() => {
924
+ await syncModules(ggbot, bwikibot).then(() => {
942
925
  session.send(
943
926
  `✅ 已尝试同步所有模块,请前往控制台查看:${config.logsUrl}`
944
927
  );
@@ -955,7 +938,7 @@ function apply(ctx, config) {
955
938
  );
956
939
  await syncSingleImage(
957
940
  ggbot,
958
- huijibot,
941
+ bwikibot,
959
942
  `${imgTitle.startsWith("File:") ? "" : "File:"}${imgTitle}`,
960
943
  config
961
944
  ).then(() => {
@@ -969,7 +952,7 @@ function apply(ctx, config) {
969
952
  session.send(
970
953
  `🚀 开始同步所有图片,任务耗时较长,请前往控制台查看:${config.logsUrl}`
971
954
  );
972
- await syncAllImages(ggbot, huijibot, config).then(() => {
955
+ await syncAllImages(ggbot, bwikibot, config).then(() => {
973
956
  session.send(
974
957
  `✅ 已尝试同步所有图片,请前往控制台查看:${config.logsUrl}`
975
958
  );
@@ -999,11 +982,7 @@ bwiki: https://${config.domain}/hj/88888888`;
999
982
  return `✅ 精准匹配成功
1000
983
  原站点: https://${config.domain}/gg/${id2}
1001
984
 
1002
- bwiki: https://${config.domain}/bw/${id2}
1003
-
1004
- 灰机:https://${config.domain}/hj/${id2}
1005
-
1006
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
985
+ bwiki: https://${config.domain}/bw/${id2}`;
1007
986
  }
1008
987
  const preciseFullPinyinRes = await ctx.database.get("wikipages", {
1009
988
  pinyin_full: queryKey
@@ -1013,11 +992,7 @@ bwiki: https://${config.domain}/bw/${id2}
1013
992
  return `✅ 拼音精准匹配成功(${queryKey} → ${title})
1014
993
  原站点: https://${config.domain}/gg/${id2}
1015
994
 
1016
- bwiki: https://${config.domain}/bw/${id2}
1017
-
1018
- 灰机:https://${config.domain}/hj/${id2}
1019
-
1020
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
995
+ bwiki: https://${config.domain}/bw/${id2}`;
1021
996
  }
1022
997
  const preciseFirstPinyinRes = await ctx.database.get("wikipages", {
1023
998
  pinyin_first: queryKey
@@ -1027,11 +1002,7 @@ bwiki: https://${config.domain}/bw/${id2}
1027
1002
  return `✅ 首字母精准匹配成功(${queryKey} → ${title})
1028
1003
  原站点: https://${config.domain}/gg/${id2}
1029
1004
 
1030
- bwiki: https://${config.domain}/bw/${id2}
1031
-
1032
- 灰机:https://${config.domain}/hj/${id2}
1033
-
1034
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护 `;
1005
+ bwiki: https://${config.domain}/bw/${id2} `;
1035
1006
  }
1036
1007
  const allPages = await ctx.database.get("wikipages", {});
1037
1008
  if (allPages.length === 0) {
@@ -1086,11 +1057,7 @@ bwiki: https://${config.domain}/bw/${id2}
1086
1057
  return `✅ 选择成功
1087
1058
  原站点: https://${config.domain}/gg/${id}
1088
1059
 
1089
- bwiki: https://${config.domain}/bw/${id}
1090
-
1091
- 灰机:https://${config.domain}/hj/${id}
1092
-
1093
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
1060
+ bwiki: https://${config.domain}/bw/${id}`;
1094
1061
  });
1095
1062
  ctx.command("update", "更新本地页面缓存(主站)", { authority: 2 }).action(async ({ session }) => {
1096
1063
  await session.execute("update.status");
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.3.0",
4
+ "version": "0.3.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -1,14 +0,0 @@
1
- import { Config } from "../index";
2
- export interface ISiteConfig {
3
- name: string;
4
- api: string;
5
- username: string;
6
- password: string;
7
- userAgent: string;
8
- }
9
- interface ISitesConfig {
10
- gg: ISiteConfig;
11
- bwiki: ISiteConfig;
12
- }
13
- export declare function getSitesConfig(config: Config): ISitesConfig;
14
- export {};
package/lib/index.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import { Context, Logger, Schema } from "koishi";
2
- export declare const name = "oni-sync-bot";
3
- export declare const inject: string[];
4
- declare module "@koishijs/console" {
5
- namespace Console {
6
- interface Services {
7
- onilogs: DataService<Logger.Record[]>;
8
- }
9
- }
10
- }
11
- declare module "koishi" {
12
- interface Tables {
13
- wikipages: WikiPages;
14
- }
15
- }
16
- export interface WikiPages {
17
- id: number;
18
- title: string;
19
- pinyin_full: string;
20
- pinyin_first: string;
21
- }
22
- export interface Config {
23
- ggUsername: string;
24
- ggPassword: string;
25
- bwikiusername: string;
26
- bwikipassword: string;
27
- domain: string;
28
- main_site: string;
29
- bwiki_site: string;
30
- logsUrl: string;
31
- }
32
- export declare const Config: Schema<Config>;
33
- export declare function apply(ctx: Context, config: Config): void;