koishi-plugin-oni-sync-bot 0.0.5 → 0.0.7
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 +2 -1
- package/lib/index.js +53 -10
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -47,9 +47,15 @@ var import_mwn = require("mwn");
|
|
|
47
47
|
var import_koishi = require("koishi");
|
|
48
48
|
var import_pinyin_pro = require("pinyin-pro");
|
|
49
49
|
var CROSS_SITE_LINK_REGEX = /\[\[(en|ru|pt-br):[^\]]*\]\]/g;
|
|
50
|
+
var DEV_TEXT_REGEX = /(?<!\w)Dev:/g;
|
|
51
|
+
var MODULE_NAMESPACE_PREFIX = "Module:Dev/";
|
|
50
52
|
function clean_page_text(text) {
|
|
51
53
|
const textWithoutCrossLink = text.replace(CROSS_SITE_LINK_REGEX, "");
|
|
52
|
-
|
|
54
|
+
const textWithReplacedDev = textWithoutCrossLink.replace(
|
|
55
|
+
DEV_TEXT_REGEX,
|
|
56
|
+
MODULE_NAMESPACE_PREFIX
|
|
57
|
+
);
|
|
58
|
+
return textWithReplacedDev;
|
|
53
59
|
}
|
|
54
60
|
__name(clean_page_text, "clean_page_text");
|
|
55
61
|
async function getAndProcessPageContent(site, pageTitle) {
|
|
@@ -601,16 +607,24 @@ async function syncSingleModule(oldSite, newSite, moduleTitle, user) {
|
|
|
601
607
|
}
|
|
602
608
|
try {
|
|
603
609
|
logger.info(`[SyncModule] 🔍 开始获取模块 ${moduleTitle} 的内容`);
|
|
610
|
+
let targetTitle = moduleTitle;
|
|
611
|
+
if (/^Dev:/i.test(moduleTitle)) {
|
|
612
|
+
const subPageName = moduleTitle.replace(/^Dev:/i, "");
|
|
613
|
+
targetTitle = `Module:Dev/${subPageName}`;
|
|
614
|
+
logger.info(
|
|
615
|
+
`[SyncModule] 🔀 检测到 Dev 命名空间,路径映射: ${moduleTitle} -> ${targetTitle}`
|
|
616
|
+
);
|
|
617
|
+
}
|
|
604
618
|
const [oldContent, newContent] = await Promise.all([
|
|
605
619
|
getAndProcessPageContent(oldSite, moduleTitle),
|
|
606
|
-
getAndProcessPageContent(newSite,
|
|
620
|
+
getAndProcessPageContent(newSite, targetTitle)
|
|
607
621
|
]);
|
|
608
622
|
if (oldContent === newContent) {
|
|
609
623
|
logger.info(`[SyncModule] 🟡 模块 ${moduleTitle} 内容未改变,跳过`);
|
|
610
624
|
return { success: true, reason: "no_change" };
|
|
611
625
|
}
|
|
612
626
|
await newSite.save(
|
|
613
|
-
|
|
627
|
+
targetTitle,
|
|
614
628
|
oldContent,
|
|
615
629
|
`由:${user || "同步坤器人手动"} 触发更改,此时同步`
|
|
616
630
|
);
|
|
@@ -651,6 +665,7 @@ async function syncModules(oldSite, newSite) {
|
|
|
651
665
|
try {
|
|
652
666
|
const oldModuleList = await getAllModules(oldSite);
|
|
653
667
|
const total = oldModuleList.length;
|
|
668
|
+
console.log(oldModuleList);
|
|
654
669
|
if (total === 0) {
|
|
655
670
|
logger.info(`[SyncAllModules] 📭 原站点无模块可同步,结束`);
|
|
656
671
|
return;
|
|
@@ -751,7 +766,8 @@ var Config = import_koishi5.Schema.object({
|
|
|
751
766
|
huijiUAKey: import_koishi5.Schema.string().description("灰机wiki UAKey").default("${{ env.huijiUAKey }}"),
|
|
752
767
|
domain: import_koishi5.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip"),
|
|
753
768
|
main_site: import_koishi5.Schema.string().description("主站域名(必填,如:oxygennotincluded.wiki.gg)").default("oxygennotincluded.wiki.gg/zh"),
|
|
754
|
-
|
|
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/"),
|
|
755
771
|
logsUrl: import_koishi5.Schema.string().description("日志查看地址").default("https://klei.vip/onilogs")
|
|
756
772
|
});
|
|
757
773
|
var PublicLogProvider = class extends import_plugin_console.DataService {
|
|
@@ -816,7 +832,18 @@ function apply(ctx, config) {
|
|
|
816
832
|
const [page] = await ctx.database.get("wikipages", { id: pageId });
|
|
817
833
|
if (!page)
|
|
818
834
|
return router.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
|
|
819
|
-
const targetUrl = `https://${config.
|
|
835
|
+
const targetUrl = `https://${config.bwiki_site}/${encodeURIComponent(
|
|
836
|
+
page.title
|
|
837
|
+
)}`;
|
|
838
|
+
router.redirect(targetUrl);
|
|
839
|
+
});
|
|
840
|
+
ctx.server.get("/hj/:id", async (router) => {
|
|
841
|
+
const pageId = Number(router.params.id);
|
|
842
|
+
if (isNaN(pageId)) return router.body = "❌ 无效的页面ID,必须为数字!";
|
|
843
|
+
const [page] = await ctx.database.get("wikipages", { id: pageId });
|
|
844
|
+
if (!page)
|
|
845
|
+
return router.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
|
|
846
|
+
const targetUrl = `https://${config.huiji_site}/${encodeURIComponent(
|
|
820
847
|
page.title
|
|
821
848
|
)}`;
|
|
822
849
|
router.redirect(targetUrl);
|
|
@@ -941,7 +968,7 @@ function apply(ctx, config) {
|
|
|
941
968
|
return `以下是使用说明:
|
|
942
969
|
原站点: https://${config.domain}/gg/88888888
|
|
943
970
|
|
|
944
|
-
|
|
971
|
+
bwiki: https://${config.domain}/hj/88888888`;
|
|
945
972
|
const { pinyin_full: queryPinyinFull, pinyin_first: queryPinyinFirst } = generatePinyinInfo(queryKey);
|
|
946
973
|
const preciseTitleRes = await ctx.database.get("wikipages", {
|
|
947
974
|
title: queryKey
|
|
@@ -951,7 +978,11 @@ function apply(ctx, config) {
|
|
|
951
978
|
return `✅ 精准匹配成功
|
|
952
979
|
原站点: https://${config.domain}/gg/${id2}
|
|
953
980
|
|
|
954
|
-
|
|
981
|
+
bwiki: https://${config.domain}/bw/${id2}
|
|
982
|
+
|
|
983
|
+
灰机:https://${config.domain}/hj/${id2}
|
|
984
|
+
|
|
985
|
+
注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
|
|
955
986
|
}
|
|
956
987
|
const preciseFullPinyinRes = await ctx.database.get("wikipages", {
|
|
957
988
|
pinyin_full: queryKey
|
|
@@ -961,7 +992,11 @@ function apply(ctx, config) {
|
|
|
961
992
|
return `✅ 拼音精准匹配成功(${queryKey} → ${title})
|
|
962
993
|
原站点: https://${config.domain}/gg/${id2}
|
|
963
994
|
|
|
964
|
-
|
|
995
|
+
bwiki: https://${config.domain}/bw/${id2}
|
|
996
|
+
|
|
997
|
+
灰机:https://${config.domain}/hj/${id2}
|
|
998
|
+
|
|
999
|
+
注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
|
|
965
1000
|
}
|
|
966
1001
|
const preciseFirstPinyinRes = await ctx.database.get("wikipages", {
|
|
967
1002
|
pinyin_first: queryKey
|
|
@@ -971,7 +1006,11 @@ function apply(ctx, config) {
|
|
|
971
1006
|
return `✅ 首字母精准匹配成功(${queryKey} → ${title})
|
|
972
1007
|
原站点: https://${config.domain}/gg/${id2}
|
|
973
1008
|
|
|
974
|
-
|
|
1009
|
+
bwiki: https://${config.domain}/bw/${id2}
|
|
1010
|
+
|
|
1011
|
+
灰机:https://${config.domain}/hj/${id2}
|
|
1012
|
+
|
|
1013
|
+
注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护 `;
|
|
975
1014
|
}
|
|
976
1015
|
const allPages = await ctx.database.get("wikipages", {});
|
|
977
1016
|
if (allPages.length === 0) {
|
|
@@ -1026,7 +1065,11 @@ function apply(ctx, config) {
|
|
|
1026
1065
|
return `✅ 选择成功
|
|
1027
1066
|
原站点: https://${config.domain}/gg/${id}
|
|
1028
1067
|
|
|
1029
|
-
|
|
1068
|
+
bwiki: https://${config.domain}/bw/${id}
|
|
1069
|
+
|
|
1070
|
+
灰机:https://${config.domain}/hj/${id}
|
|
1071
|
+
|
|
1072
|
+
注:bwiki将在不久后停止技术支持,镜像站点将迁移至灰机!并继续维护`;
|
|
1030
1073
|
});
|
|
1031
1074
|
ctx.command("update", "更新本地页面缓存(主站)", { authority: 2 }).action(async ({ session }) => {
|
|
1032
1075
|
await session.execute("update.status");
|