Skip to content

Commit

Permalink
feat[onebot11]:add markdown segment [WIP]; format code
Browse files Browse the repository at this point in the history
  • Loading branch information
RTAkland committed Jan 6, 2025
1 parent 451a854 commit dc084fe
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package cn.rtast.rob.enums

import cn.rtast.rob.enums.AIRecordCharacter.entries


/**
* 定义几个常用的AI音色枚举类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ enum class ArrayMessageType {
at, rps, shake, poke, share,
reply, json, forward, dice,
video, contact, location,
music, xml, mface, node, file
music, xml, mface, node, file,
markdown
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package cn.rtast.rob.enums

import cn.rtast.rob.enums.BusinessName.entries


enum class BusinessName(val type: Int, val description: String) {
BigVIP(113, "QQ大会员"), VIP(1, "QQ会员"), YellowDiamond(102, "黄钻"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ class MessageChain internal constructor(arrayMessageList: MutableList<InternalBa
return this
}

@Deprecated(level = DeprecationLevel.HIDDEN, message = "Can't be used")
fun addMarkdown(content: String): Builder {
arrayMessageList.add(IMarkdown(IMarkdown.Data(content)))
return this
}

fun build(): MessageChain {
return MessageChain(arrayMessageList)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ internal data class INode(
)
}

/**
* Markdown 消息 ***WIP***
*/
internal data class IMarkdown(
val data: Data,
override val type: ArrayMessageType = ArrayMessageType.markdown
) : InternalBaseSegment {
data class Data(val content: String)
}

internal data class IRps(override val type: ArrayMessageType = ArrayMessageType.rps) : InternalBaseSegment
internal data class IDice(override val type: ArrayMessageType = ArrayMessageType.dice) : InternalBaseSegment
internal data class IShake(override val type: ArrayMessageType = ArrayMessageType.shake) : InternalBaseSegment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ package cn.rtast.rob.util

import cn.rtast.rob.command.IBrigadierCommand

abstract class BrigadierCommand: IBrigadierCommand<CommandSource>
abstract class BrigadierCommand : IBrigadierCommand<CommandSource>
23 changes: 23 additions & 0 deletions ronebot-onebot-v11/src/test/kotlin/test/TestClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ package test
import cn.rtast.rob.ROneBotFactory
import cn.rtast.rob.entity.GroupMessage
import cn.rtast.rob.entity.custom.ErrorEvent
import cn.rtast.rob.onebot.MessageChain
import cn.rtast.rob.onebot.NodeMessageChain
import cn.rtast.rob.onebot.OneBotListener
import cn.rtast.rob.util.BaseCommand
import cn.rtast.rob.util.BrigadierCommand
import cn.rtast.rob.util.CommandSource
import com.mojang.brigadier.CommandDispatcher
Expand All @@ -32,6 +35,7 @@ class TestClient : OneBotListener {

val commands = listOf(
EchoCommand(), DelayCommand(), MatchedCommand(),
ACommand()
)

class TestBrigadierCommand : BrigadierCommand() {
Expand All @@ -56,11 +60,30 @@ class TestBrigadierCommand : BrigadierCommand() {
}
}

class ACommand : BaseCommand() {
override val commandNames = listOf("/1")

override suspend fun executeGroup(message: GroupMessage, args: List<String>) {
val nodeMsg = NodeMessageChain.Builder()
.addMessageChain(
MessageChain.Builder()
// .addMarkdown("#test")
.addText("1")
.build(), 1845464277L
).build()
println(nodeMsg.nodes.toJson())
message.action.sendGroupMessage(message.groupId, nodeMsg)
}
}

suspend fun main() {
val client = TestClient()
// val wsAddress = "ws://127.0.0.1:4646"
val wsAddress = System.getenv("WS_ADDRESS")
val wsAccessToken = System.getenv("WS_ACCESS_TOKEN")
val instance1 = ROneBotFactory.createClient(wsAddress, wsAccessToken, client)
ROneBotFactory.brigadierCommandManager.register(TestBrigadierCommand())
commands.forEach {
ROneBotFactory.commandManager.register(it)
}
}

0 comments on commit dc084fe

Please sign in to comment.