diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index cbc77af..8c9c6ad 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -94,40 +94,27 @@ class FancyBot : OneBotListener { val plainTextContent = getMsg.message .filter { it.type == ArrayMessageType.text } .joinToString { it.data.text!! } - if (command.contains("加速")) { - val multiply = command.split("加速").last().toFloat() - SpeedUpGIFCommand.speedUp(message, getMsg, multiply) - } - if (command.contains("倒放") || command.contains("/df")) { - // 使用回复消息的方式对一个gif倒放 - ReverseGIFCommand.reverse(message, getMsg) - } - if (command.contains("/sl") || command.contains("/short")) { - // 使用回复消息的方式快速对一个url消息创建一个短链接 - message.reply(plainTextContent.trim().makeShortLink()) - } - if (command.contains("/pb") || command.contains("/pastebin")) { - // 使用回复消息的方式快速将创建一个pastebin - val pastebinUrl = PastebinCommand.createPastebin(plainTextContent) - message.reply(pastebinUrl) - } + if (command.contains("倒放") || command.contains("/df")) ReverseGIFCommand.reverse(message, getMsg) + if (command.contains("图来") || command.contains("图链")) ImageURLCommand.callback(message, getMsg) + if (command.contains("reaction")) ReactionCommand.reaction(message) + if (command.contains("图床")) ImageBedCommand.execute(getMsg, message) + if (command.contains("/sl") || command.contains("/short")) message.reply( + plainTextContent.trim().makeShortLink() + ) if (command.contains("/ascii") || command.contains("/asc")) { // 使用回复消息的方式直接对一个图片进行生成Ascii art的操作 val url = AsciiArtCommand.getImageUrl(getMsg) val image = AsciiArtCommand.generateAsciiArt(url) message.reply(image) } - if (command.contains("图来") || command.contains("图链")) { - // 获取一个或多个图片的链接, 并且生成一个或多个短链接 - ImageURLCommand.callback(message, getMsg) + if (command.contains("/pb") || command.contains("/pastebin")) { + // 使用回复消息的方式快速将创建一个pastebin + val pastebinUrl = PastebinCommand.createPastebin(plainTextContent) + message.reply(pastebinUrl) } - if (command.contains("reaction")) { - // 使用reaction刷屏回应一条消息 - ReactionCommand.reaction(message) - } - if (command.contains("图床")) { - // 将一个图片上传到图床 - ImageBedCommand.execute(getMsg, message) + if (command.contains("加速")) { + val multiply = command.split("加速").last().toFloat() + SpeedUpGIFCommand.speedUp(message, getMsg, multiply) } } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/reply/SpeedUpGIFCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/reply/SpeedUpGIFCommand.kt index 5ec3b99..8193948 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/reply/SpeedUpGIFCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/reply/SpeedUpGIFCommand.kt @@ -23,7 +23,7 @@ object SpeedUpGIFCommand { val gifStream = gifUrl.toURL().openStream() val decoder = GifDecoder() decoder.read(gifStream) - val frames = (0 until decoder.frameCount).map { decoder.getFrame(it) }.reversed() + val frames = (0 until decoder.frameCount).map { decoder.getFrame(it) } val gifBase64 = decoder.makeGif(frames, multiply) val imgBedUrl = ImageBed.upload(gifBase64) val shortLink = imgBedUrl.makeShortLink() diff --git a/src/main/kotlin/cn/rtast/fancybot/util/misc/Image.kt b/src/main/kotlin/cn/rtast/fancybot/util/misc/Image.kt index 7354319..92f4c1e 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/misc/Image.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/misc/Image.kt @@ -8,6 +8,7 @@ package cn.rtast.fancybot.util.misc import cn.rtast.fancybot.configManager +import java.awt.Color import java.awt.Graphics2D import java.awt.geom.Ellipse2D import java.awt.geom.RoundRectangle2D @@ -128,4 +129,20 @@ fun BufferedImage.isFullyTransparent(): Boolean { } } return true +} + +fun BufferedImage.toGrayscale(): BufferedImage { + val width = this.width + val height = this.height + val grayscaleImage = BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY) + + for (y in 0 until height) { + for (x in 0 until width) { + val color = Color(this.getRGB(x, y)) + val gray = (color.red * 0.299 + color.green * 0.587 + color.blue * 0.114).toInt() + val grayColor = Color(gray, gray, gray) + grayscaleImage.setRGB(x, y, grayColor.rgb) + } + } + return grayscaleImage } \ No newline at end of file