koishi-plugin-dew-bot 1.0.251 → 1.0.253
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/README.md +0 -4
- package/lib/index.js +328 -106
- package/lib/plugin/serverHandel/qqCommandMessage.d.ts +1 -1
- package/lib/plugin/serverHandel/qqMarkdownHelpers.d.ts +6 -0
- package/lib/plugin/serverHandel/qqPageMessage.d.ts +4 -2
- package/lib/plugin/serverHandel/qqRewardMessage.d.ts +9 -0
- package/lib/plugin/serverHandel/qqStoryMessage.d.ts +6 -0
- package/lib/shared/face/index.d.ts +6 -0
- package/package.json +1 -1
- package/src/index.ts +0 -4
- package/src/plugin/serverHandel/image.ts +11 -4
- package/src/plugin/serverHandel/qqCommandMessage.ts +29 -24
- package/src/plugin/serverHandel/qqMarkdownHelpers.ts +17 -0
- package/src/plugin/serverHandel/qqPageMessage.ts +71 -36
- package/src/plugin/serverHandel/qqRewardMessage.ts +62 -0
- package/src/plugin/serverHandel/qqStoryMessage.ts +73 -0
- package/src/plugin/serverHandel/qqTransactionMessage.ts +22 -8
- package/src/plugin/serverHandel/text.ts +14 -5
- package/src/shared/bot/serviceProto.ts +25 -1
- package/src/shared/face/index.ts +6 -0
package/README.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -42,40 +42,6 @@ var import_koishi2 = require("koishi");
|
|
|
42
42
|
// src/plugin/serverHandel/image.ts
|
|
43
43
|
var import_koishi = require("koishi");
|
|
44
44
|
|
|
45
|
-
// src/shared/bot/analysisMsg.ts
|
|
46
|
-
var AnalysisMsg = class {
|
|
47
|
-
static {
|
|
48
|
-
__name(this, "AnalysisMsg");
|
|
49
|
-
}
|
|
50
|
-
parse(data) {
|
|
51
|
-
let msg = "";
|
|
52
|
-
let haveTitle = false;
|
|
53
|
-
for (const item of data.line) {
|
|
54
|
-
switch (item.type) {
|
|
55
|
-
case 0 /* title */:
|
|
56
|
-
haveTitle = true;
|
|
57
|
-
msg += `┄━═${item.content}═━┄
|
|
58
|
-
`;
|
|
59
|
-
break;
|
|
60
|
-
case 1 /* line */:
|
|
61
|
-
msg += `${item.content}
|
|
62
|
-
`;
|
|
63
|
-
break;
|
|
64
|
-
case 2 /* error */:
|
|
65
|
-
msg += `❌出错了!错误原因:${item.content},请反馈至联系开发者
|
|
66
|
-
`;
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (haveTitle) {
|
|
73
|
-
msg += "┄━════════━┄";
|
|
74
|
-
}
|
|
75
|
-
return msg;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
45
|
// src/plugin/appearanceCardTemplate.ts
|
|
80
46
|
var escape = /* @__PURE__ */ __name((value) => String(value ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]), "escape");
|
|
81
47
|
function appearanceCardHtml(card, artwork, paper) {
|
|
@@ -689,32 +655,41 @@ var handel_base = class {
|
|
|
689
655
|
}
|
|
690
656
|
};
|
|
691
657
|
|
|
692
|
-
// src/
|
|
693
|
-
var
|
|
658
|
+
// src/shared/bot/analysisMsg.ts
|
|
659
|
+
var AnalysisMsg = class {
|
|
694
660
|
static {
|
|
695
|
-
__name(this, "
|
|
661
|
+
__name(this, "AnalysisMsg");
|
|
696
662
|
}
|
|
697
|
-
|
|
698
|
-
let
|
|
699
|
-
let
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
663
|
+
parse(data) {
|
|
664
|
+
let msg = "";
|
|
665
|
+
let haveTitle = false;
|
|
666
|
+
for (const item of data.line) {
|
|
667
|
+
switch (item.type) {
|
|
668
|
+
case 0 /* title */:
|
|
669
|
+
haveTitle = true;
|
|
670
|
+
msg += `┄━═${item.content}═━┄
|
|
671
|
+
`;
|
|
672
|
+
break;
|
|
673
|
+
case 1 /* line */:
|
|
674
|
+
msg += `${item.content}
|
|
675
|
+
`;
|
|
676
|
+
break;
|
|
677
|
+
case 2 /* error */:
|
|
678
|
+
msg += `❌出错了!错误原因:${item.content},请反馈至联系开发者
|
|
679
|
+
`;
|
|
680
|
+
break;
|
|
681
|
+
default:
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
712
684
|
}
|
|
713
|
-
|
|
685
|
+
if (haveTitle) {
|
|
686
|
+
msg += "┄━════════━┄";
|
|
687
|
+
}
|
|
688
|
+
return msg;
|
|
714
689
|
}
|
|
715
690
|
};
|
|
716
691
|
|
|
717
|
-
// src/plugin/serverHandel/
|
|
692
|
+
// src/plugin/serverHandel/qqMarkdownHelpers.ts
|
|
718
693
|
function escapeMarkdown(value) {
|
|
719
694
|
return value.replace(/[\\`*_{}\[\]()#+\-.!|>~<&]/g, "\\$&");
|
|
720
695
|
}
|
|
@@ -723,6 +698,68 @@ function compactDisplayText(value) {
|
|
|
723
698
|
return value.trim().replace(/[ \t\u3000]*([·×+|])[ \t\u3000]*/g, "$1").replace(/([\p{Script=Han}\p{Extended_Pictographic}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F])[ \t\u3000]+/gu, "$1").replace(/[ \t\u3000]+(?=[\p{Script=Han}\p{Extended_Pictographic}\p{Regional_Indicator}])/gu, "");
|
|
724
699
|
}
|
|
725
700
|
__name(compactDisplayText, "compactDisplayText");
|
|
701
|
+
function renderQQTitle(content) {
|
|
702
|
+
return `**${escapeMarkdown(compactDisplayText(content))}**
|
|
703
|
+
|
|
704
|
+
***`;
|
|
705
|
+
}
|
|
706
|
+
__name(renderQQTitle, "renderQQTitle");
|
|
707
|
+
|
|
708
|
+
// src/plugin/serverHandel/qqRewardMessage.ts
|
|
709
|
+
function hasRewardLines(data) {
|
|
710
|
+
return data.line.some((item) => item.type === 1 /* line */ && item.reward === true);
|
|
711
|
+
}
|
|
712
|
+
__name(hasRewardLines, "hasRewardLines");
|
|
713
|
+
function isRewardMessage(data) {
|
|
714
|
+
return data.reward === true || hasRewardLines(data);
|
|
715
|
+
}
|
|
716
|
+
__name(isRewardMessage, "isRewardMessage");
|
|
717
|
+
function renderRewardTitle(content) {
|
|
718
|
+
return `**${escapeMarkdown(compactDisplayText(content))}**`;
|
|
719
|
+
}
|
|
720
|
+
__name(renderRewardTitle, "renderRewardTitle");
|
|
721
|
+
function renderRewardLine(content) {
|
|
722
|
+
return content.replace(/\r\n?/g, "\n").split("\n").filter((line) => line.trim()).map((line) => {
|
|
723
|
+
const text = line.trim();
|
|
724
|
+
const quantity = /([++\-−×xX]\s*\d+(?:\.\d+)?)$/.exec(text);
|
|
725
|
+
const formatted = quantity ? escapeMarkdown(text.slice(0, quantity.index)) + `**${escapeMarkdown(quantity[1])}**` : escapeMarkdown(text);
|
|
726
|
+
return "> " + formatted;
|
|
727
|
+
}).join(" \n");
|
|
728
|
+
}
|
|
729
|
+
__name(renderRewardLine, "renderRewardLine");
|
|
730
|
+
function renderQQRewardMarkdown(data, showGreeting) {
|
|
731
|
+
const sections = [];
|
|
732
|
+
const bodyLines = [];
|
|
733
|
+
const rewardLines = [];
|
|
734
|
+
const flushBody = /* @__PURE__ */ __name(() => {
|
|
735
|
+
if (bodyLines.length) sections.push(bodyLines.splice(0).join(" \n"));
|
|
736
|
+
}, "flushBody");
|
|
737
|
+
if (showGreeting && !data.reward) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
738
|
+
for (const item of data.line) {
|
|
739
|
+
if (item.type === 1 /* line */ && item.reward) {
|
|
740
|
+
const reward = renderRewardLine(item.content);
|
|
741
|
+
if (reward) rewardLines.push(reward);
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (item.type === 0 /* title */) {
|
|
745
|
+
flushBody();
|
|
746
|
+
bodyLines.push(renderRewardTitle(item.content));
|
|
747
|
+
} else if (item.type === 1 /* line */) {
|
|
748
|
+
for (const line of item.content.replace(/\r\n?/g, "\n").split("\n")) {
|
|
749
|
+
if (!line.trim()) flushBody();
|
|
750
|
+
else bodyLines.push(escapeMarkdown(line));
|
|
751
|
+
}
|
|
752
|
+
} else if (item.type === 2 /* error */) {
|
|
753
|
+
bodyLines.push(`❌ ${escapeMarkdown(item.content)}`);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
flushBody();
|
|
757
|
+
if (rewardLines.length) sections.push(rewardLines.join(" \n"));
|
|
758
|
+
return sections.join("\n\n") || " ";
|
|
759
|
+
}
|
|
760
|
+
__name(renderQQRewardMarkdown, "renderQQRewardMarkdown");
|
|
761
|
+
|
|
762
|
+
// src/plugin/serverHandel/qqPageMessage.ts
|
|
726
763
|
function compactListLabel(value) {
|
|
727
764
|
const label = compactDisplayText(value);
|
|
728
765
|
return /[📖📚]/u.test(label) ? label.replace(/技能书(?=$|×\d+(?:\.\d+)?(?:||$)||)/g, "") : label;
|
|
@@ -733,6 +770,42 @@ function inlineCommandUrl(command) {
|
|
|
733
770
|
return `mqqapi://aio/inlinecmd?command=${encoded}&enter=true&reply=false`;
|
|
734
771
|
}
|
|
735
772
|
__name(inlineCommandUrl, "inlineCommandUrl");
|
|
773
|
+
function inlineCommandSpans(content) {
|
|
774
|
+
const spans = [];
|
|
775
|
+
let depth = 0, start = 0, labelStart = 0;
|
|
776
|
+
for (let index = 0; index < content.length; index++) {
|
|
777
|
+
if (content[index] === "[") {
|
|
778
|
+
if (depth === 0) {
|
|
779
|
+
start = index > 0 && content[index - 1] === "\\" ? index - 1 : index;
|
|
780
|
+
labelStart = index + 1;
|
|
781
|
+
}
|
|
782
|
+
depth++;
|
|
783
|
+
} else if (content[index] === "]" && depth > 0 && --depth === 0) {
|
|
784
|
+
const label = content.slice(labelStart, index).replace(/\\$/, "");
|
|
785
|
+
if (!label.trim() || /[\[\]\r\n]/.test(label) || /^\d+$/.test(label.trim())) continue;
|
|
786
|
+
const command = label.split(/[++]/, 1)[0].trim();
|
|
787
|
+
if (command) spans.push({ start, end: index + 1, label, command });
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return spans;
|
|
791
|
+
}
|
|
792
|
+
__name(inlineCommandSpans, "inlineCommandSpans");
|
|
793
|
+
function hasInlineCommands(content) {
|
|
794
|
+
return inlineCommandSpans(content).length > 0;
|
|
795
|
+
}
|
|
796
|
+
__name(hasInlineCommands, "hasInlineCommands");
|
|
797
|
+
function renderInlineCommands(content) {
|
|
798
|
+
const parts = [];
|
|
799
|
+
let offset = 0;
|
|
800
|
+
for (const span of inlineCommandSpans(content)) {
|
|
801
|
+
parts.push(escapeMarkdown(content.slice(offset, span.start)));
|
|
802
|
+
parts.push("[" + escapeMarkdown(span.label) + "](" + inlineCommandUrl(span.command) + ")");
|
|
803
|
+
offset = span.end;
|
|
804
|
+
}
|
|
805
|
+
parts.push(escapeMarkdown(content.slice(offset)));
|
|
806
|
+
return parts.join("");
|
|
807
|
+
}
|
|
808
|
+
__name(renderInlineCommands, "renderInlineCommands");
|
|
736
809
|
function pageCommandLines(nav) {
|
|
737
810
|
return [
|
|
738
811
|
...nav.previousCommand ? [nav.previousCommand] : [],
|
|
@@ -741,52 +814,59 @@ function pageCommandLines(nav) {
|
|
|
741
814
|
}
|
|
742
815
|
__name(pageCommandLines, "pageCommandLines");
|
|
743
816
|
function renderQQPageMarkdown(data, showGreeting) {
|
|
817
|
+
const rewardMessage = isRewardMessage(data);
|
|
744
818
|
const nav = data.pageNav;
|
|
745
819
|
const entryCommands = new Map(nav?.entries?.map((entry) => [entry.lineIndex, entry.viewCommand]) ?? []);
|
|
746
820
|
const listPattern = /^\[(\d+)\]\s*([^\r\n]+)$/;
|
|
747
821
|
const pagePattern = /^第\s*\d+\s*\/\s*\d+\s*页(?:\s*[||]\s*共\s*(\d+)\s*([项条]))?$/;
|
|
748
822
|
const title = data.line.find((item) => item.type === 0 /* title */);
|
|
749
|
-
const summaryLine = data.line.find((item) => item.type === 1 /* line */ && pagePattern.test(item.content));
|
|
750
|
-
const summary = summaryLine && pagePattern.exec(summaryLine.content);
|
|
751
|
-
const listCount = data.line.filter((item) => item.type === 1 /* line */ && listPattern.test(item.content)).length;
|
|
752
|
-
const count = summary?.[1] ?? (nav?.total === 1 && listCount > 0 ? String(listCount) : void 0);
|
|
753
|
-
const countUnit = summary?.[2] ?? "项";
|
|
754
823
|
const isLeaderboardDirectory = !!nav?.entries?.length && /^(?:🏆)?排行榜$/u.test(compactDisplayText(title?.content ?? ""));
|
|
755
824
|
const sections = [];
|
|
756
825
|
const bodyLines = [];
|
|
757
826
|
const listLines = [];
|
|
827
|
+
const rewardLines = [];
|
|
758
828
|
const flushBody = /* @__PURE__ */ __name(() => {
|
|
759
829
|
if (bodyLines.length) sections.push(bodyLines.splice(0).join(" \n"));
|
|
760
830
|
}, "flushBody");
|
|
761
831
|
const flushList = /* @__PURE__ */ __name(() => {
|
|
762
832
|
if (listLines.length) sections.push(listLines.splice(0).join("\n"));
|
|
763
833
|
}, "flushList");
|
|
834
|
+
const flushRewards = /* @__PURE__ */ __name(() => {
|
|
835
|
+
if (rewardLines.length) sections.push(rewardLines.splice(0).join(" \n"));
|
|
836
|
+
}, "flushRewards");
|
|
764
837
|
const flush = /* @__PURE__ */ __name(() => {
|
|
765
838
|
flushList();
|
|
766
839
|
flushBody();
|
|
840
|
+
flushRewards();
|
|
767
841
|
}, "flush");
|
|
768
842
|
let hasPageSummary = false;
|
|
769
843
|
let hasHelp = false;
|
|
770
844
|
let pageFooter;
|
|
771
|
-
if (showGreeting) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
845
|
+
if (showGreeting && !data.reward) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
772
846
|
for (const [lineIndex, item] of data.line.entries()) {
|
|
773
847
|
switch (item.type) {
|
|
774
848
|
case 0 /* title */:
|
|
775
849
|
flush();
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
} else {
|
|
780
|
-
sections.push(`**${escapeMarkdown(compactDisplayText(item.content))}${count !== void 0 ? `·${count}${countUnit}` : ""}**`);
|
|
781
|
-
}
|
|
850
|
+
const titleText = `${isLeaderboardDirectory && !item.content.includes("🏆") ? "🏆" : ""}${item.content}`;
|
|
851
|
+
if (rewardMessage) bodyLines.push(renderRewardTitle(titleText));
|
|
852
|
+
else sections.push(renderQQTitle(titleText));
|
|
782
853
|
break;
|
|
783
854
|
case 1 /* line */: {
|
|
855
|
+
if (item.reward) {
|
|
856
|
+
flushList();
|
|
857
|
+
flushBody();
|
|
858
|
+
const reward = renderRewardLine(item.content);
|
|
859
|
+
if (reward) rewardLines.push(reward);
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
flushRewards();
|
|
784
863
|
const listEntry = listPattern.exec(item.content);
|
|
785
864
|
if (listEntry) {
|
|
786
865
|
flushBody();
|
|
787
866
|
const command2 = entryCommands.get(lineIndex);
|
|
788
|
-
const
|
|
789
|
-
const
|
|
867
|
+
const content = compactListLabel(listEntry[2]);
|
|
868
|
+
const label = escapeMarkdown(content);
|
|
869
|
+
const name2 = command2 ? `[${label}](${inlineCommandUrl(command2)})` : renderInlineCommands(content);
|
|
790
870
|
listLines.push(`${listEntry[1]}. ${name2}`);
|
|
791
871
|
break;
|
|
792
872
|
}
|
|
@@ -803,17 +883,17 @@ function renderQQPageMarkdown(data, showGreeting) {
|
|
|
803
883
|
const page = pagePattern.exec(item.content);
|
|
804
884
|
if (page && nav) {
|
|
805
885
|
flushBody();
|
|
806
|
-
pageFooter = `**第${nav.current}/${nav.total}
|
|
886
|
+
pageFooter = `**第${nav.current}/${nav.total}页**`;
|
|
807
887
|
hasPageSummary = true;
|
|
808
888
|
break;
|
|
809
889
|
}
|
|
810
890
|
const command = entryCommands.get(lineIndex);
|
|
811
|
-
bodyLines.push(command ? `[${escapeMarkdown(
|
|
891
|
+
bodyLines.push(command ? `[${escapeMarkdown(compactListLabel(item.content))}](${inlineCommandUrl(command)})` : renderInlineCommands(item.content));
|
|
812
892
|
break;
|
|
813
893
|
}
|
|
814
894
|
case 2 /* error */:
|
|
815
895
|
flush();
|
|
816
|
-
sections.push(`❌ 出错了!错误原因:${
|
|
896
|
+
sections.push(`❌ 出错了!错误原因:${renderInlineCommands(item.content)},请反馈至联系开发者`);
|
|
817
897
|
break;
|
|
818
898
|
}
|
|
819
899
|
}
|
|
@@ -824,10 +904,7 @@ function renderQQPageMarkdown(data, showGreeting) {
|
|
|
824
904
|
const nextLink = nav?.nextCommand ? `[${nav.nextCommand === "下一个" ? "下一个" : "下一页"}](${inlineCommandUrl(nav.nextCommand)})` : void 0;
|
|
825
905
|
const helpLink = hasHelp ? `[指令](${inlineCommandUrl("指令")})` : void 0;
|
|
826
906
|
const footer = pageFooter ? [pageFooter, previousLink, nextLink, helpLink].filter(Boolean).join("·") : helpLink ? `更多操作:${helpLink}` : void 0;
|
|
827
|
-
if (footer)
|
|
828
|
-
if (isLeaderboardDirectory) sections.push("***");
|
|
829
|
-
sections.push(footer);
|
|
830
|
-
}
|
|
907
|
+
if (footer) sections.push(footer);
|
|
831
908
|
return sections.join("\n\n") || " ";
|
|
832
909
|
}
|
|
833
910
|
__name(renderQQPageMarkdown, "renderQQPageMarkdown");
|
|
@@ -866,32 +943,47 @@ __name(sendQQMarkdown, "sendQQMarkdown");
|
|
|
866
943
|
|
|
867
944
|
// src/plugin/serverHandel/qqTransactionMessage.ts
|
|
868
945
|
function renderQQTransactionMarkdown(data, showGreeting) {
|
|
946
|
+
const rewardMessage = isRewardMessage(data);
|
|
869
947
|
const sections = [];
|
|
870
948
|
const bodyLines = [];
|
|
871
949
|
const actions = [];
|
|
950
|
+
const rewardLines = [];
|
|
872
951
|
const flushBody = /* @__PURE__ */ __name(() => {
|
|
873
952
|
if (bodyLines.length) sections.push(bodyLines.splice(0).join(" \n"));
|
|
874
953
|
}, "flushBody");
|
|
875
954
|
const flushActions = /* @__PURE__ */ __name(() => {
|
|
876
955
|
if (actions.length) sections.push(actions.splice(0).join(" · "));
|
|
877
956
|
}, "flushActions");
|
|
957
|
+
const flushRewards = /* @__PURE__ */ __name(() => {
|
|
958
|
+
if (rewardLines.length) sections.push(rewardLines.splice(0).join(" \n"));
|
|
959
|
+
}, "flushRewards");
|
|
878
960
|
const flush = /* @__PURE__ */ __name(() => {
|
|
879
961
|
flushBody();
|
|
880
962
|
flushActions();
|
|
963
|
+
flushRewards();
|
|
881
964
|
}, "flush");
|
|
882
|
-
if (showGreeting) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
965
|
+
if (showGreeting && !data.reward) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
883
966
|
for (const item of data.line) {
|
|
884
967
|
if (item.type === 0 /* title */) {
|
|
885
968
|
flush();
|
|
886
|
-
|
|
969
|
+
if (rewardMessage) bodyLines.push(renderRewardTitle(item.content));
|
|
970
|
+
else sections.push(renderQQTitle(item.content));
|
|
887
971
|
continue;
|
|
888
972
|
}
|
|
889
973
|
if (item.type === 2 /* error */) {
|
|
890
974
|
flush();
|
|
891
|
-
sections.push(`❌ 出错了!错误原因:${
|
|
975
|
+
sections.push(`❌ 出错了!错误原因:${renderInlineCommands(item.content)},请反馈至联系开发者`);
|
|
892
976
|
continue;
|
|
893
977
|
}
|
|
894
978
|
if (item.type !== 1 /* line */) continue;
|
|
979
|
+
if (item.reward) {
|
|
980
|
+
flushBody();
|
|
981
|
+
flushActions();
|
|
982
|
+
const reward = renderRewardLine(item.content);
|
|
983
|
+
if (reward) rewardLines.push(reward);
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
flushRewards();
|
|
895
987
|
const action = data.transaction && (item.content === "[是]确认交易" ? { command: "是", label: "确认交易" } : item.content === "[否]取消交易" ? { command: "否", label: "取消交易" } : void 0);
|
|
896
988
|
if (action) {
|
|
897
989
|
flushBody();
|
|
@@ -908,7 +1000,7 @@ function renderQQTransactionMarkdown(data, showGreeting) {
|
|
|
908
1000
|
flushBody();
|
|
909
1001
|
sections.push(`**${escapeMarkdown(section?.[1] ?? "还缺")}**`);
|
|
910
1002
|
} else {
|
|
911
|
-
bodyLines.push(
|
|
1003
|
+
bodyLines.push(renderInlineCommands(item.content));
|
|
912
1004
|
}
|
|
913
1005
|
}
|
|
914
1006
|
flush();
|
|
@@ -921,44 +1013,49 @@ async function sendQQTransaction(session, data) {
|
|
|
921
1013
|
__name(sendQQTransaction, "sendQQTransaction");
|
|
922
1014
|
|
|
923
1015
|
// src/plugin/serverHandel/qqCommandMessage.ts
|
|
924
|
-
function renderCommandLine(content, commandHelp) {
|
|
925
|
-
if (!commandHelp || !/^\s*\[[^\[\]\r\n]+\]/.test(content)) return escapeMarkdown(content);
|
|
926
|
-
const parts = [];
|
|
927
|
-
let offset = 0;
|
|
928
|
-
for (const match of content.matchAll(/\[([^\[\]\r\n]+)\]/g)) {
|
|
929
|
-
parts.push(escapeMarkdown(content.slice(offset, match.index)));
|
|
930
|
-
const command = match[1].split(/[++]/, 1)[0].trim();
|
|
931
|
-
parts.push(command ? `[${escapeMarkdown(match[1])}](${inlineCommandUrl(command)})` : escapeMarkdown(match[0]));
|
|
932
|
-
offset = match.index + match[0].length;
|
|
933
|
-
}
|
|
934
|
-
parts.push(escapeMarkdown(content.slice(offset)));
|
|
935
|
-
return parts.join("");
|
|
936
|
-
}
|
|
937
|
-
__name(renderCommandLine, "renderCommandLine");
|
|
938
1016
|
function renderQQCommandMarkdown(data, showGreeting) {
|
|
1017
|
+
const rewardMessage = isRewardMessage(data);
|
|
1018
|
+
if (!data.commandHelp && !data.pageNav && data.line.some((item) => item.type === 1 /* line */ && !item.reward && /^\[\d+\]\s*[^\r\n]+$/.test(item.content))) {
|
|
1019
|
+
return renderQQPageMarkdown(data, showGreeting);
|
|
1020
|
+
}
|
|
939
1021
|
const sections = [];
|
|
940
1022
|
const bodyLines = [];
|
|
1023
|
+
const rewardLines = [];
|
|
941
1024
|
const flushBody = /* @__PURE__ */ __name(() => {
|
|
942
1025
|
if (bodyLines.length) sections.push(bodyLines.splice(0).join(" \n"));
|
|
943
1026
|
}, "flushBody");
|
|
944
|
-
|
|
1027
|
+
const flushRewards = /* @__PURE__ */ __name(() => {
|
|
1028
|
+
if (rewardLines.length) sections.push(rewardLines.splice(0).join(" \n"));
|
|
1029
|
+
}, "flushRewards");
|
|
1030
|
+
if (showGreeting && !data.reward) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
945
1031
|
for (const item of data.line) {
|
|
946
1032
|
switch (item.type) {
|
|
947
1033
|
case 0 /* title */:
|
|
948
1034
|
flushBody();
|
|
949
|
-
|
|
1035
|
+
flushRewards();
|
|
1036
|
+
if (rewardMessage) bodyLines.push(renderRewardTitle(item.content));
|
|
1037
|
+
else sections.push(renderQQTitle(item.content));
|
|
950
1038
|
break;
|
|
951
1039
|
case 1 /* line */:
|
|
1040
|
+
if (item.reward) {
|
|
1041
|
+
flushBody();
|
|
1042
|
+
const reward = renderRewardLine(item.content);
|
|
1043
|
+
if (reward) rewardLines.push(reward);
|
|
1044
|
+
break;
|
|
1045
|
+
}
|
|
1046
|
+
flushRewards();
|
|
952
1047
|
if (!item.content.trim()) flushBody();
|
|
953
|
-
else bodyLines.push(
|
|
1048
|
+
else bodyLines.push(renderInlineCommands(item.content));
|
|
954
1049
|
break;
|
|
955
1050
|
case 2 /* error */:
|
|
956
1051
|
flushBody();
|
|
957
|
-
|
|
1052
|
+
flushRewards();
|
|
1053
|
+
sections.push(`❌ 出错了!错误原因:${renderInlineCommands(item.content)},请反馈至联系开发者`);
|
|
958
1054
|
break;
|
|
959
1055
|
}
|
|
960
1056
|
}
|
|
961
1057
|
flushBody();
|
|
1058
|
+
flushRewards();
|
|
962
1059
|
return sections.join("\n\n") || " ";
|
|
963
1060
|
}
|
|
964
1061
|
__name(renderQQCommandMarkdown, "renderQQCommandMarkdown");
|
|
@@ -967,6 +1064,73 @@ async function sendQQCommand(session, data) {
|
|
|
967
1064
|
}
|
|
968
1065
|
__name(sendQQCommand, "sendQQCommand");
|
|
969
1066
|
|
|
1067
|
+
// src/plugin/serverHandel/qqStoryMessage.ts
|
|
1068
|
+
function hasStoryCodeBlock(data) {
|
|
1069
|
+
return data.line.some((item) => item.type === 1 /* line */ && item.codeBlock === true);
|
|
1070
|
+
}
|
|
1071
|
+
__name(hasStoryCodeBlock, "hasStoryCodeBlock");
|
|
1072
|
+
function fencedStory(content) {
|
|
1073
|
+
const story = content.replace(/\r\n?/g, "\n");
|
|
1074
|
+
const longestRun = Math.max(0, ...Array.from(story.matchAll(/`+/g), (match) => match[0].length));
|
|
1075
|
+
const fence = "`".repeat(Math.max(3, longestRun + 1));
|
|
1076
|
+
return fence + "\n" + story + (story.endsWith("\n") ? "" : "\n") + fence;
|
|
1077
|
+
}
|
|
1078
|
+
__name(fencedStory, "fencedStory");
|
|
1079
|
+
function renderQQStoryMarkdown(data, showGreeting) {
|
|
1080
|
+
const rewardMessage = isRewardMessage(data);
|
|
1081
|
+
const sections = [];
|
|
1082
|
+
const bodyLines = [];
|
|
1083
|
+
const rewardLines = [];
|
|
1084
|
+
const flushBody = /* @__PURE__ */ __name(() => {
|
|
1085
|
+
if (bodyLines.length) sections.push(bodyLines.splice(0).join(" \n"));
|
|
1086
|
+
}, "flushBody");
|
|
1087
|
+
const flushRewards = /* @__PURE__ */ __name(() => {
|
|
1088
|
+
if (rewardLines.length) sections.push(rewardLines.splice(0).join(" \n"));
|
|
1089
|
+
}, "flushRewards");
|
|
1090
|
+
if (showGreeting && !data.reward) sections.push(escapeMarkdown("Ciallo~(∠・ω< )"));
|
|
1091
|
+
for (const item of data.line) {
|
|
1092
|
+
switch (item.type) {
|
|
1093
|
+
case 0 /* title */:
|
|
1094
|
+
flushBody();
|
|
1095
|
+
if (!data.reward) flushRewards();
|
|
1096
|
+
if (rewardMessage) bodyLines.push(renderRewardTitle(item.content));
|
|
1097
|
+
else sections.push(renderQQTitle(item.content));
|
|
1098
|
+
break;
|
|
1099
|
+
case 1 /* line */:
|
|
1100
|
+
if (item.reward) {
|
|
1101
|
+
if (!data.reward) flushBody();
|
|
1102
|
+
const reward = renderRewardLine(item.content);
|
|
1103
|
+
if (reward) rewardLines.push(reward);
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
if (!data.reward) flushRewards();
|
|
1107
|
+
if (item.codeBlock) {
|
|
1108
|
+
flushBody();
|
|
1109
|
+
sections.push(fencedStory(item.content));
|
|
1110
|
+
} else {
|
|
1111
|
+
for (const line of item.content.replace(/\r\n?/g, "\n").split("\n")) {
|
|
1112
|
+
if (!line.trim()) flushBody();
|
|
1113
|
+
else bodyLines.push(data.reward ? escapeMarkdown(line) : renderInlineCommands(line));
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
break;
|
|
1117
|
+
case 2 /* error */:
|
|
1118
|
+
flushBody();
|
|
1119
|
+
if (!data.reward) flushRewards();
|
|
1120
|
+
sections.push("❌ 出错了!错误原因:" + (data.reward ? escapeMarkdown(item.content) : renderInlineCommands(item.content)) + ",请反馈至联系开发者");
|
|
1121
|
+
break;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
flushBody();
|
|
1125
|
+
flushRewards();
|
|
1126
|
+
return sections.join("\n\n") || " ";
|
|
1127
|
+
}
|
|
1128
|
+
__name(renderQQStoryMarkdown, "renderQQStoryMarkdown");
|
|
1129
|
+
async function sendQQStory(session, data) {
|
|
1130
|
+
await sendQQMarkdown(session, renderQQStoryMarkdown(data, session.event?.channel?.type === 0));
|
|
1131
|
+
}
|
|
1132
|
+
__name(sendQQStory, "sendQQStory");
|
|
1133
|
+
|
|
970
1134
|
// src/plugin/serverHandel/text.ts
|
|
971
1135
|
var handelr_text = class extends handel_base {
|
|
972
1136
|
static {
|
|
@@ -975,12 +1139,18 @@ var handelr_text = class extends handel_base {
|
|
|
975
1139
|
async start(data) {
|
|
976
1140
|
const content = new AnalysisMsg().parse(data);
|
|
977
1141
|
const session = sessions_default.get(sessionKey(data.botId, data.userId, data.channelId));
|
|
978
|
-
|
|
1142
|
+
const inlineCommands = data.line.some((item) => (item.type === 1 /* line */ || item.type === 2 /* error */) && hasInlineCommands(item.content));
|
|
1143
|
+
const story = hasStoryCodeBlock(data);
|
|
1144
|
+
const reward = isRewardMessage(data);
|
|
1145
|
+
if ((story || data.commandHelp || data.transaction || data.pageNav || inlineCommands || reward) && canSendQQPage(session, data)) {
|
|
979
1146
|
const sendStartedAt = this.timing ? performance.now() : 0;
|
|
980
1147
|
try {
|
|
981
|
-
if (
|
|
1148
|
+
if (story) await sendQQStory(session, data);
|
|
1149
|
+
else if (data.commandHelp) await sendQQCommand(session, data);
|
|
982
1150
|
else if (data.transaction) await sendQQTransaction(session, data);
|
|
983
|
-
else await sendQQPage(session, data);
|
|
1151
|
+
else if (data.pageNav) await sendQQPage(session, data);
|
|
1152
|
+
else if (reward) await sendQQMarkdown(session, renderQQRewardMarkdown(data, session.event?.channel?.type === 0));
|
|
1153
|
+
else await sendQQCommand(session, data);
|
|
984
1154
|
if (this.timing) {
|
|
985
1155
|
this.timing.delivery = "qq-markdown";
|
|
986
1156
|
this.timing.sendMs = performance.now() - sendStartedAt;
|
|
@@ -989,7 +1159,7 @@ var handelr_text = class extends handel_base {
|
|
|
989
1159
|
} catch (error) {
|
|
990
1160
|
this.ctx.logger.warn("QQ Markdown 发送失败,改用普通文字", error instanceof Error ? error.message : error);
|
|
991
1161
|
}
|
|
992
|
-
const commands = !data.commandHelp && !data.transaction && data.pageNav ? pageCommandLines(data.pageNav) : [];
|
|
1162
|
+
const commands = !story && !data.commandHelp && !data.transaction && data.pageNav ? pageCommandLines(data.pageNav) : [];
|
|
993
1163
|
await this.send(data, commands.length ? `${content.trimEnd()}
|
|
994
1164
|
${commands.join("\n")}` : content);
|
|
995
1165
|
return;
|
|
@@ -998,6 +1168,38 @@ ${commands.join("\n")}` : content);
|
|
|
998
1168
|
}
|
|
999
1169
|
};
|
|
1000
1170
|
|
|
1171
|
+
// src/plugin/serverHandel/image.ts
|
|
1172
|
+
var ImageHandler = class extends handel_base {
|
|
1173
|
+
static {
|
|
1174
|
+
__name(this, "ImageHandler");
|
|
1175
|
+
}
|
|
1176
|
+
async start(data) {
|
|
1177
|
+
let content = "";
|
|
1178
|
+
let rendered = false;
|
|
1179
|
+
const renderStartedAt = this.timing ? performance.now() : 0;
|
|
1180
|
+
try {
|
|
1181
|
+
if (!data.characterCard && !data.itemCard && !data.card && !data.leaderboard && !data.equipmentCard) throw new Error("缺少卡片数据");
|
|
1182
|
+
const image = await renderSkillCard(this.ctx, data.card, data.leaderboard, data.itemCard, data.characterCard, data.equipmentCard);
|
|
1183
|
+
if (this.timing) this.timing.imageBytes = image.length;
|
|
1184
|
+
content = import_koishi.h.image(image, "image/jpeg").toString();
|
|
1185
|
+
rendered = true;
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
this.ctx.logger.warn("卡片绘制失败,使用文字详情", error instanceof Error ? error.message : "unknown");
|
|
1188
|
+
} finally {
|
|
1189
|
+
if (this.timing) this.timing.renderMs = performance.now() - renderStartedAt;
|
|
1190
|
+
}
|
|
1191
|
+
if (!rendered) {
|
|
1192
|
+
const fallback = new handelr_text(data);
|
|
1193
|
+
fallback.set(this.ctx);
|
|
1194
|
+
if (this.timing) fallback.setTiming(this.timing);
|
|
1195
|
+
fallback.send = (message, text, type = "text") => this.send(message, text, type);
|
|
1196
|
+
await fallback.start(data);
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
await this.send(data, content, "image");
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1001
1203
|
// src/plugin/messageQueue.ts
|
|
1002
1204
|
var handlers = {
|
|
1003
1205
|
["text" /* text */]: handelr_text,
|
|
@@ -1062,7 +1264,7 @@ var import_tsrpc = require("tsrpc");
|
|
|
1062
1264
|
|
|
1063
1265
|
// src/shared/bot/serviceProto.ts
|
|
1064
1266
|
var serviceProto = {
|
|
1065
|
-
"version":
|
|
1267
|
+
"version": 15,
|
|
1066
1268
|
"services": [
|
|
1067
1269
|
{
|
|
1068
1270
|
"id": 0,
|
|
@@ -1213,6 +1415,14 @@ var serviceProto = {
|
|
|
1213
1415
|
},
|
|
1214
1416
|
"optional": true
|
|
1215
1417
|
},
|
|
1418
|
+
{
|
|
1419
|
+
"id": 10,
|
|
1420
|
+
"name": "reward",
|
|
1421
|
+
"type": {
|
|
1422
|
+
"type": "Boolean"
|
|
1423
|
+
},
|
|
1424
|
+
"optional": true
|
|
1425
|
+
},
|
|
1216
1426
|
{
|
|
1217
1427
|
"id": 1,
|
|
1218
1428
|
"name": "line",
|
|
@@ -1949,6 +2159,22 @@ var serviceProto = {
|
|
|
1949
2159
|
"type": {
|
|
1950
2160
|
"type": "String"
|
|
1951
2161
|
}
|
|
2162
|
+
},
|
|
2163
|
+
{
|
|
2164
|
+
"id": 2,
|
|
2165
|
+
"name": "codeBlock",
|
|
2166
|
+
"type": {
|
|
2167
|
+
"type": "Boolean"
|
|
2168
|
+
},
|
|
2169
|
+
"optional": true
|
|
2170
|
+
},
|
|
2171
|
+
{
|
|
2172
|
+
"id": 3,
|
|
2173
|
+
"name": "reward",
|
|
2174
|
+
"type": {
|
|
2175
|
+
"type": "Boolean"
|
|
2176
|
+
},
|
|
2177
|
+
"optional": true
|
|
1952
2178
|
}
|
|
1953
2179
|
]
|
|
1954
2180
|
},
|
|
@@ -2280,10 +2506,6 @@ var usage = `
|
|
|
2280
2506
|
踏入主神空间,成为轮回者。与伙伴迎接未知的试炼,在生死之间积蓄力量,书写属于你的无限冒险。
|
|
2281
2507
|
|
|
2282
2508
|
无论你熟悉原作,还是初次踏入无限流世界,这场轮回,都有你的位置。
|
|
2283
|
-
|
|
2284
|
-
---
|
|
2285
|
-
|
|
2286
|
-
连接 DEW 游戏服后,在聊天中发送 **帮助**,开启第一场冒险。
|
|
2287
2509
|
`;
|
|
2288
2510
|
var Config = import_koishi2.Schema.object({
|
|
2289
2511
|
服务器地址: import_koishi2.Schema.string().default("ws://dew-v7-test:3021").description("DEW 游戏服的 WebSocket 地址;同机部署可填写 ws://127.0.0.1:3021")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Session } from 'koishi';
|
|
2
2
|
import type { MsgMessage } from '../../shared/bot/MsgMessage';
|
|
3
|
-
/**
|
|
3
|
+
/** Render command help and ordinary prose with clickable bracketed commands. */
|
|
4
4
|
export declare function renderQQCommandMarkdown(data: MsgMessage, showGreeting: boolean): string;
|
|
5
5
|
export declare function sendQQCommand(session: Session, data: MsgMessage): Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Escape server-provided text before embedding it in native QQ Markdown. */
|
|
2
|
+
export declare function escapeMarkdown(value: string): string;
|
|
3
|
+
/** Compact display padding while retaining spaces between English words. */
|
|
4
|
+
export declare function compactDisplayText(value: string): string;
|
|
5
|
+
/** Keep existing menu, help and transaction titles consistent. */
|
|
6
|
+
export declare function renderQQTitle(content: string): string;
|