koishi-plugin-make-a-choice 1.0.1 → 1.0.2
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.js +11 -14
- package/package.json +4 -4
- package/src/index.ts +10 -12
package/lib/index.js
CHANGED
|
@@ -14,27 +14,24 @@ function apply(ctx, config) {
|
|
|
14
14
|
const handleChoice = async (payload) => {
|
|
15
15
|
const text = payload === null || payload === void 0 ? void 0 : payload.trim();
|
|
16
16
|
if (!text)
|
|
17
|
-
return '
|
|
17
|
+
return '请按照“A 还是 B 还是 C”的格式提供多个选项。';
|
|
18
18
|
if (!text.includes('还是'))
|
|
19
|
-
return '
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
return '
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (!left || !right)
|
|
26
|
-
return '两个选项都要提供哦。';
|
|
27
|
-
if (left === right)
|
|
19
|
+
return '请用“A 还是 B”的格式,让我能拆分多个选项。';
|
|
20
|
+
const options = text.split(/\s*还是\s*/).map(opt => opt.trim()).filter(Boolean);
|
|
21
|
+
if (options.length < 2)
|
|
22
|
+
return '请提供至少两个有效的选项。';
|
|
23
|
+
const uniqueOptions = new Set(options);
|
|
24
|
+
if (uniqueOptions.size === 1)
|
|
28
25
|
return '我不知道是谁都选好了还在问我◖⚆ᴥ⚆◗';
|
|
29
|
-
const choice = Math.random()
|
|
26
|
+
const choice = options[Math.floor(Math.random() * options.length)];
|
|
30
27
|
return `我建议${choice}`;
|
|
31
28
|
};
|
|
32
29
|
for (const word of wakeWords) {
|
|
33
30
|
ctx
|
|
34
|
-
.command(`${word} <payload:text>`, '
|
|
31
|
+
.command(`${word} <payload:text>`, '在多个选项之间随机选择')
|
|
35
32
|
.shortcut(word, { prefix: true })
|
|
36
|
-
.usage(`示例:${word}
|
|
37
|
-
.example(`${word} 猫 还是
|
|
33
|
+
.usage(`示例:${word} 选项A 还是 选项B 还是 选项C`)
|
|
34
|
+
.example(`${word} 猫 还是 狗 还是 狐狸`)
|
|
38
35
|
.action(async ({ session }, payload) => handleChoice(payload));
|
|
39
36
|
}
|
|
40
37
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-make-a-choice",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Pick between
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Pick between multiple options after a wake word.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"type": "commonjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
],
|
|
32
32
|
"koishi": {
|
|
33
33
|
"description": {
|
|
34
|
-
"en": "Pick between
|
|
35
|
-
"zh-CN": "设定唤醒词后,在“xx还是xx
|
|
34
|
+
"en": "Pick between multiple options after a wake word",
|
|
35
|
+
"zh-CN": "设定唤醒词后,在“xx还是xx还是xx......”之间随机选择"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -16,27 +16,25 @@ export function apply(ctx: Context, config: Config) {
|
|
|
16
16
|
|
|
17
17
|
const handleChoice = async (payload: string | undefined) => {
|
|
18
18
|
const text = payload?.trim()
|
|
19
|
-
if (!text) return '
|
|
20
|
-
if (!text.includes('还是')) return '
|
|
19
|
+
if (!text) return '请按照“A 还是 B 还是 C”的格式提供多个选项。'
|
|
20
|
+
if (!text.includes('还是')) return '请用“A 还是 B”的格式,让我能拆分多个选项。'
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
22
|
+
const options = text.split(/\s*还是\s*/).map(opt => opt.trim()).filter(Boolean)
|
|
23
|
+
if (options.length < 2) return '请提供至少两个有效的选项。'
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
if (!left || !right) return '两个选项都要提供哦。'
|
|
28
|
-
if (left === right) return '我不知道是谁都选好了还在问我◖⚆ᴥ⚆◗'
|
|
25
|
+
const uniqueOptions = new Set(options)
|
|
26
|
+
if (uniqueOptions.size === 1) return '我不知道是谁都选好了还在问我◖⚆ᴥ⚆◗'
|
|
29
27
|
|
|
30
|
-
const choice = Math.random()
|
|
28
|
+
const choice = options[Math.floor(Math.random() * options.length)]
|
|
31
29
|
return `我建议${choice}`
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
for (const word of wakeWords) {
|
|
35
33
|
ctx
|
|
36
|
-
.command(`${word} <payload:text>`, '
|
|
34
|
+
.command(`${word} <payload:text>`, '在多个选项之间随机选择')
|
|
37
35
|
.shortcut(word, { prefix: true })
|
|
38
|
-
.usage(`示例:${word}
|
|
39
|
-
.example(`${word} 猫 还是
|
|
36
|
+
.usage(`示例:${word} 选项A 还是 选项B 还是 选项C`)
|
|
37
|
+
.example(`${word} 猫 还是 狗 还是 狐狸`)
|
|
40
38
|
.action(async ({ session }, payload) => handleChoice(payload))
|
|
41
39
|
}
|
|
42
40
|
}
|