feat: add anti revoke command
This commit is contained in:
12 files changed
+98
-23
No files matched your search
@@ -12,6 +12,7 @@ version = fancyBotVersion
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
maven {
|
maven {
|
||||||
name = "repo.rtast.cn"
|
name = "repo.rtast.cn"
|
||||||
url = uri("https://repo.rtast.cn/api/v4/projects/33/packages/maven")
|
url = uri("https://repo.rtast.cn/api/v4/projects/33/packages/maven")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kotlinVersion = "2.0.10"
|
kotlinVersion = "2.0.10"
|
||||||
ronebotVersion = "1.4.1"
|
ronebotVersion = "1.4.9"
|
||||||
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"
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import com.google.gson.GsonBuilder
|
|||||||
val gson: Gson = GsonBuilder()
|
val gson: Gson = GsonBuilder()
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.disableHtmlEscaping()
|
.disableHtmlEscaping()
|
||||||
.serializeNulls()
|
|
||||||
.create()
|
.create()
|
||||||
|
|
||||||
const val ROOT_PATH = "./data"
|
const val ROOT_PATH = "./data"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot
|
package cn.rtast.fancybot
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.commands.AntiRevokeCommand
|
||||||
import cn.rtast.fancybot.commands.EchoCommand
|
import cn.rtast.fancybot.commands.EchoCommand
|
||||||
import cn.rtast.fancybot.commands.FKXQSCommand
|
import cn.rtast.fancybot.commands.FKXQSCommand
|
||||||
import cn.rtast.fancybot.commands.HitokotoCommand
|
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.file.ConfigManager
|
||||||
import cn.rtast.fancybot.util.initDatabase
|
import cn.rtast.fancybot.util.initDatabase
|
||||||
import cn.rtast.rob.ROneBotFactory
|
import cn.rtast.rob.ROneBotFactory
|
||||||
|
import cn.rtast.rob.entity.GetMessage
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
import org.java_websocket.WebSocket
|
import org.java_websocket.WebSocket
|
||||||
|
|
||||||
class FancyBot : OBMessage {
|
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)
|
println(message.rawMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onWebsocketError(webSocket: WebSocket, ex: Exception) {
|
override suspend fun onGroupMessageRevoke(ws: WebSocket, message: GroupRevokeMessage) {
|
||||||
println(ex.printStackTrace())
|
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(),
|
SignCommand(), RedeemCommand(), MyPointCommand(),
|
||||||
HitokotoCommand(),
|
HitokotoCommand(),
|
||||||
FKXQSCommand(),
|
FKXQSCommand(),
|
||||||
QRCodeCommand()
|
QRCodeCommand(),
|
||||||
|
AntiRevokeCommand()
|
||||||
)
|
)
|
||||||
|
|
||||||
val configManager = ConfigManager()
|
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.fancybot.util.Http
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
class FKXQSCommand: BaseCommand() {
|
class FKXQSCommand: BaseCommand() {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ package cn.rtast.fancybot.commands
|
|||||||
import cn.rtast.fancybot.util.Http
|
import cn.rtast.fancybot.util.Http
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
class HitokotoCommand : BaseCommand() {
|
class HitokotoCommand : BaseCommand() {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ package cn.rtast.fancybot.commands
|
|||||||
import cn.rtast.fancybot.util.file.JrrpManager
|
import cn.rtast.fancybot.util.file.JrrpManager
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
class JrrpCommand : BaseCommand() {
|
class JrrpCommand : BaseCommand() {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import cn.rtast.fancybot.entity.music.SongUrl
|
|||||||
import cn.rtast.fancybot.util.Http
|
import cn.rtast.fancybot.util.Http
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ package cn.rtast.fancybot.commands
|
|||||||
|
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
class QRCodeCommand : BaseCommand() {
|
class QRCodeCommand : BaseCommand() {
|
||||||
|
|||||||
@@ -14,16 +14,11 @@ import cn.rtast.fancybot.util.file.SignManager
|
|||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.enums.UserRole
|
import cn.rtast.rob.enums.UserRole
|
||||||
import cn.rtast.rob.util.BaseCommand
|
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 cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
private val signManager = SignManager()
|
private val signManager = SignManager()
|
||||||
|
|
||||||
private val items = mapOf(
|
|
||||||
"色图" to 50,
|
|
||||||
"黑丝" to 60
|
|
||||||
)
|
|
||||||
|
|
||||||
class SignCommand : BaseCommand() {
|
class SignCommand : BaseCommand() {
|
||||||
override val commandNames = listOf("/签到", "/sign")
|
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() {
|
class RedeemCommand : BaseCommand() {
|
||||||
override val commandNames = listOf("/redeem", "/兑换", "/rdm")
|
override val commandNames = listOf("/redeem", "/兑换", "/rdm")
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ class RedeemCommand : BaseCommand() {
|
|||||||
.build()
|
.build()
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
when (selectedItemKey) {
|
when (selectedItemKey) {
|
||||||
"黑丝", "hs", "heisi" -> {
|
"黑丝" -> {
|
||||||
val url = Http.get<Heisi>("https://v2.api-m.com/api/heisi").data
|
val url = Http.get<Heisi>("https://v2.api-m.com/api/heisi").data
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addAt(message.sender.userId)
|
.addAt(message.sender.userId)
|
||||||
@@ -137,13 +138,22 @@ class RedeemCommand : BaseCommand() {
|
|||||||
listener.sendGroupMessage(message.groupId, msg)
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
"色图", "st", "setu" -> {
|
"色图" -> {
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addAt(message.sender.userId)
|
.addAt(message.sender.userId)
|
||||||
.addImage("https://moe.jitsu.top/img/?sort=r18&size=small")
|
.addImage("https://moe.jitsu.top/img/?sort=r18&size=small")
|
||||||
.build()
|
.build()
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
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.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
|
||||||
fun Long.isSameDay(otherTimestamp: Long, zoneId: ZoneId = ZoneId.systemDefault()): Boolean {
|
fun Long.isSameDay(timestamp2: Long): Boolean {
|
||||||
val thisDate = Instant.ofEpochMilli(this).atZone(zoneId).toLocalDate()
|
val zoneId = ZoneId.of("Asia/Shanghai")
|
||||||
val otherDate = Instant.ofEpochMilli(otherTimestamp).atZone(zoneId).toLocalDate()
|
val date1 = Instant.ofEpochSecond(this).atZone(zoneId).toLocalDate()
|
||||||
return thisDate == otherDate
|
val date2 = Instant.ofEpochSecond(timestamp2).atZone(zoneId).toLocalDate()
|
||||||
|
return date1 == date2
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user