Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guimc233 committed Jul 10, 2024
1 parent fc265f0 commit 39adac7
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/kotlin/ltd/guimc/plugin/quotly/QuotLyCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.nameCardOrNick
import net.mamoe.mirai.event.events.GroupMessageEvent
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.data.Image.Key.queryUrl
import org.json.JSONArray
import org.json.JSONObject
import top.mrxiaom.overflow.OverflowAPI
import xyz.cssxsh.mirai.hibernate.MiraiHibernateRecorder
Expand Down Expand Up @@ -59,7 +61,19 @@ object QuotLyCommand: SimpleCommand(
}

val quote = fromEvent.message.findIsInstance<QuoteReply>() ?: return@launch
var textMessage = quote.source.originalMessage.contentToString()
var textMessage = ""
var image = ""
for (singleMessage in quote.source.originalMessage) {
textMessage += when (singleMessage) {
is At -> "@${subject.cast<Group>().getOrFail(singleMessage.target).nameCardOrNick}"
is Image -> {
image = singleMessage.queryUrl()
""
}
is RichMessage -> "[卡片消息]"
else -> singleMessage.contentToString()
}
}

var member = subject.cast<Group>().getOrFail(quote.source.fromId)

Expand Down Expand Up @@ -87,13 +101,16 @@ object QuotLyCommand: SimpleCommand(

cooldown.flag(user!!)
postValue.getJSONArray("messages").getJSONObject(0).put("text", textMessage)
if (image != "") {
postValue.getJSONArray("messages").getJSONObject(0).put("media", JSONObject().put("url", image))
}
try {
val rawResp = JSONObject(HttpUtil.post("http://127.0.0.1:3000/generate", postValue.toString()))
val resp = rawResp.getJSONObject("result").getString("image")
if (!OverflowUtils.checkOverflowCore()) {
sendMessage(ImageUtils.base642imageMessage(resp, bot!!, subject!!))
} else {
sendMessage(OverflowAPI.get().imageFromFile("base64://"+resp))
sendMessage(OverflowAPI.get().imageFromFile("base64://$resp"))
}
} catch (e: Throwable) {
sendMessage("Oops, something went wrong.")
Expand Down

0 comments on commit 39adac7

Please sign in to comment.