From 19e980be86f3bcef6352bf165d47beede0c14e8e Mon Sep 17 00:00:00 2001 From: RTAkland Date: Wed, 25 Sep 2024 18:18:28 +0800 Subject: [PATCH] chore: format code and add qodana --- qodana.yaml | 31 +++++++++++++++++++ .../commands/lookup/NslookupCommand.kt | 6 +++- .../commands/parse/AsciiArtCommand.kt | 6 +++- .../kotlin/cn/rtast/fancybot/util/Http.kt | 4 +-- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 qodana.yaml diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000..08a316b --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,31 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +projectJDK: 17 #(Applied in CI/CD pipeline) + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-jvm:latest diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt index 9b3650a..74251e0 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt @@ -11,6 +11,8 @@ import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.util.BaseCommand import cn.rtast.rob.util.ob.MessageChain import cn.rtast.rob.util.ob.OneBotListener +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import java.net.InetAddress class NslookupCommand : BaseCommand() { @@ -20,7 +22,9 @@ class NslookupCommand : BaseCommand() { val msg = MessageChain.Builder() .addReply(message.messageId) .addText("域名: ${args.first()}解析后的IP地址为: ") - .addText(InetAddress.getByName(args.first()).hostAddress) + .addText(withContext(Dispatchers.IO) { + InetAddress.getByName(args.first()) + }.hostAddress) .build() listener.sendGroupMessage(message.groupId, msg) } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt index a5f4e12..8bebcc5 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt @@ -14,6 +14,8 @@ import cn.rtast.rob.enums.ArrayMessageType import cn.rtast.rob.util.BaseCommand import cn.rtast.rob.util.ob.MessageChain import cn.rtast.rob.util.ob.OneBotListener +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import java.awt.Color import java.awt.Font import java.awt.image.BufferedImage @@ -84,7 +86,9 @@ class AsciiArtCommand : BaseCommand() { if (message.sender.userId in waitingList) { if (message.message.any { it.type == ArrayMessageType.image }) { val url = message.message.find { it.type == ArrayMessageType.image }!!.data.file!! - val bufferedImage = ImageIO.read(URI(url).toURL()) + val bufferedImage = withContext(Dispatchers.IO) { + ImageIO.read(URI(url).toURL()) + } val imageBase64 = bufferedImage.convertToAscii().saveAsciiArtToImage(bufferedImage.width, bufferedImage.height) val msg = MessageChain.Builder().addImage(imageBase64, true).build() diff --git a/src/main/kotlin/cn/rtast/fancybot/util/Http.kt b/src/main/kotlin/cn/rtast/fancybot/util/Http.kt index b25dc8a..5455875 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/Http.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/Http.kt @@ -16,8 +16,8 @@ import okhttp3.RequestBody.Companion.toRequestBody object Http { - val jsonMediaType = "application/json; charset=utf-8".toMediaType() - val jsonHeader = mapOf( + private val jsonMediaType = "application/json; charset=utf-8".toMediaType() + private val jsonHeader = mapOf( "Content-Type" to "application/json; charset=utf-8", "Accept" to "application/json" )