koishi-plugin-make-a-choice 1.0.0 → 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 +24 -26
- package/package.json +4 -4
- package/src/index.ts +24 -26
package/lib/index.js
CHANGED
|
@@ -8,32 +8,30 @@ exports.Config = koishi_1.Schema.object({
|
|
|
8
8
|
wakeWords: koishi_1.Schema.array(koishi_1.Schema.string()).default(['选择', '帮选', '决定']).description('触发插件的唤醒词列表。'),
|
|
9
9
|
});
|
|
10
10
|
function apply(ctx, config) {
|
|
11
|
-
const wakeWords = config.wakeWords.map(word => word.trim()).filter(Boolean);
|
|
11
|
+
const wakeWords = Array.from(new Set(config.wakeWords.map(word => word.trim()).filter(Boolean)));
|
|
12
12
|
if (!wakeWords.length)
|
|
13
13
|
return;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
await session.send(`我建议${choice}`);
|
|
38
|
-
});
|
|
14
|
+
const handleChoice = async (payload) => {
|
|
15
|
+
const text = payload === null || payload === void 0 ? void 0 : payload.trim();
|
|
16
|
+
if (!text)
|
|
17
|
+
return '请按照“A 还是 B 还是 C”的格式提供多个选项。';
|
|
18
|
+
if (!text.includes('还是'))
|
|
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)
|
|
25
|
+
return '我不知道是谁都选好了还在问我◖⚆ᴥ⚆◗';
|
|
26
|
+
const choice = options[Math.floor(Math.random() * options.length)];
|
|
27
|
+
return `我建议${choice}`;
|
|
28
|
+
};
|
|
29
|
+
for (const word of wakeWords) {
|
|
30
|
+
ctx
|
|
31
|
+
.command(`${word} <payload:text>`, '在多个选项之间随机选择')
|
|
32
|
+
.shortcut(word, { prefix: true })
|
|
33
|
+
.usage(`示例:${word} 选项A 还是 选项B 还是 选项C`)
|
|
34
|
+
.example(`${word} 猫 还是 狗 还是 狐狸`)
|
|
35
|
+
.action(async ({ session }, payload) => handleChoice(payload));
|
|
36
|
+
}
|
|
39
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
|
@@ -11,32 +11,30 @@ export const Config: Schema<Config> = Schema.object({
|
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
export function apply(ctx: Context, config: Config) {
|
|
14
|
-
const wakeWords = config.wakeWords.map(word => word.trim()).filter(Boolean)
|
|
14
|
+
const wakeWords = Array.from(new Set(config.wakeWords.map(word => word.trim()).filter(Boolean)))
|
|
15
15
|
if (!wakeWords.length) return
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
await session.send(`我建议${choice}`)
|
|
41
|
-
})
|
|
17
|
+
const handleChoice = async (payload: string | undefined) => {
|
|
18
|
+
const text = payload?.trim()
|
|
19
|
+
if (!text) return '请按照“A 还是 B 还是 C”的格式提供多个选项。'
|
|
20
|
+
if (!text.includes('还是')) return '请用“A 还是 B”的格式,让我能拆分多个选项。'
|
|
21
|
+
|
|
22
|
+
const options = text.split(/\s*还是\s*/).map(opt => opt.trim()).filter(Boolean)
|
|
23
|
+
if (options.length < 2) return '请提供至少两个有效的选项。'
|
|
24
|
+
|
|
25
|
+
const uniqueOptions = new Set(options)
|
|
26
|
+
if (uniqueOptions.size === 1) return '我不知道是谁都选好了还在问我◖⚆ᴥ⚆◗'
|
|
27
|
+
|
|
28
|
+
const choice = options[Math.floor(Math.random() * options.length)]
|
|
29
|
+
return `我建议${choice}`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (const word of wakeWords) {
|
|
33
|
+
ctx
|
|
34
|
+
.command(`${word} <payload:text>`, '在多个选项之间随机选择')
|
|
35
|
+
.shortcut(word, { prefix: true })
|
|
36
|
+
.usage(`示例:${word} 选项A 还是 选项B 还是 选项C`)
|
|
37
|
+
.example(`${word} 猫 还是 狗 还是 狐狸`)
|
|
38
|
+
.action(async ({ session }, payload) => handleChoice(payload))
|
|
39
|
+
}
|
|
42
40
|
}
|