koishi-plugin-ciyi 0.0.6 → 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 CHANGED
@@ -6,6 +6,8 @@ export interface Config {
6
6
  atReply: boolean;
7
7
  quoteReply: boolean;
8
8
  isEnableMiddleware: boolean;
9
+ maxHistory: number;
10
+ maxRank: number;
9
11
  }
10
12
  export declare const Config: Schema<Config>;
11
13
  declare module 'koishi' {
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).description("最大历史记录数,值为 0 时不限制"),
46
+ maxRank: import_koishi.Schema.number().default(10).description("最大排行榜人数,值为 0 时不限制")
45
47
  });
46
48
  function apply(ctx, cfg) {
47
49
  ctx.model.extend("ciyi", {
@@ -93,20 +95,18 @@ function apply(ctx, cfg) {
93
95
  });
94
96
  function formatCiyiRanks(ranks) {
95
97
  ranks.sort((a, b) => b.score - a.score);
96
- const top10Ranks = ranks.slice(0, 10);
97
- return top10Ranks.map((rank, index) => {
98
+ const topMaxRanks = ranks.slice(0, cfg.maxRank || void 0);
99
+ return topMaxRanks.map((rank, index) => {
98
100
  return `${index + 1}. ${rank.username} ${rank.score}`;
99
101
  }).join("\n");
100
102
  }
101
103
  __name(formatCiyiRanks, "formatCiyiRanks");
102
104
  function formatHistories(histories) {
103
- histories.sort((a, b) => a.rank - b.rank);
104
- const formattedStrings = histories.map((history, index) => {
105
+ return histories.sort((a, b) => a.rank - b.rank).slice(0, cfg.maxHistory || void 0).map((history, index) => {
105
106
  const leftHintChar = history.leftHint.length > 1 ? history.leftHint[1] : "?";
106
107
  const rightHintChar = history.rightHint.length > 0 ? history.rightHint[0] : "?";
107
108
  return `${index + 1}. ?${leftHintChar})${history.guess}(${rightHintChar}? ${history.rank}`;
108
- });
109
- return formattedStrings.join("\n");
109
+ }).join("\n");
110
110
  }
111
111
  __name(formatHistories, "formatHistories");
112
112
  function getHistory(targetString, stringArray) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ciyi",
3
3
  "description": "Koishi 的词意(猜词游戏)插件。根据词语的含义相似程度,猜测正确的词语。",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [