diff --git a/src/main/kotlin/cn/rtast/fancybot/Const.kt b/src/main/kotlin/cn/rtast/fancybot/Const.kt index 65560c4..a9f81f0 100644 --- a/src/main/kotlin/cn/rtast/fancybot/Const.kt +++ b/src/main/kotlin/cn/rtast/fancybot/Const.kt @@ -117,5 +117,5 @@ val commands = listOf( GravatarCommand(), PastebinCommand(), ShuffleEchoCommand(), TodayDontEatCommand(), TodayDontDrinkCommand(), MCBotCommand(), HTTPCatCommand(), HTTPDogCommand(), AITTSCommand(), NWWNCommand(), TJBGXLCommand(), XNMCommand(), SJCommand(), - OSUCommand(), TodaySmokeCommand() + OSUCommand(), TodaySmokeCommand(), GoodNewsCommand() ) \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/GoodNewsCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/GoodNewsCommand.kt new file mode 100644 index 0000000..03f150c --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/GoodNewsCommand.kt @@ -0,0 +1,45 @@ +/* + * Copyright © 2025 RTAkland + * Author: RTAkland + * Date: 2025/2/20 + */ + + +package cn.rtast.fancybot.commands.misc + +import cn.rtast.fancybot.util.misc.Resources +import cn.rtast.fancybot.util.misc.drawCenteredText +import cn.rtast.fancybot.util.misc.toByteArray +import cn.rtast.fancybot.util.str.encodeToBase64 +import cn.rtast.rob.entity.GroupMessage +import cn.rtast.rob.segment.Image +import cn.rtast.rob.util.BaseCommand +import java.awt.Color +import java.awt.Font +import java.awt.RenderingHints +import javax.imageio.ImageIO + +class GoodNewsCommand: BaseCommand() { + override val commandNames = listOf("xb", "喜报") + + private val goodNewsImageBytes = Resources.loadFromResourcesAsBytes("misc/good_news.png") + private val font = Font("SimSun", Font.BOLD, 130) + + private fun generateImage(content: String): String { + val img = ImageIO.read(goodNewsImageBytes!!.inputStream()) + val g2d = img.createGraphics() + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) + g2d.color = Color.RED + g2d.font = font + g2d.drawCenteredText(content, 650, 500) + g2d.dispose() + val imgBase64 = img.toByteArray().encodeToBase64() + return imgBase64 + } + + override suspend fun executeGroup(message: GroupMessage, args: List) { + val content = args.joinToString(" ") + val imgBase64 = generateImage(content) + message.reply(Image(imgBase64, true)) + } +} \ No newline at end of file diff --git a/src/main/resources/misc/good_news.png b/src/main/resources/misc/good_news.png new file mode 100644 index 0000000..6f82c0b Binary files /dev/null and b/src/main/resources/misc/good_news.png differ