mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 17:00:14 +08:00
Add ImageArgumentParser, fix #183
This commit is contained in:
parent
704674698f
commit
453ad8f9e2
@ -20,6 +20,7 @@ import net.mamoe.mirai.console.permission.PermissionId
|
|||||||
import net.mamoe.mirai.console.permission.PermitteeId
|
import net.mamoe.mirai.console.permission.PermitteeId
|
||||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
|
import net.mamoe.mirai.message.data.Image
|
||||||
import kotlin.internal.LowPriorityInOverloadResolution
|
import kotlin.internal.LowPriorityInOverloadResolution
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.full.isSubclassOf
|
import kotlin.reflect.full.isSubclassOf
|
||||||
@ -74,6 +75,7 @@ public interface CommandArgumentContext {
|
|||||||
Long::class with LongArgumentParser
|
Long::class with LongArgumentParser
|
||||||
Double::class with DoubleArgumentParser
|
Double::class with DoubleArgumentParser
|
||||||
Float::class with FloatArgumentParser
|
Float::class with FloatArgumentParser
|
||||||
|
Image::class with ImageArgumentParser
|
||||||
|
|
||||||
Contact::class with ExistingContactArgumentParser
|
Contact::class with ExistingContactArgumentParser
|
||||||
User::class with ExistingUserArgumentParser
|
User::class with ExistingUserArgumentParser
|
||||||
|
@ -19,10 +19,7 @@ import net.mamoe.mirai.console.permission.PermitteeId
|
|||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
import net.mamoe.mirai.getFriendOrNull
|
import net.mamoe.mirai.getFriendOrNull
|
||||||
import net.mamoe.mirai.getGroupOrNull
|
import net.mamoe.mirai.getGroupOrNull
|
||||||
import net.mamoe.mirai.message.data.At
|
import net.mamoe.mirai.message.data.*
|
||||||
import net.mamoe.mirai.message.data.MessageContent
|
|
||||||
import net.mamoe.mirai.message.data.SingleMessage
|
|
||||||
import net.mamoe.mirai.message.data.content
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,6 +77,24 @@ public object StringArgumentParser : InternalCommandArgumentParserExtensions<Str
|
|||||||
public override fun parse(raw: String, sender: CommandSender): String = raw
|
public override fun parse(raw: String, sender: CommandSender): String = raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析 [String] 通过 [Image].
|
||||||
|
*/
|
||||||
|
public object ImageArgumentParser : InternalCommandArgumentParserExtensions<Image> {
|
||||||
|
public override fun parse(raw: String, sender: CommandSender): Image {
|
||||||
|
return kotlin.runCatching {
|
||||||
|
Image(raw)
|
||||||
|
}.getOrElse {
|
||||||
|
illegalArgument("无法解析 $raw 为图片.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun parse(raw: MessageContent, sender: CommandSender): Image {
|
||||||
|
if (raw is Image) return raw
|
||||||
|
return super.parse(raw, sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当字符串内容为(不区分大小写) "true", "yes", "enabled"
|
* 当字符串内容为(不区分大小写) "true", "yes", "enabled"
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user