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

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/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{defineComponent as d,ref as p,watch as i,onMounted as g,resolveComponent as v,openBlock as m,createBlock as y,withCtx as h,createElementVNode as u,createElementBlock as _,Fragment as k,renderList as x,toDisplayString as B}from"vue";import{store as C,Time as T}from"@koishijs/client";const b="yyyy-MM-dd hh:mm:ss",M=d({__name:"page",setup(n){const t=p(),o=p([]);function s(e){const r=T.template(b,new Date(e.timestamp)),l=e.type.toUpperCase(),a=e.content.replace(/\u001b\[[0-9;]*m/g,"");return`[${r}] [${l}] ${a}`}i(()=>C.logs,e=>{if(!e)return;const r=e.filter(l=>l.name==="oni-sync").slice(-100).map(s);o.value=r},{deep:true,immediate:true});const c=()=>{t.value&&(t.value.scrollTop=t.value.scrollHeight)};return i(()=>o.value.length,()=>{setTimeout(c,0)}),g(()=>{c()}),(e,r)=>{const l=v("k-layout");return m(),y(l,null,{default:h(()=>[u("div",{class:"log-container",ref_key:"scrollRef",ref:t},[(m(true),_(k,null,x(o.value,(a,f)=>(m(),_("div",{key:f,class:"log-line"},[u("pre",null,B(a),1)]))),128))],512)]),_:1})}}}),R=(n,t)=>{const o=n.__vccOpts||n;for(const[s,c]of t)o[s]=c;return o},$=R(M,[["__scopeId","data-v-46bc7bec"]]),E=n=>{n.page({name:"同步机器人",path:"/onilogs",component:$})};export{E as default};
1
+ import{defineComponent as d,ref as i,watch as p,onMounted as g,resolveComponent as v,openBlock as c,createBlock as y,withCtx as h,createElementVNode as u,createElementBlock as f,Fragment as k,renderList as x,toDisplayString as B}from"vue";import{store as C,Time as T}from"@koishijs/client";const M="yyyy-MM-dd hh:mm:ss",R=d({__name:"page",setup(n){const t=i(),o=i([]);function r(e){const m=T.template(M,new Date(e.timestamp)),s=e.type.toUpperCase(),a=e.content.replace(/\u001b\[[0-9;]*m/g,"");return`[${m}] [${s}] ${a}`}p(()=>C.onilogs,e=>{e&&(o.value=e.map(r))},{deep:true,immediate:true});const l=()=>{t.value&&(t.value.scrollTop=t.value.scrollHeight)};return p(()=>o.value.length,()=>{setTimeout(l,0)}),g(()=>{l()}),(e,m)=>{const s=v("k-layout");return c(),y(s,null,{default:h(()=>[u("div",{class:"log-container",ref_key:"scrollRef",ref:t},[(c(true),f(k,null,x(o.value,(a,_)=>(c(),f("div",{key:_,class:"log-line"},[u("pre",null,B(a),1)]))),128))],512)]),_:1})}}}),$=(n,t)=>{const o=n.__vccOpts||n;for(const[r,l]of t)o[r]=l;return o},w=$(R,[["__scopeId","data-v-f988000f"]]),F=n=>{n.page({name:"同步机器人",path:"/onilogs",component:w,fields:["onilogs"]})};export{F as default};
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .log-container[data-v-46bc7bec]{width:100%;height:100%;overflow-y:auto;padding:12px;font-family:monospace;background:#1e1e1e;color:#d4d4d4}.log-line[data-v-46bc7bec]{line-height:1.5;font-size:13px}pre[data-v-46bc7bec]{margin:0;font-family:inherit;white-space:pre-wrap;word-break:break-all}.break-all{word-break:break-all}
1
+ .log-container[data-v-f988000f]{width:100%;height:100%;overflow-y:auto;padding:12px;font-family:monospace;background:#1e1e1e;color:#d4d4d4}.log-line[data-v-f988000f]{line-height:1.5;font-size:13px}pre[data-v-f988000f]{margin:0;font-family:inherit;white-space:pre-wrap;word-break:break-all}.break-all{word-break:break-all}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
- import { Context, Schema } from "koishi";
1
+ import { Context, Logger, Schema } from "koishi";
2
2
  export declare const name = "oni-sync-bot";
3
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
+ }
4
11
  declare module "koishi" {
5
12
  interface Tables {
6
13
  wikipages: WikiPages;
package/lib/index.js CHANGED
@@ -38,6 +38,7 @@ __export(src_exports, {
38
38
  module.exports = __toCommonJS(src_exports);
39
39
  var import_koishi5 = require("koishi");
40
40
  var import_path = require("path");
41
+ var import_plugin_console = require("@koishijs/plugin-console");
41
42
 
42
43
  // src/utils/login.ts
43
44
  var import_mwn = require("mwn");
@@ -46,9 +47,15 @@ var import_mwn = require("mwn");
46
47
  var import_koishi = require("koishi");
47
48
  var import_pinyin_pro = require("pinyin-pro");
48
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/";
49
52
  function clean_page_text(text) {
50
53
  const textWithoutCrossLink = text.replace(CROSS_SITE_LINK_REGEX, "");
51
- return textWithoutCrossLink;
54
+ const textWithReplacedDev = textWithoutCrossLink.replace(
55
+ DEV_TEXT_REGEX,
56
+ MODULE_NAMESPACE_PREFIX
57
+ );
58
+ return textWithReplacedDev;
52
59
  }
53
60
  __name(clean_page_text, "clean_page_text");
54
61
  async function getAndProcessPageContent(site, pageTitle) {
@@ -600,16 +607,24 @@ async function syncSingleModule(oldSite, newSite, moduleTitle, user) {
600
607
  }
601
608
  try {
602
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
+ }
603
618
  const [oldContent, newContent] = await Promise.all([
604
619
  getAndProcessPageContent(oldSite, moduleTitle),
605
- getAndProcessPageContent(newSite, moduleTitle)
620
+ getAndProcessPageContent(newSite, targetTitle)
606
621
  ]);
607
622
  if (oldContent === newContent) {
608
623
  logger.info(`[SyncModule] 🟡 模块 ${moduleTitle} 内容未改变,跳过`);
609
624
  return { success: true, reason: "no_change" };
610
625
  }
611
626
  await newSite.save(
612
- moduleTitle,
627
+ targetTitle,
613
628
  oldContent,
614
629
  `由:${user || "同步坤器人手动"} 触发更改,此时同步`
615
630
  );
@@ -650,6 +665,7 @@ async function syncModules(oldSite, newSite) {
650
665
  try {
651
666
  const oldModuleList = await getAllModules(oldSite);
652
667
  const total = oldModuleList.length;
668
+ console.log(oldModuleList);
653
669
  if (total === 0) {
654
670
  logger.info(`[SyncAllModules] 📭 原站点无模块可同步,结束`);
655
671
  return;
@@ -741,6 +757,7 @@ __name(syncModules, "syncModules");
741
757
  // src/index.ts
742
758
  var name = "oni-sync-bot";
743
759
  var inject = ["console", "database", "server", "cron"];
760
+ var logBuffer = [];
744
761
  var Config = import_koishi5.Schema.object({
745
762
  ggUsername: import_koishi5.Schema.string().description("WIKIGG 用户名").default("${{ env.ggUsername }}"),
746
763
  ggPassword: import_koishi5.Schema.string().description("WIKIGG 密码").default("${{ env.ggPassword }}"),
@@ -750,8 +767,19 @@ var Config = import_koishi5.Schema.object({
750
767
  domain: import_koishi5.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip"),
751
768
  main_site: import_koishi5.Schema.string().description("主站域名(必填,如:oxygennotincluded.wiki.gg)").default("oxygennotincluded.wiki.gg/zh"),
752
769
  mirror_site: import_koishi5.Schema.string().description("镜像站域名(必填,如:wiki.biligame.com)").default("wiki.biligame.com/oni"),
753
- logsUrl: import_koishi5.Schema.string().description("日志查看地址").default("htts://klei.vip/onilogs")
770
+ logsUrl: import_koishi5.Schema.string().description("日志查看地址").default("https://klei.vip/onilogs")
754
771
  });
772
+ var PublicLogProvider = class extends import_plugin_console.DataService {
773
+ static {
774
+ __name(this, "PublicLogProvider");
775
+ }
776
+ constructor(ctx) {
777
+ super(ctx, "onilogs", { authority: 0 });
778
+ }
779
+ async get() {
780
+ return logBuffer;
781
+ }
782
+ };
755
783
  function apply(ctx, config) {
756
784
  let ggbot;
757
785
  let huijibot;
@@ -761,6 +789,23 @@ function apply(ctx, config) {
761
789
  prod: (0, import_path.resolve)(__dirname, "../dist")
762
790
  });
763
791
  });
792
+ ctx.plugin(PublicLogProvider);
793
+ const target = {
794
+ colors: 0,
795
+ record: /* @__PURE__ */ __name((record) => {
796
+ if (record.name !== "oni-sync") return;
797
+ logBuffer.push(record);
798
+ if (logBuffer.length > 100) {
799
+ logBuffer = logBuffer.slice(-100);
800
+ }
801
+ ctx.get("console")?.patch("onilogs", logBuffer);
802
+ }, "record")
803
+ };
804
+ import_koishi5.Logger.targets.push(target);
805
+ ctx.on("dispose", () => {
806
+ const index = import_koishi5.Logger.targets.indexOf(target);
807
+ if (index > -1) import_koishi5.Logger.targets.splice(index, 1);
808
+ });
764
809
  ctx.model.extend("wikipages", {
765
810
  id: "integer",
766
811
  title: "string",
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.4",
4
+ "version": "0.0.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [