chore: introduce logger and save log into file
This commit is contained in:
7 files changed
+56
-9
No files matched your search
@@ -10,10 +10,7 @@ package cn.rtast.fancybot
|
||||
import cn.rtast.fancybot.commands.misc.ScanQRCodeCommand
|
||||
import cn.rtast.fancybot.commands.parse.*
|
||||
import cn.rtast.fancybot.enums.WSType
|
||||
import cn.rtast.fancybot.util.initCommandAndItem
|
||||
import cn.rtast.fancybot.util.initDatabase
|
||||
import cn.rtast.fancybot.util.initFilesDir
|
||||
import cn.rtast.fancybot.util.initSetuIndex
|
||||
import cn.rtast.fancybot.util.*
|
||||
import cn.rtast.rob.ROneBotFactory
|
||||
import cn.rtast.rob.entity.*
|
||||
import cn.rtast.rob.entity.lagrange.FileEvent
|
||||
@@ -30,6 +27,7 @@ import java.net.URI
|
||||
|
||||
class FancyBot : OneBotListener {
|
||||
|
||||
private val logger = Logger.getLogger<FancyBot>()
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.IO)
|
||||
private val githubRegex = Regex("""github\.com/([^/]+)/([^/]+)""")
|
||||
|
||||
@@ -43,7 +41,8 @@ class FancyBot : OneBotListener {
|
||||
val msg = message.rawMessage
|
||||
val groupId = message.groupId
|
||||
val messageId = message.messageId
|
||||
println("$sender($senderId: $groupId >>> $messageId): $msg")
|
||||
logger.info("$sender($senderId: $groupId >>> $messageId): $msg")
|
||||
logger.trace("$sender($senderId: $groupId >>> $messageId: $json")
|
||||
|
||||
if (message.message.any { it.type == ArrayMessageType.face && it.data.id.toString() == "419" }) {
|
||||
message.reply("你发牛魔的火车呢, 我直接就是打断")
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.fancybot.annotations.CommandDescription
|
||||
import cn.rtast.fancybot.util.Logger
|
||||
import cn.rtast.fancybot.util.makeGif
|
||||
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||
import cn.rtast.fancybot.util.toByteArray
|
||||
@@ -33,6 +34,7 @@ class AsciiArtCommand : BaseCommand() {
|
||||
companion object {
|
||||
private const val FONT_SIZE = 12
|
||||
private val font = Font("Monospaced", Font.PLAIN, FONT_SIZE)
|
||||
private val logger = Logger.getLogger<AsciiArtCommand>()
|
||||
val waitingList = mutableListOf<Long>()
|
||||
|
||||
private fun BufferedImage.convertToAscii(): String {
|
||||
@@ -106,7 +108,7 @@ class AsciiArtCommand : BaseCommand() {
|
||||
val msg = MessageChain.Builder().addImage(imageBase64, true).build()
|
||||
message.reply(msg)
|
||||
} else {
|
||||
println("Making gif ascii art, frames: ${decoder.frameCount}")
|
||||
logger.info("制作GIF Ascii art中, 总帧数: ${decoder.frameCount}")
|
||||
val frames = (0 until decoder.frameCount).map { decoder.getFrame(it) }
|
||||
val asciiFrames = mutableListOf<BufferedImage>()
|
||||
val width = frames.first().width
|
||||
@@ -114,11 +116,12 @@ class AsciiArtCommand : BaseCommand() {
|
||||
frames.forEach { asciiFrames.add(it.convertToAscii().saveAsciiArtToImage(width, height)) }
|
||||
val gifBytes = decoder.makeGif(asciiFrames)
|
||||
val gifBase64 = gifBytes.encodeToBase64()
|
||||
println(gifBase64)
|
||||
logger.info("处理后的图片大小: ${gifBytes.size}字节, base64大小: ${gifBase64.length * 2}字节")
|
||||
message.reply(MessageChain.Builder().addImage(gifBase64, true).build())
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
message.reply("处理GIF失败")
|
||||
logger.info("gif处理失败")
|
||||
}
|
||||
} else {
|
||||
message.reply("回复错误已取消本次操作")
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/10/7
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.util
|
||||
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.slf4j.event.Level
|
||||
|
||||
object Logger {
|
||||
inline fun <reified T> getLogger(): Logger {
|
||||
return LoggerFactory.getLogger(T::class.simpleName).also { it.atLevel(Level.INFO) }
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ fun initCommandAndItem(rob: ROneBotFactory) {
|
||||
}
|
||||
|
||||
fun initFilesDir() {
|
||||
File("./$ROOT_PATH/caches/images").also { it.mkdirs() }
|
||||
File("$ROOT_PATH/caches/images").also { it.mkdirs() }
|
||||
File("$ROOT_PATH/logs").also { it.mkdirs() }
|
||||
}
|
||||
|
||||
fun initSetuIndex() {
|
||||
|
||||
Reference in New Issue
Block a user