koishi-plugin-ciyi 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 +2 -0
- package/lib/index.js +17 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -41,7 +41,9 @@ var inject = ["database"];
|
|
|
41
41
|
var Config = import_koishi.Schema.object({
|
|
42
42
|
atReply: import_koishi.Schema.boolean().default(true).description("响应时 @"),
|
|
43
43
|
quoteReply: import_koishi.Schema.boolean().default(false).description("响应时引用"),
|
|
44
|
-
isEnableMiddleware: import_koishi.Schema.boolean().default(true).description("是否启用中间件,若启用,猜测词语时可以不加前缀")
|
|
44
|
+
isEnableMiddleware: import_koishi.Schema.boolean().default(true).description("是否启用中间件,若启用,猜测词语时可以不加前缀"),
|
|
45
|
+
maxHistory: import_koishi.Schema.number().default(20).min(0).description("最大历史记录数"),
|
|
46
|
+
maxRank: import_koishi.Schema.number().default(10).min(0).description("最大排行榜人数")
|
|
45
47
|
});
|
|
46
48
|
function apply(ctx, cfg) {
|
|
47
49
|
ctx.model.extend("ciyi", {
|
|
@@ -93,20 +95,28 @@ function apply(ctx, cfg) {
|
|
|
93
95
|
});
|
|
94
96
|
function formatCiyiRanks(ranks) {
|
|
95
97
|
ranks.sort((a, b) => b.score - a.score);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
+
const maxRank = cfg.maxRank;
|
|
99
|
+
const needsSlicing = maxRank !== void 0 && maxRank < ranks.length;
|
|
100
|
+
const slicedRanks = needsSlicing ? ranks.slice(0, maxRank) : ranks;
|
|
101
|
+
const formattedString = slicedRanks.map((rank, index) => {
|
|
98
102
|
return `${index + 1}. ${rank.username} ${rank.score}`;
|
|
99
103
|
}).join("\n");
|
|
104
|
+
return needsSlicing ? `${formattedString}
|
|
105
|
+
...` : formattedString;
|
|
100
106
|
}
|
|
101
107
|
__name(formatCiyiRanks, "formatCiyiRanks");
|
|
102
108
|
function formatHistories(histories) {
|
|
103
|
-
histories.sort((a, b) => a.rank - b.rank);
|
|
104
|
-
const
|
|
109
|
+
const sortedHistories = histories.sort((a, b) => a.rank - b.rank);
|
|
110
|
+
const maxHistory = cfg.maxHistory;
|
|
111
|
+
const needsSlicing = maxHistory !== void 0 && maxHistory < sortedHistories.length;
|
|
112
|
+
const slicedHistories = needsSlicing ? sortedHistories.slice(0, maxHistory) : sortedHistories;
|
|
113
|
+
const formattedString = slicedHistories.map((history, index) => {
|
|
105
114
|
const leftHintChar = history.leftHint.length > 1 ? history.leftHint[1] : "?";
|
|
106
115
|
const rightHintChar = history.rightHint.length > 0 ? history.rightHint[0] : "?";
|
|
107
116
|
return `${index + 1}. ?${leftHintChar})${history.guess}(${rightHintChar}? ${history.rank}`;
|
|
108
|
-
});
|
|
109
|
-
return
|
|
117
|
+
}).join("\n");
|
|
118
|
+
return needsSlicing ? `${formattedString}
|
|
119
|
+
...` : formattedString;
|
|
110
120
|
}
|
|
111
121
|
__name(formatHistories, "formatHistories");
|
|
112
122
|
function getHistory(targetString, stringArray) {
|