koishi-plugin-oni-sync-bot 0.0.6 → 0.0.8

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.d.ts CHANGED
@@ -27,7 +27,8 @@ export interface Config {
27
27
  huijiUAKey: string;
28
28
  domain: string;
29
29
  main_site: string;
30
- mirror_site: string;
30
+ bwiki_site: string;
31
+ huiji_site: string;
31
32
  logsUrl: string;
32
33
  }
33
34
  export declare const Config: Schema<Config>;
package/lib/index.js CHANGED
@@ -766,7 +766,8 @@ var Config = import_koishi5.Schema.object({
766
766
  huijiUAKey: import_koishi5.Schema.string().description("灰机wiki UAKey").default("${{ env.huijiUAKey }}"),
767
767
  domain: import_koishi5.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip"),
768
768
  main_site: import_koishi5.Schema.string().description("主站域名(必填,如:oxygennotincluded.wiki.gg)").default("oxygennotincluded.wiki.gg/zh"),
769
- mirror_site: import_koishi5.Schema.string().description("镜像站域名(必填,如:wiki.biligame.com)").default("wiki.biligame.com/oni"),
769
+ 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/"),
770
771
  logsUrl: import_koishi5.Schema.string().description("日志查看地址").default("https://klei.vip/onilogs")
771
772
  });
772
773
  var PublicLogProvider = class extends import_plugin_console.DataService {
@@ -781,6 +782,7 @@ var PublicLogProvider = class extends import_plugin_console.DataService {
781
782
  }
782
783
  };
783
784
  function apply(ctx, config) {
785
+ const log = ctx.logger("oni-sync");
784
786
  let ggbot;
785
787
  let huijibot;
786
788
  ctx.inject(["console"], (ctx2) => {
@@ -831,7 +833,18 @@ function apply(ctx, config) {
831
833
  const [page] = await ctx.database.get("wikipages", { id: pageId });
832
834
  if (!page)
833
835
  return router.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
834
- const targetUrl = `https://${config.mirror_site}/${encodeURIComponent(
836
+ const targetUrl = `https://${config.bwiki_site}/${encodeURIComponent(
837
+ page.title
838
+ )}`;
839
+ router.redirect(targetUrl);
840
+ });
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(
835
848
  page.title
836
849
  )}`;
837
850
  router.redirect(targetUrl);
@@ -853,14 +866,16 @@ function apply(ctx, config) {
853
866
  await syncPages(ggbot, huijibot).then(() => {
854
867
  logger.info("自动任务:尝试同步所有页面,从 WIKIGG 到 灰机wiki");
855
868
  }).catch((err) => {
856
- logger.error(`同步所有页面失败,错误信息:${err}`);
869
+ logger.error(`同步所有页面失败`);
870
+ log.error(`,错误信息:${err}`);
857
871
  });
858
872
  });
859
873
  ctx.cron("30 8 * * 3", async () => {
860
874
  await syncAllImages(ggbot, huijibot, config).then(() => {
861
875
  logger.info("自动任务:尝试同步所有图片,从 WIKIGG 到 灰机wiki");
862
876
  }).catch((err) => {
863
- logger.error(`同步所有图片失败,错误信息:${err}`);
877
+ logger.error(`同步所有图片失败`);
878
+ log.error(`,错误信息:${err}`);
864
879
  });
865
880
  });
866
881
  });
@@ -870,7 +885,8 @@ function apply(ctx, config) {
870
885
  `✅ 已尝试同步页面:${pageTitle},请前往控制台查看:${config.logsUrl}`
871
886
  );
872
887
  }).catch((err) => {
873
- session.send(`❌ 同步页面失败:${pageTitle},错误信息:${err}`);
888
+ session.send(`❌ 同步页面失败:${pageTitle}`);
889
+ log.error(`,错误信息:${err}`);
874
890
  });
875
891
  });
876
892
  ctx.command("sync.incrementalUpdate", "获取3h内的编辑并尝试更新", {
@@ -884,7 +900,10 @@ function apply(ctx, config) {
884
900
  `✅ 已尝试获取三小时前的编辑并同步,请前往控制台查看:${config.logsUrl}`
885
901
  );
886
902
  }).catch((err) => {
887
- session.send(`❌ 同步所有页面失败,错误信息:${err}`);
903
+ session.send(
904
+ `❌ 同步所有页面失败,请前往控制台查看日志:${config.logsUrl}`
905
+ );
906
+ log.error(`同步所有页面失败,错误信息:${err}`);
888
907
  });
889
908
  });
890
909
  ctx.command("sync.allpages", "同步所有页面", { authority: 2 }).action(async ({ session }) => {
@@ -896,7 +915,10 @@ function apply(ctx, config) {
896
915
  `✅ 已尝试同步所有页面,请前往控制台查看:${config.logsUrl}`
897
916
  );
898
917
  }).catch((err) => {
899
- session.send(`❌ 同步所有页面失败,错误信息:${err}`);
918
+ session.send(
919
+ `❌ 同步所有页面失败,请前往控制台查看日志:${config.logsUrl}`
920
+ );
921
+ log.error(`同步所有页面失败,错误信息:${err}`);
900
922
  });
901
923
  });
902
924
  ctx.command("sync.module <moduleTitle:string>", "同步指定模块", {
@@ -908,7 +930,8 @@ function apply(ctx, config) {
908
930
  `✅ 已尝试同步模块:${moduleTitle},请前往控制台查看:${config.logsUrl}`
909
931
  );
910
932
  }).catch((err) => {
911
- session.send(`❌ 同步模块失败:${moduleTitle},错误信息:${err}`);
933
+ session.send(`❌ 同步模块失败:${moduleTitle}`);
934
+ log.error(`错误信息:${err}`);
912
935
  });
913
936
  });
914
937
  ctx.command("sync.allmodules", "同步所有模块", { authority: 2 }).action(async ({ session }) => {
@@ -920,7 +943,10 @@ function apply(ctx, config) {
920
943
  `✅ 已尝试同步所有模块,请前往控制台查看:${config.logsUrl}`
921
944
  );
922
945
  }).catch((err) => {
923
- session.send(`❌ 同步所有模块失败,错误信息:${err}`);
946
+ session.send(
947
+ `❌ 同步所有模块失败,请前往控制台查看日志:${config.logsUrl}`
948
+ );
949
+ log.error(`同步所有模块失败,错误信息:${err}`);
924
950
  });
925
951
  });
926
952
  ctx.command("sync.img <imgTitle:string>", "同步指定图片", { authority: 2 }).action(async ({ session }, imgTitle) => {
@@ -935,7 +961,8 @@ function apply(ctx, config) {
935
961
  ).then(() => {
936
962
  session.send(`✅ 已尝试同步图片:${imgTitle}`);
937
963
  }).catch((err) => {
938
- session.send(`❌ 同步图片失败:${imgTitle},错误信息:${err}`);
964
+ session.send(`❌ 同步图片失败:${imgTitle}`);
965
+ log.error(`同步图片失败:${imgTitle},错误信息:${err}`);
939
966
  });
940
967
  });
941
968
  ctx.command("sync.allimgs", "同步所有图片", { authority: 2 }).action(async ({ session }) => {
@@ -947,7 +974,10 @@ function apply(ctx, config) {
947
974
  `✅ 已尝试同步所有图片,请前往控制台查看:${config.logsUrl}`
948
975
  );
949
976
  }).catch((err) => {
950
- session.send(`❌ 同步所有图片失败,错误信息:${err}`);
977
+ session.send(
978
+ `❌ 同步所有图片失败,请前往控制台查看日志:${config.logsUrl}`
979
+ );
980
+ log.error(`同步所有图片失败,错误信息:${err}`);
951
981
  });
952
982
  });
953
983
  ctx.command("x <itemName>", "查询缺氧中文wiki,精准匹配+拼音模糊匹配").alias("/查wiki").action(async ({ session }, itemName = "") => {
@@ -956,7 +986,7 @@ function apply(ctx, config) {
956
986
  return `以下是使用说明:
957
987
  原站点: https://${config.domain}/gg/88888888
958
988
 
959
- 镜像站: https://${config.domain}/bw/88888888`;
989
+ bwiki: https://${config.domain}/hj/88888888`;
960
990
  const { pinyin_full: queryPinyinFull, pinyin_first: queryPinyinFirst } = generatePinyinInfo(queryKey);
961
991
  const preciseTitleRes = await ctx.database.get("wikipages", {
962
992
  title: queryKey
@@ -966,7 +996,11 @@ function apply(ctx, config) {
966
996
  return `✅ 精准匹配成功
967
997
  原站点: https://${config.domain}/gg/${id2}
968
998
 
969
- 镜像站: https://${config.domain}/bw/${id2}`;
999
+ bwiki: https://${config.domain}/bw/${id2}
1000
+
1001
+ 灰机:https://${config.domain}/hj/${id2}
1002
+
1003
+ 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
970
1004
  }
971
1005
  const preciseFullPinyinRes = await ctx.database.get("wikipages", {
972
1006
  pinyin_full: queryKey
@@ -976,7 +1010,11 @@ function apply(ctx, config) {
976
1010
  return `✅ 拼音精准匹配成功(${queryKey} → ${title})
977
1011
  原站点: https://${config.domain}/gg/${id2}
978
1012
 
979
- 镜像站: https://${config.domain}/bw/${id2}`;
1013
+ bwiki: https://${config.domain}/bw/${id2}
1014
+
1015
+ 灰机:https://${config.domain}/hj/${id2}
1016
+
1017
+ 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
980
1018
  }
981
1019
  const preciseFirstPinyinRes = await ctx.database.get("wikipages", {
982
1020
  pinyin_first: queryKey
@@ -986,7 +1024,11 @@ function apply(ctx, config) {
986
1024
  return `✅ 首字母精准匹配成功(${queryKey} → ${title})
987
1025
  原站点: https://${config.domain}/gg/${id2}
988
1026
 
989
- 镜像站: https://${config.domain}/bw/${id2}`;
1027
+ bwiki: https://${config.domain}/bw/${id2}
1028
+
1029
+ 灰机:https://${config.domain}/hj/${id2}
1030
+
1031
+ 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护 `;
990
1032
  }
991
1033
  const allPages = await ctx.database.get("wikipages", {});
992
1034
  if (allPages.length === 0) {
@@ -1041,7 +1083,11 @@ function apply(ctx, config) {
1041
1083
  return `✅ 选择成功
1042
1084
  原站点: https://${config.domain}/gg/${id}
1043
1085
 
1044
- 镜像站: https://${config.domain}/bw/${id}`;
1086
+ bwiki: https://${config.domain}/bw/${id}
1087
+
1088
+ 灰机:https://${config.domain}/hj/${id}
1089
+
1090
+ 注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
1045
1091
  });
1046
1092
  ctx.command("update", "更新本地页面缓存(主站)", { authority: 2 }).action(async ({ session }) => {
1047
1093
  await session.execute("update.status");
@@ -1069,7 +1115,7 @@ function apply(ctx, config) {
1069
1115
  session.send(`✅ 检索到 ${pages.length} 个页面,已更新至数据库`);
1070
1116
  logger.info(`检索到 ${pages.length} 个页面,已更新至数据库`);
1071
1117
  } catch (err) {
1072
- logger.error("主站缓存更新失败", err);
1118
+ log.error("主站缓存更新失败", err);
1073
1119
  session.send("❌ 主站缓存更新失败,请联系管理员查看日志");
1074
1120
  }
1075
1121
  });
@@ -1079,7 +1125,7 @@ function apply(ctx, config) {
1079
1125
  session.send(`✅ 已删除 ${count.removed} 条本地缓存`);
1080
1126
  logger.info(`已删除 ${count.removed} 条本地缓存`);
1081
1127
  } catch (err) {
1082
- logger.error("删除缓存失败", err);
1128
+ log.error("删除缓存失败", err);
1083
1129
  session.send("❌ 删除缓存失败,请联系管理员查看日志");
1084
1130
  }
1085
1131
  });
@@ -1089,7 +1135,7 @@ function apply(ctx, config) {
1089
1135
  session.send(`📊 数据库中缓存了 ${pages.length} 条页面`);
1090
1136
  logger.info(`数据库中缓存了 ${pages.length} 条页面`);
1091
1137
  } catch (err) {
1092
- logger.error("查询缓存状态失败", err);
1138
+ log.error("查询缓存状态失败", err);
1093
1139
  session.send("❌ 查询缓存状态失败,请联系管理员查看日志");
1094
1140
  }
1095
1141
  });
@@ -1109,7 +1155,7 @@ function apply(ctx, config) {
1109
1155
  session.send(`✅ 已尝试添加重定向 ${pageName} -> ${targetPageName}`);
1110
1156
  await session.execute(`update`);
1111
1157
  } catch (err) {
1112
- logger.error(`添加重定向 ${pageName} -> ${targetPageName} 失败`, err);
1158
+ log.error(`添加重定向 ${pageName} -> ${targetPageName} 失败`, err);
1113
1159
  session.send(`❌ 添加重定向失败,请联系管理员查看日志`);
1114
1160
  }
1115
1161
  });
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.0.6",
4
+ "version": "0.0.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [