2024-09-06 10:58:55 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 RTAkland
|
|
|
|
|
* Author: RTAkland
|
|
|
|
|
* Date: 2024/9/6
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2024-09-13 12:44:10 +08:00
|
|
|
package cn.rtast.fancybot.commands.parse
|
2024-09-06 10:58:55 +08:00
|
|
|
|
2024-10-09 14:55:03 +08:00
|
|
|
import cn.rtast.fancybot.commands.misc.ShortLinkCommand.Companion.makeShortLink
|
|
|
|
|
import cn.rtast.fancybot.configManager
|
2024-09-06 10:58:55 +08:00
|
|
|
import cn.rtast.rob.entity.GetMessage
|
2024-09-24 00:48:23 +08:00
|
|
|
import cn.rtast.rob.entity.GroupMessage
|
2024-09-06 10:58:55 +08:00
|
|
|
import cn.rtast.rob.enums.ArrayMessageType
|
2024-10-09 14:55:03 +08:00
|
|
|
import cn.rtast.rob.util.ob.MessageChain
|
|
|
|
|
import cn.rtast.rob.util.ob.asNode
|
2024-09-06 10:58:55 +08:00
|
|
|
|
|
|
|
|
object ImageURLCommand {
|
2024-10-09 13:06:43 +08:00
|
|
|
|
2024-10-09 14:55:03 +08:00
|
|
|
fun getImageUrl(message: GetMessage.Data): List<String> {
|
2024-10-09 13:06:43 +08:00
|
|
|
try {
|
2024-10-09 14:55:03 +08:00
|
|
|
val images = mutableListOf<String>()
|
|
|
|
|
message.message.forEach {
|
|
|
|
|
if (it.type == ArrayMessageType.image) images.add(it.data.url!!)
|
|
|
|
|
if (it.type == ArrayMessageType.mface) images.add(it.data.file!!)
|
2024-10-09 13:06:43 +08:00
|
|
|
}
|
2024-10-09 14:55:03 +08:00
|
|
|
return images
|
2024-10-09 13:06:43 +08:00
|
|
|
} catch (_: NullPointerException) {
|
2024-10-09 14:55:03 +08:00
|
|
|
return emptyList()
|
2024-10-09 13:06:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 00:48:23 +08:00
|
|
|
suspend fun callback(groupMessage: GroupMessage, message: GetMessage.Data) {
|
2024-10-09 14:55:03 +08:00
|
|
|
val images = getImageUrl(message)
|
|
|
|
|
if (images.isEmpty()) {
|
2024-10-09 13:06:43 +08:00
|
|
|
groupMessage.reply("这个消息里没有图片呢!")
|
2024-09-08 17:59:06 +08:00
|
|
|
} else {
|
2024-10-09 14:55:03 +08:00
|
|
|
if (images.size == 1) {
|
|
|
|
|
val msg = MessageChain.Builder()
|
|
|
|
|
.addText(images.first().makeShortLink())
|
|
|
|
|
.addNewLine(2)
|
|
|
|
|
.addText(images.first())
|
|
|
|
|
.build()
|
|
|
|
|
groupMessage.reply(msg)
|
|
|
|
|
} else {
|
|
|
|
|
val messages = mutableListOf<MessageChain>()
|
|
|
|
|
images.forEach {
|
|
|
|
|
val msg = MessageChain.Builder()
|
|
|
|
|
.addText(it)
|
|
|
|
|
.addNewLine(2)
|
|
|
|
|
.build()
|
|
|
|
|
messages.add(msg)
|
|
|
|
|
}
|
|
|
|
|
groupMessage.reply(messages.asNode(configManager.selfId))
|
|
|
|
|
}
|
2024-09-08 17:59:06 +08:00
|
|
|
}
|
2024-09-06 10:58:55 +08:00
|
|
|
}
|
|
|
|
|
}
|