feat: support gif reverse and fix get image bug
This commit is contained in:
6 files changed
+89
-5
No files matched your search
@@ -34,6 +34,7 @@ dependencies {
|
|||||||
implementation(libs.exposedJDBC)
|
implementation(libs.exposedJDBC)
|
||||||
implementation(libs.sqliteJDBC)
|
implementation(libs.sqliteJDBC)
|
||||||
implementation(libs.motdPinger)
|
implementation(libs.motdPinger)
|
||||||
|
implementation("com.madgag:animated-gif-lib:1.4")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.build {
|
tasks.build {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kotlinVersion = "2.0.10"
|
kotlinVersion = "2.0.10"
|
||||||
ronebotVersion = "1.6.0"
|
ronebotVersion = "1.6.2"
|
||||||
shadowVersion = "8.3.0"
|
shadowVersion = "8.3.0"
|
||||||
okhttpVersion = "5.0.0-alpha.14"
|
okhttpVersion = "5.0.0-alpha.14"
|
||||||
exposedVersion = "0.53.0"
|
exposedVersion = "0.53.0"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ package cn.rtast.fancybot
|
|||||||
import cn.rtast.fancybot.commands.*
|
import cn.rtast.fancybot.commands.*
|
||||||
import cn.rtast.fancybot.commands.misc.BVParseCommand
|
import cn.rtast.fancybot.commands.misc.BVParseCommand
|
||||||
import cn.rtast.fancybot.commands.misc.ImageURLCommand
|
import cn.rtast.fancybot.commands.misc.ImageURLCommand
|
||||||
|
import cn.rtast.fancybot.commands.misc.ReverseGIFCommand
|
||||||
import cn.rtast.fancybot.entity.enums.WSType
|
import cn.rtast.fancybot.entity.enums.WSType
|
||||||
import cn.rtast.fancybot.items.BaisiItem
|
import cn.rtast.fancybot.items.BaisiItem
|
||||||
import cn.rtast.fancybot.items.HeisiItem
|
import cn.rtast.fancybot.items.HeisiItem
|
||||||
@@ -42,8 +43,13 @@ class FancyBot : OBMessage {
|
|||||||
val command = message.message.reversed().find { it.type == ArrayMessageType.text }!!.data.text!!
|
val command = message.message.reversed().find { it.type == ArrayMessageType.text }!!.data.text!!
|
||||||
val replyId = message.message.find { it.type == ArrayMessageType.reply }!!.data.id!!
|
val replyId = message.message.find { it.type == ArrayMessageType.reply }!!.data.id!!
|
||||||
if (command.contains("图来") || command.contains("图链")) {
|
if (command.contains("图来") || command.contains("图链")) {
|
||||||
|
// get image url
|
||||||
this.getMessage(replyId.toString().toLong(), "imageUrl", message.groupId)
|
this.getMessage(replyId.toString().toLong(), "imageUrl", message.groupId)
|
||||||
}
|
}
|
||||||
|
if (command.contains("倒放") || command.contains("df")) {
|
||||||
|
// reverse gif
|
||||||
|
this.getMessage(replyId.toString().toLong(), "reverseGif", message.groupId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +67,7 @@ class FancyBot : OBMessage {
|
|||||||
when (message.data.id) {
|
when (message.data.id) {
|
||||||
"revoke" -> AntiRevokeCommand.getMessageCallback(this, message)
|
"revoke" -> AntiRevokeCommand.getMessageCallback(this, message)
|
||||||
"imageUrl" -> ImageURLCommand.callback(this, message)
|
"imageUrl" -> ImageURLCommand.callback(this, message)
|
||||||
|
"reverseGif" -> ReverseGIFCommand.callback(this, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,18 @@ import cn.rtast.rob.util.ob.OBMessage
|
|||||||
object ImageURLCommand {
|
object ImageURLCommand {
|
||||||
|
|
||||||
suspend fun callback(listener: OBMessage, message: GetMessage) {
|
suspend fun callback(listener: OBMessage, message: GetMessage) {
|
||||||
val image = message.data.message.find { it.type == ArrayMessageType.image }!!
|
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addReply(message.data.messageId)
|
.addReply(message.data.messageId)
|
||||||
.addText("哈哈哈哈图片来咯~")
|
.addText("哈哈哈哈图片来咯~")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText(image.data.file!!)
|
val image = message.data.message.find { it.type == ArrayMessageType.image }
|
||||||
.build()
|
if (image == null) {
|
||||||
listener.sendGroupMessage(message.data.groupId!!, msg)
|
val gif = message.data.message.find { it.type == ArrayMessageType.mface }!!
|
||||||
|
msg.addText(gif.data.url!!)
|
||||||
|
} else {
|
||||||
|
msg.addText(image.data.file!!)
|
||||||
|
|
||||||
|
}
|
||||||
|
listener.sendGroupMessage(message.data.groupId!!, msg.build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/8
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.misc
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||||
|
import cn.rtast.rob.entity.GetMessage
|
||||||
|
import cn.rtast.rob.enums.ArrayMessageType
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OBMessage
|
||||||
|
import com.madgag.gif.fmsware.AnimatedGifEncoder
|
||||||
|
import com.madgag.gif.fmsware.GifDecoder
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.net.URI
|
||||||
|
|
||||||
|
object ReverseGIFCommand {
|
||||||
|
|
||||||
|
private fun reverseGif(gifUrl: String): String {
|
||||||
|
val gifStream = URI(gifUrl).toURL().openStream()
|
||||||
|
val decoder = GifDecoder()
|
||||||
|
decoder.read(gifStream)
|
||||||
|
val frames = (0 until decoder.frameCount).map { decoder.getFrame(it) }.reversed()
|
||||||
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
val encoder = AnimatedGifEncoder()
|
||||||
|
encoder.start(byteArrayOutputStream)
|
||||||
|
encoder.setRepeat(0)
|
||||||
|
for (i in frames.indices) {
|
||||||
|
encoder.setDelay(decoder.getDelay(decoder.frameCount - i - 1))
|
||||||
|
encoder.addFrame(frames[i])
|
||||||
|
}
|
||||||
|
encoder.finish()
|
||||||
|
val gifBytes = byteArrayOutputStream.toByteArray()
|
||||||
|
return gifBytes.encodeToBase64()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun callback(listener: OBMessage, message: GetMessage) {
|
||||||
|
val gifUrl = message.data.message.find { it.type == ArrayMessageType.mface }!!.data.url!!
|
||||||
|
val base64String = this.reverseGif(gifUrl)
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addReply(message.data.messageId)
|
||||||
|
.addImage(base64String, true)
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.data.groupId!!, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/8
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.util.str
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun String.encodeToBase64(): String {
|
||||||
|
return Base64.getEncoder().encodeToString(this.toByteArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteArray.encodeToBase64(): String {
|
||||||
|
return Base64.getEncoder().encodeToString(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.decodeToString(): String {
|
||||||
|
return String(Base64.getDecoder().decode(this))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user