1+ @file:Suppress(" TooManyFunctions" )
2+
13package org.ntqqrev.saltify.extension
24
5+ import org.ntqqrev.milky.IncomingSegment
36import org.ntqqrev.saltify.dsl.SaltifyParameterBuilder
47import org.ntqqrev.saltify.runtime.command.CommandParameter
58import org.ntqqrev.saltify.runtime.context.CommandExecutionContext
@@ -8,34 +11,64 @@ import org.ntqqrev.saltify.runtime.context.CommandExecutionContext
811 * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
912 */
1013public fun SaltifyParameterBuilder.string (name : String , desc : String = ""): CommandParameter <String > =
11- from(name, desc) { it }
14+ from(name, desc) { (it as ? IncomingSegment . Text )?.text }
1215
1316/* *
1417 * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
1518 */
1619public fun SaltifyParameterBuilder.int (name : String , desc : String = ""): CommandParameter <Int > =
17- from(name, desc) { it .toIntOrNull() }
20+ from(name, desc) { (it as ? IncomingSegment . Text )?.text? .toIntOrNull() }
1821
1922/* *
2023 * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
2124 */
2225public fun SaltifyParameterBuilder.long (name : String , desc : String = ""): CommandParameter <Long > =
23- from(name, desc) { it .toLongOrNull() }
26+ from(name, desc) { (it as ? IncomingSegment . Text )?.text? .toLongOrNull() }
2427
2528/* *
2629 * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
2730 */
2831public fun SaltifyParameterBuilder.boolean (name : String , desc : String = ""): CommandParameter <Boolean > =
29- from(name, desc) { it .toBooleanStrictOrNull() }
32+ from(name, desc) { (it as ? IncomingSegment . Text )?.text? .toBooleanStrictOrNull() }
3033
3134/* *
3235 * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
3336 */
3437public fun SaltifyParameterBuilder.double (name : String , desc : String = ""): CommandParameter <Double > =
35- from(name, desc) { it .toDoubleOrNull() }
38+ from(name, desc) { (it as ? IncomingSegment . Text )?.text? .toDoubleOrNull() }
3639
3740/* *
3841 * 定义一个贪婪字符串参数。该参数会捕获剩余的**所有**文本内容。请搭配 [CommandExecutionContext.value] 使用。
3942 */
4043public fun SaltifyParameterBuilder.greedyString (name : String , desc : String = ""): CommandParameter <String > =
41- from(name, desc, isGreedy = true ) { it }
44+ from(name, desc, isGreedy = true ) { (it as ? IncomingSegment .Text )?.text }
45+
46+ /* *
47+ * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
48+ */
49+ public fun SaltifyParameterBuilder.image (name : String , desc : String = ""): CommandParameter <IncomingSegment .Image .Data > =
50+ from(name, desc) { (it as ? IncomingSegment .Image )?.data }
51+
52+ /* *
53+ * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
54+ */
55+ public fun SaltifyParameterBuilder.mention (name : String , desc : String = ""): CommandParameter <IncomingSegment .Mention .Data > =
56+ from(name, desc) { (it as ? IncomingSegment .Mention )?.data }
57+
58+ /* *
59+ * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
60+ */
61+ public fun SaltifyParameterBuilder.mentionAll (name : String , desc : String = ""): CommandParameter <Unit > =
62+ from(name, desc) { if (it is IncomingSegment .MentionAll ) Unit else null }
63+
64+ /* *
65+ * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
66+ */
67+ public fun SaltifyParameterBuilder.face (name : String , desc : String = ""): CommandParameter <IncomingSegment .Face .Data > =
68+ from(name, desc) { (it as ? IncomingSegment .Face )?.data }
69+
70+ /* *
71+ * 定义一个指令参数。请搭配 [CommandExecutionContext.value] 使用。
72+ */
73+ public fun SaltifyParameterBuilder.reply (name : String , desc : String = ""): CommandParameter <IncomingSegment .Reply .Data > =
74+ from(name, desc) { (it as ? IncomingSegment .Reply )?.data }
0 commit comments