feat: add some command
This commit is contained in:
5 files changed
+169
-3
No files matched your search
@@ -19,10 +19,13 @@ import cn.rtast.fancybot.commands.MusicCommand
|
|||||||
import cn.rtast.fancybot.commands.MyPointCommand
|
import cn.rtast.fancybot.commands.MyPointCommand
|
||||||
import cn.rtast.fancybot.commands.PixivCommand
|
import cn.rtast.fancybot.commands.PixivCommand
|
||||||
import cn.rtast.fancybot.commands.QRCodeCommand
|
import cn.rtast.fancybot.commands.QRCodeCommand
|
||||||
|
import cn.rtast.fancybot.commands.RUACommand
|
||||||
import cn.rtast.fancybot.commands.RedeemCommand
|
import cn.rtast.fancybot.commands.RedeemCommand
|
||||||
import cn.rtast.fancybot.commands.RemakeCommand
|
import cn.rtast.fancybot.commands.RemakeCommand
|
||||||
import cn.rtast.fancybot.commands.SignCommand
|
import cn.rtast.fancybot.commands.SignCommand
|
||||||
import cn.rtast.fancybot.commands.WeatherCommand
|
import cn.rtast.fancybot.commands.WeatherCommand
|
||||||
|
import cn.rtast.fancybot.commands.misc.BVParseCommand
|
||||||
|
import cn.rtast.fancybot.commands.misc.ImageURLCommand
|
||||||
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
|
||||||
@@ -35,6 +38,7 @@ import cn.rtast.rob.ROneBotFactory
|
|||||||
import cn.rtast.rob.entity.GetMessage
|
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.entity.GroupRevokeMessage
|
||||||
|
import cn.rtast.rob.enums.ArrayMessageType
|
||||||
import cn.rtast.rob.util.ob.MessageChain
|
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
|
||||||
@@ -47,6 +51,16 @@ class FancyBot : OBMessage {
|
|||||||
val msg = message.rawMessage
|
val msg = message.rawMessage
|
||||||
val groupId = message.groupId
|
val groupId = message.groupId
|
||||||
println("$sender($senderId: $groupId): $msg")
|
println("$sender($senderId: $groupId): $msg")
|
||||||
|
if (message.rawMessage.startsWith("BV") || message.rawMessage.startsWith("https://www.bilibili.com")) {
|
||||||
|
BVParseCommand.parse(this, message)
|
||||||
|
}
|
||||||
|
if (message.message.any { it.type == ArrayMessageType.reply }) { // Image url parse
|
||||||
|
val command = message.message.reversed().find { it.type == ArrayMessageType.text }!!.data.text!!
|
||||||
|
val replyId = message.message.find { it.type == ArrayMessageType.reply }!!.data.id!!
|
||||||
|
if (command == "图来" || command == "图链") {
|
||||||
|
this.getMessage(replyId.toString().toLong(), "imageUrl", message.groupId)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onGroupMessageRevoke(ws: WebSocket, message: GroupRevokeMessage) {
|
override suspend fun onGroupMessageRevoke(ws: WebSocket, message: GroupRevokeMessage) {
|
||||||
@@ -60,8 +74,9 @@ class FancyBot : OBMessage {
|
|||||||
|
|
||||||
|
|
||||||
override suspend fun onGetGroupMessageResponse(ws: WebSocket, message: GetMessage) {
|
override suspend fun onGetGroupMessageResponse(ws: WebSocket, message: GetMessage) {
|
||||||
if (message.data.id == "revoke") {
|
when (message.data.id) {
|
||||||
AntiRevokeCommand.getMessageCallback(this, message)
|
"revoke" -> AntiRevokeCommand.getMessageCallback(this, message)
|
||||||
|
"imageUrl" -> ImageURLCommand.callback(this, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +103,8 @@ val commands = listOf(
|
|||||||
QRCodeCommand(), AntiRevokeCommand(),
|
QRCodeCommand(), AntiRevokeCommand(),
|
||||||
MCPingCommand(), HelpCommand(),
|
MCPingCommand(), HelpCommand(),
|
||||||
WeatherCommand(), CigaretteCommand(),
|
WeatherCommand(), CigaretteCommand(),
|
||||||
RemakeCommand(), PixivCommand()
|
RemakeCommand(), PixivCommand(),
|
||||||
|
RUACommand()
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun main() {
|
suspend fun main() {
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/6
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands
|
||||||
|
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.enums.ArrayMessageType
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
|
class RUACommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/rua", "rua")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addText("使用rua @xxxx")
|
||||||
|
.addText("即可rua某人啦~")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val target = message.message.find { it.type == ArrayMessageType.at }?.data!!
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addReply(message.messageId)
|
||||||
|
.addAt(target.qq.toString().toLong())
|
||||||
|
.addNewLine()
|
||||||
|
.addText(message.sender.nickname)
|
||||||
|
.addText(" ")
|
||||||
|
.addText("rua了你~")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
} catch (_: NullPointerException) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addText("要@才有用哦~")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/6
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.misc
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.entity.bili.BVID
|
||||||
|
import cn.rtast.fancybot.util.Http
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
|
object BVParseCommand {
|
||||||
|
|
||||||
|
private const val CID_URL = "https://api.bilibili.com/x/web-interface/view"
|
||||||
|
|
||||||
|
suspend fun parse(listener: OBMessage, message: GroupMessage) {
|
||||||
|
val bvid = if (message.rawMessage.startsWith("BV")) {
|
||||||
|
message.rawMessage
|
||||||
|
} else {
|
||||||
|
message.rawMessage.split("/")[4]
|
||||||
|
}
|
||||||
|
val cidResponse = Http.get<BVID>(
|
||||||
|
CID_URL, mapOf("bvid" to bvid)
|
||||||
|
)
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addImage(cidResponse.data.pic)
|
||||||
|
.addText("标题: ${cidResponse.data.title} | 作者: ${cidResponse.data.owner.name}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("点赞: ${cidResponse.data.stat.like} | 观看: ${cidResponse.data.stat.view}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("收藏: ${cidResponse.data.stat.favorite} | 投币: ${cidResponse.data.stat.coin}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("https://www.bilibili.com/video/$bvid")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/6
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.misc
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
object ImageURLCommand {
|
||||||
|
|
||||||
|
suspend fun callback(listener: OBMessage, message: GetMessage) {
|
||||||
|
val image = message.data.message.find { it.type == ArrayMessageType.image }!!
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addReply(message.data.messageId)
|
||||||
|
.addAt(message.data.sender.userId)
|
||||||
|
.addNewLine()
|
||||||
|
.addText("哈哈哈哈图片来咯~")
|
||||||
|
.addNewLine()
|
||||||
|
.addText(image.data.file!!)
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.data.groupId!!, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/6
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.bili
|
||||||
|
|
||||||
|
data class BVID(
|
||||||
|
val data: Data
|
||||||
|
) {
|
||||||
|
data class Data(
|
||||||
|
val pic: String,
|
||||||
|
val title: String,
|
||||||
|
val owner: Owner,
|
||||||
|
val stat: Stat,
|
||||||
|
val cid: Long,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Owner(
|
||||||
|
val name: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Stat(
|
||||||
|
val view: Long,
|
||||||
|
val favorite: Int,
|
||||||
|
val coin: Int,
|
||||||
|
val like: Int,
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user