From f3f8be5fb6525cba15d25a1391d35b480c1d4238 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 4 Dec 2019 20:43:29 +0800 Subject: [PATCH] Simplify code --- .../src/main/kotlin/demo/gentleman/Main.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt b/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt index f2c06c834..a0479a863 100644 --- a/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt +++ b/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt @@ -132,20 +132,19 @@ suspend fun main() { } has { - 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@{