-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[onebot11]: introduce brigadier: create command using mojang's br…
…igadier lib
- Loading branch information
Showing
13 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ dependencies { | |
api(libs.slf4j.api) | ||
api(libs.logback.classic) | ||
api(libs.kotlin.reflect) | ||
api(libs.brigadier) | ||
} |
35 changes: 35 additions & 0 deletions
35
ronebot-common/src/main/kotlin/cn/rtast/rob/command/BrigadierCommandManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright © 2024 RTAkland | ||
* Author: RTAkland | ||
* Date: 2024/12/14 | ||
*/ | ||
|
||
|
||
package cn.rtast.rob.command | ||
|
||
import cn.rtast.rob.BaseBotInstance | ||
import com.mojang.brigadier.CommandDispatcher | ||
|
||
interface BrigadierCommandManager<B : BaseBotInstance> { | ||
/** | ||
* 命令分发器 | ||
*/ | ||
val dispatcher: CommandDispatcher<B> | ||
|
||
/** | ||
* 所有Bot实例 | ||
*/ | ||
val botInstances: List<B> | ||
|
||
/** | ||
* 注册命令 | ||
*/ | ||
fun register(command: IBrigadierCommand<B>) { | ||
command.register(dispatcher) | ||
} | ||
|
||
/** | ||
* 执行命令 | ||
*/ | ||
fun execute(command: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
ronebot-common/src/main/kotlin/cn/rtast/rob/command/IBrigadierCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright © 2024 RTAkland | ||
* Author: RTAkland | ||
* Date: 2024/12/14 | ||
*/ | ||
|
||
|
||
package cn.rtast.rob.command | ||
|
||
import cn.rtast.rob.BaseBotInstance | ||
import com.mojang.brigadier.CommandDispatcher | ||
|
||
interface IBrigadierCommand<B : BaseBotInstance> { | ||
/** | ||
* 注册指令 | ||
*/ | ||
fun register(dispatcher: CommandDispatcher<B>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
ronebot-onebot-v11/src/main/kotlin/cn/rtast/rob/util/BrigadierCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright © 2024 RTAkland | ||
* Author: RTAkland | ||
* Date: 2024/12/14 | ||
*/ | ||
|
||
|
||
package cn.rtast.rob.util | ||
|
||
import cn.rtast.rob.BotInstance | ||
import cn.rtast.rob.command.IBrigadierCommand | ||
|
||
abstract class BrigadierCommand: IBrigadierCommand<BotInstance> |
27 changes: 27 additions & 0 deletions
27
ronebot-onebot-v11/src/main/kotlin/cn/rtast/rob/util/BrigadierCommandManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright © 2024 RTAkland | ||
* Author: RTAkland | ||
* Date: 2024/12/14 | ||
*/ | ||
|
||
|
||
package cn.rtast.rob.util | ||
|
||
import cn.rtast.rob.BotInstance | ||
import cn.rtast.rob.command.BrigadierCommandManager | ||
import com.mojang.brigadier.CommandDispatcher | ||
|
||
class BrigadierCommandManagerImpl internal constructor( | ||
override val botInstances: List<BotInstance> | ||
) : BrigadierCommandManager<BotInstance> { | ||
|
||
override val dispatcher = CommandDispatcher<BotInstance>() | ||
override fun execute(command: String) { | ||
try { | ||
botInstances.forEach { | ||
dispatcher.execute(command, it) | ||
} | ||
} catch (_: Exception) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters