koishi-plugin-oni-sync-bot 0.2.4 → 0.3.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
@@ -42,6 +42,7 @@ var import_plugin_console = require("@koishijs/plugin-console");
42
42
 
43
43
  // src/utils/login.ts
44
44
  var import_mwn = require("mwn");
45
+ var import_tough_cookie = require("tough-cookie");
45
46
 
46
47
  // src/utils/tools.ts
47
48
  var import_koishi = require("koishi");
@@ -101,15 +102,19 @@ async function login(siteConfig) {
101
102
  assert: "user"
102
103
  }
103
104
  });
104
- const customRequestOptions = {
105
- headers: {
106
- "User-Agent": siteConfig.userAgent
107
- }
108
- };
109
- if (siteConfig.uakey) {
110
- customRequestOptions.headers["X-authkey"] = siteConfig.uakey;
105
+ if (siteConfig.name === "bwiki") {
106
+ const sessdataCookie = new import_tough_cookie.Cookie({
107
+ key: "SESSDATA",
108
+ value: "666",
109
+ domain: "wiki.biligame.com",
110
+ path: "/oni",
111
+ httpOnly: true,
112
+ secure: true
113
+ });
114
+ bot.cookieJar.setCookie(sessdataCookie, bot.options.apiUrl, (err) => {
115
+ if (err) console.error("Cookie 注入失败:", err);
116
+ });
111
117
  }
112
- bot.setRequestOptions(customRequestOptions);
113
118
  await bot.login();
114
119
  logger.info(`✅ 成功登录 ${siteConfig.name}`);
115
120
  return bot;
@@ -127,13 +132,12 @@ function getSitesConfig(config) {
127
132
  password: config.ggPassword,
128
133
  userAgent
129
134
  },
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
135
+ bwiki: {
136
+ name: "bwiki",
137
+ api: "https://wiki.biligame.com/oni/api.php",
138
+ username: config.bwikiusername,
139
+ password: config.bwikipassword,
140
+ userAgent
137
141
  }
138
142
  };
139
143
  }
@@ -226,8 +230,8 @@ async function syncSingleImage(sourceBot, targetBot, fileName, config) {
226
230
  url: targetBot.options.apiUrl,
227
231
  data: form,
228
232
  headers: {
229
- ...form.getHeaders(),
230
- "X-authkey": `${getSitesConfig(config).huiji.uakey}`
233
+ ...form.getHeaders()
234
+ // "X-authkey": `${getSitesConfig(config).huiji.uakey}`,
231
235
  }
232
236
  });
233
237
  const responseData = rawResponse.data;
@@ -759,15 +763,13 @@ var name = "oni-sync-bot";
759
763
  var inject = ["console", "database", "server", "cron"];
760
764
  var logBuffer = [];
761
765
  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 }}"),
766
+ ggUsername: import_koishi5.Schema.string().description("WIKIGG 用户名").default("1"),
767
+ ggPassword: import_koishi5.Schema.string().description("WIKIGG 密码").default("1"),
768
+ bwikiusername: import_koishi5.Schema.string().description("bwiki用户名").default("1"),
769
+ bwikipassword: import_koishi5.Schema.string().description("bwiki密码").default("1"),
767
770
  domain: import_koishi5.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip"),
768
771
  main_site: import_koishi5.Schema.string().description("主站域名(必填,如:oxygennotincluded.wiki.gg)").default("oxygennotincluded.wiki.gg/zh"),
769
772
  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
773
  logsUrl: import_koishi5.Schema.string().description("日志查看地址").default("https://klei.vip/onilogs")
772
774
  });
773
775
  var PublicLogProvider = class extends import_plugin_console.DataService {
@@ -784,7 +786,7 @@ var PublicLogProvider = class extends import_plugin_console.DataService {
784
786
  function apply(ctx, config) {
785
787
  const log = ctx.logger("oni-sync");
786
788
  let ggbot;
787
- let huijibot;
789
+ let bwikibot;
788
790
  ctx.inject(["console"], (ctx2) => {
789
791
  ctx2.console.addEntry({
790
792
  dev: (0, import_path.resolve)(__dirname, "../client/index.ts"),
@@ -838,41 +840,30 @@ function apply(ctx, config) {
838
840
  )}`;
839
841
  router.redirect(targetUrl);
840
842
  });
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
843
  ctx.on("ready", async () => {
853
844
  logger.info("初始化中...");
854
845
  const sitesConfig = getSitesConfig(config);
855
846
  ggbot = await login(sitesConfig.gg);
856
- huijibot = await login(sitesConfig.huiji);
857
- if (ggbot.login && huijibot.login) {
847
+ bwikibot = await login(sitesConfig.bwiki);
848
+ if (ggbot.login && bwikibot.login) {
858
849
  logger.info("登录成功,插件已准备就绪");
859
850
  } else {
860
851
  logger.error("登录失败,请检查配置");
861
852
  }
862
853
  ctx.cron("15 * * * *", async () => {
863
- await incrementalUpdate(ggbot, huijibot, config);
854
+ await incrementalUpdate(ggbot, bwikibot, config);
864
855
  });
865
856
  ctx.cron("30 8 * * 4", async () => {
866
- await syncPages(ggbot, huijibot).then(() => {
867
- logger.info("自动任务:尝试同步所有页面,从 WIKIGG 到 灰机wiki");
857
+ await syncPages(ggbot, bwikibot).then(() => {
858
+ logger.info("自动任务:尝试同步所有页面,从 WIKIGG 到 bwiki");
868
859
  }).catch((err) => {
869
860
  logger.error(`同步所有页面失败`);
870
861
  log.error(`,错误信息:${err}`);
871
862
  });
872
863
  });
873
864
  ctx.cron("30 8 * * 3", async () => {
874
- await syncAllImages(ggbot, huijibot, config).then(() => {
875
- logger.info("自动任务:尝试同步所有图片,从 WIKIGG 到 灰机wiki");
865
+ await syncAllImages(ggbot, bwikibot, config).then(() => {
866
+ logger.info("自动任务:尝试同步所有图片,从 WIKIGG 到 bwiki");
876
867
  }).catch((err) => {
877
868
  logger.error(`同步所有图片失败`);
878
869
  log.error(`,错误信息:${err}`);
@@ -880,7 +871,7 @@ function apply(ctx, config) {
880
871
  });
881
872
  });
882
873
  ctx.command("sync <pageTitle:string>", "同步指定页面", { authority: 2 }).action(async ({ session }, pageTitle) => {
883
- await syncSinglePage(ggbot, huijibot, pageTitle, "sync-bot").then(() => {
874
+ await syncSinglePage(ggbot, bwikibot, pageTitle, "sync-bot").then(() => {
884
875
  session.send(
885
876
  `✅ 已尝试同步页面:${pageTitle},请前往控制台查看:${config.logsUrl}`
886
877
  );
@@ -895,7 +886,7 @@ function apply(ctx, config) {
895
886
  session.send(
896
887
  `🚀 获取3h内的编辑并尝试更新,任务耗时可能较长,请前往控制台查看日志:${config.logsUrl}`
897
888
  );
898
- await incrementalUpdate(ggbot, huijibot, config).then(() => {
889
+ await incrementalUpdate(ggbot, bwikibot, config).then(() => {
899
890
  session.send(
900
891
  `✅ 已尝试获取三小时前的编辑并同步,请前往控制台查看:${config.logsUrl}`
901
892
  );
@@ -910,7 +901,7 @@ function apply(ctx, config) {
910
901
  session.send(
911
902
  `🚀 开始同步所有页面,任务耗时较长,请前往控制台查看日志:${config.logsUrl}`
912
903
  );
913
- await syncPages(ggbot, huijibot).then(() => {
904
+ await syncPages(ggbot, bwikibot).then(() => {
914
905
  session.send(
915
906
  `✅ 已尝试同步所有页面,请前往控制台查看:${config.logsUrl}`
916
907
  );
@@ -925,7 +916,7 @@ function apply(ctx, config) {
925
916
  authority: 2
926
917
  }).action(async ({ session }, moduleTitle) => {
927
918
  await session.send(`✅ 同步中,请前往控制台查看:${config.logsUrl}`);
928
- await syncSingleModule(ggbot, huijibot, moduleTitle, "sync-bot").then(() => {
919
+ await syncSingleModule(ggbot, bwikibot, moduleTitle, "sync-bot").then(() => {
929
920
  session.send(
930
921
  `✅ 已尝试同步模块:${moduleTitle},请前往控制台查看:${config.logsUrl}`
931
922
  );
@@ -938,7 +929,7 @@ function apply(ctx, config) {
938
929
  await session.send(
939
930
  `🚀 开始同步所有模块,任务耗时较长,请前往控制台查看:${config.logsUrl}`
940
931
  );
941
- await syncModules(ggbot, huijibot).then(() => {
932
+ await syncModules(ggbot, bwikibot).then(() => {
942
933
  session.send(
943
934
  `✅ 已尝试同步所有模块,请前往控制台查看:${config.logsUrl}`
944
935
  );
@@ -955,7 +946,7 @@ function apply(ctx, config) {
955
946
  );
956
947
  await syncSingleImage(
957
948
  ggbot,
958
- huijibot,
949
+ bwikibot,
959
950
  `${imgTitle.startsWith("File:") ? "" : "File:"}${imgTitle}`,
960
951
  config
961
952
  ).then(() => {
@@ -969,7 +960,7 @@ function apply(ctx, config) {
969
960
  session.send(
970
961
  `🚀 开始同步所有图片,任务耗时较长,请前往控制台查看:${config.logsUrl}`
971
962
  );
972
- await syncAllImages(ggbot, huijibot, config).then(() => {
963
+ await syncAllImages(ggbot, bwikibot, config).then(() => {
973
964
  session.send(
974
965
  `✅ 已尝试同步所有图片,请前往控制台查看:${config.logsUrl}`
975
966
  );
@@ -999,11 +990,7 @@ bwiki: https://${config.domain}/hj/88888888`;
999
990
  return `✅ 精准匹配成功
1000
991
  原站点: https://${config.domain}/gg/${id2}
1001
992
 
1002
- bwiki: https://${config.domain}/bw/${id2}
1003
-
1004
- 灰机:https://${config.domain}/hj/${id2}
1005
-
1006
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
993
+ bwiki: https://${config.domain}/bw/${id2}`;
1007
994
  }
1008
995
  const preciseFullPinyinRes = await ctx.database.get("wikipages", {
1009
996
  pinyin_full: queryKey
@@ -1013,11 +1000,7 @@ bwiki: https://${config.domain}/bw/${id2}
1013
1000
  return `✅ 拼音精准匹配成功(${queryKey} → ${title})
1014
1001
  原站点: https://${config.domain}/gg/${id2}
1015
1002
 
1016
- bwiki: https://${config.domain}/bw/${id2}
1017
-
1018
- 灰机:https://${config.domain}/hj/${id2}
1019
-
1020
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
1003
+ bwiki: https://${config.domain}/bw/${id2}`;
1021
1004
  }
1022
1005
  const preciseFirstPinyinRes = await ctx.database.get("wikipages", {
1023
1006
  pinyin_first: queryKey
@@ -1027,11 +1010,7 @@ bwiki: https://${config.domain}/bw/${id2}
1027
1010
  return `✅ 首字母精准匹配成功(${queryKey} → ${title})
1028
1011
  原站点: https://${config.domain}/gg/${id2}
1029
1012
 
1030
- bwiki: https://${config.domain}/bw/${id2}
1031
-
1032
- 灰机:https://${config.domain}/hj/${id2}
1033
-
1034
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护 `;
1013
+ bwiki: https://${config.domain}/bw/${id2} `;
1035
1014
  }
1036
1015
  const allPages = await ctx.database.get("wikipages", {});
1037
1016
  if (allPages.length === 0) {
@@ -1086,11 +1065,7 @@ bwiki: https://${config.domain}/bw/${id2}
1086
1065
  return `✅ 选择成功
1087
1066
  原站点: https://${config.domain}/gg/${id}
1088
1067
 
1089
- bwiki: https://${config.domain}/bw/${id}
1090
-
1091
- 灰机:https://${config.domain}/hj/${id}
1092
-
1093
- 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
1068
+ bwiki: https://${config.domain}/bw/${id}`;
1094
1069
  });
1095
1070
  ctx.command("update", "更新本地页面缓存(主站)", { authority: 2 }).action(async ({ session }) => {
1096
1071
  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.2.4",
4
+ "version": "0.3.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -15,11 +15,11 @@
15
15
  "plugin"
16
16
  ],
17
17
  "devDependencies": {
18
- "@koishijs/client": "^5.30.4"
18
+ "@koishijs/client": "^5.30.11"
19
19
  },
20
20
  "peerDependencies": {
21
- "@koishijs/plugin-console": "^5.30.4",
22
- "koishi": "^4.18.7"
21
+ "@koishijs/plugin-console": "^5.30.11",
22
+ "koishi": "^4.18.11"
23
23
  },
24
24
  "dependencies": {
25
25
  "@types/node-fetch": "^2.6.13",
@@ -27,6 +27,7 @@
27
27
  "koishi-plugin-cron": "^3.1.0",
28
28
  "mwn": "^3.0.1",
29
29
  "node-fetch": "^3.3.2",
30
- "pinyin-pro": "^3.28.0"
30
+ "pinyin-pro": "^3.28.0",
31
+ "tough-cookie": "^6.0.1"
31
32
  }
32
33
  }
package/lib/index.d.ts DELETED
@@ -1,35 +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
- huijiUsername: string;
26
- huijiPassword: string;
27
- huijiUAKey: string;
28
- domain: string;
29
- main_site: string;
30
- bwiki_site: string;
31
- huiji_site: string;
32
- logsUrl: string;
33
- }
34
- export declare const Config: Schema<Config>;
35
- export declare function apply(ctx: Context, config: Config): void;