Simplify code

This commit is contained in:
Him188 2019-12-04 20:43:29 +08:00
parent a5853ba28a
commit f3f8be5fb6

View File

@ -132,20 +132,19 @@ suspend fun main() {
}
has<Image> {
if (this is FriendMessage || (this is GroupMessage && this.permission == MemberPermission.ADMINISTRATOR)) {
withContext(IO) {
val image: Image by message
// 等同于 val image = message[Image]
if (this is FriendMessage || (this is GroupMessage && this.permission == MemberPermission.ADMINISTRATOR)) withContext(IO) {
val image: Image by message
// 等同于 val image = message[Image]
try {
image.downloadTo(newTestTempFile(suffix = ".png").also { reply("Temp file: ${it.absolutePath}") })
reply(image.id.value + " downloaded")
} catch (e: Exception) {
e.printStackTrace()
reply(e.message ?: e::class.java.simpleName)
}
try {
image.downloadTo(newTestTempFile(suffix = ".png").also { reply("Temp file: ${it.absolutePath}") })
reply(image.id.value + " downloaded")
} catch (e: Exception) {
e.printStackTrace()
reply(e.message ?: e::class.java.simpleName)
}
}
}
startsWith("上传图片", removePrefix = true) handler@{