feat: add anti revoke command
This commit is contained in:
12 files changed
+98
-23
No files matched your search
@@ -15,7 +15,6 @@ import com.google.gson.GsonBuilder
|
||||
val gson: Gson = GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.disableHtmlEscaping()
|
||||
.serializeNulls()
|
||||
.create()
|
||||
|
||||
const val ROOT_PATH = "./data"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package cn.rtast.fancybot
|
||||
|
||||
import cn.rtast.fancybot.commands.AntiRevokeCommand
|
||||
import cn.rtast.fancybot.commands.EchoCommand
|
||||
import cn.rtast.fancybot.commands.FKXQSCommand
|
||||
import cn.rtast.fancybot.commands.HitokotoCommand
|
||||
@@ -20,17 +21,37 @@ import cn.rtast.fancybot.entity.enums.WSType
|
||||
import cn.rtast.fancybot.util.file.ConfigManager
|
||||
import cn.rtast.fancybot.util.initDatabase
|
||||
import cn.rtast.rob.ROneBotFactory
|
||||
import cn.rtast.rob.entity.GetMessage
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.entity.GroupRevokeMessage
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
import org.java_websocket.WebSocket
|
||||
|
||||
class FancyBot : OBMessage {
|
||||
override suspend fun onGroupMessage(websocket: WebSocket, message: GroupMessage, json: String) {
|
||||
|
||||
override suspend fun onGroupMessage(ws: WebSocket, message: GroupMessage, json: String) {
|
||||
println(message.rawMessage)
|
||||
}
|
||||
|
||||
override suspend fun onWebsocketError(webSocket: WebSocket, ex: Exception) {
|
||||
println(ex.printStackTrace())
|
||||
override suspend fun onGroupMessageRevoke(ws: WebSocket, message: GroupRevokeMessage) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addText("用户: ${message.userId} 被: ${message.operatorId} 撤回了一条消息")
|
||||
.addNewLine()
|
||||
.addText("使用/revoke ${message.messageId} 来获取被撤回的消息")
|
||||
.build()
|
||||
this.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
|
||||
|
||||
override suspend fun onGetGroupMessageResponse(ws: WebSocket, message: GetMessage) {
|
||||
if (message.data.id == "revoke") {
|
||||
AntiRevokeCommand.getMessageCallback(this, message)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun onWebsocketErrorEvent(ws: WebSocket, ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +62,8 @@ val commands = listOf(
|
||||
SignCommand(), RedeemCommand(), MyPointCommand(),
|
||||
HitokotoCommand(),
|
||||
FKXQSCommand(),
|
||||
QRCodeCommand()
|
||||
QRCodeCommand(),
|
||||
AntiRevokeCommand()
|
||||
)
|
||||
|
||||
val configManager = ConfigManager()
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/1
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
|
||||
import cn.rtast.fancybot.util.toJson
|
||||
import cn.rtast.rob.entity.GetMessage
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class AntiRevokeCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/revoke", "/rv", "/防撤回")
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
val messageId = args.first().toLong()
|
||||
listener.getMessage(messageId, "revoke", message.groupId)
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("正在获取消息中...")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
|
||||
companion object {
|
||||
suspend fun getMessageCallback(listener: OBMessage, message: GetMessage) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.data.sender.userId)
|
||||
.addNewLine()
|
||||
.addText("被撤回的消息如下: ")
|
||||
.addNewLine()
|
||||
.addText(message.data.message.toJson())
|
||||
.build()
|
||||
listener.sendGroupMessage(message.data.groupId!!, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import cn.rtast.fancybot.entity.FKXQS
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.message.MessageChain
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class FKXQSCommand: BaseCommand() {
|
||||
|
||||
@@ -10,7 +10,7 @@ package cn.rtast.fancybot.commands
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.message.MessageChain
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class HitokotoCommand : BaseCommand() {
|
||||
|
||||
@@ -10,7 +10,7 @@ package cn.rtast.fancybot.commands
|
||||
import cn.rtast.fancybot.util.file.JrrpManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.message.MessageChain
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class JrrpCommand : BaseCommand() {
|
||||
|
||||
@@ -14,7 +14,7 @@ import cn.rtast.fancybot.entity.music.SongUrl
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.message.MessageChain
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
import java.time.Instant
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ package cn.rtast.fancybot.commands
|
||||
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.message.MessageChain
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class QRCodeCommand : BaseCommand() {
|
||||
|
||||
@@ -14,16 +14,11 @@ import cn.rtast.fancybot.util.file.SignManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.enums.UserRole
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.message.MessageChain
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
private val signManager = SignManager()
|
||||
|
||||
private val items = mapOf(
|
||||
"色图" to 50,
|
||||
"黑丝" to 60
|
||||
)
|
||||
|
||||
class SignCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/签到", "/sign")
|
||||
|
||||
@@ -83,6 +78,12 @@ class MyPointCommand : BaseCommand() {
|
||||
}
|
||||
}
|
||||
|
||||
private val items = mapOf(
|
||||
"色图" to 50,
|
||||
"黑丝" to 60,
|
||||
"白丝" to 70
|
||||
)
|
||||
|
||||
class RedeemCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/redeem", "/兑换", "/rdm")
|
||||
|
||||
@@ -128,7 +129,7 @@ class RedeemCommand : BaseCommand() {
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
when (selectedItemKey) {
|
||||
"黑丝", "hs", "heisi" -> {
|
||||
"黑丝" -> {
|
||||
val url = Http.get<Heisi>("https://v2.api-m.com/api/heisi").data
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
@@ -137,13 +138,22 @@ class RedeemCommand : BaseCommand() {
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
|
||||
"色图", "st", "setu" -> {
|
||||
"色图" -> {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addImage("https://moe.jitsu.top/img/?sort=r18&size=small")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
|
||||
"白丝" -> {
|
||||
val url = Http.get<Heisi>("https://v2.api-m.com/api/baisi").data
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addImage(url)
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,9 @@ package cn.rtast.fancybot.util
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
|
||||
fun Long.isSameDay(otherTimestamp: Long, zoneId: ZoneId = ZoneId.systemDefault()): Boolean {
|
||||
val thisDate = Instant.ofEpochMilli(this).atZone(zoneId).toLocalDate()
|
||||
val otherDate = Instant.ofEpochMilli(otherTimestamp).atZone(zoneId).toLocalDate()
|
||||
return thisDate == otherDate
|
||||
fun Long.isSameDay(timestamp2: Long): Boolean {
|
||||
val zoneId = ZoneId.of("Asia/Shanghai")
|
||||
val date1 = Instant.ofEpochSecond(this).atZone(zoneId).toLocalDate()
|
||||
val date2 = Instant.ofEpochSecond(timestamp2).atZone(zoneId).toLocalDate()
|
||||
return date1 == date2
|
||||
}
|
||||
Reference in New Issue
Block a user