chore: bump dep version

This commit is contained in:
2024-08-30 15:05:51 +08:00
parent bf75cfad38
commit 27f691b48a
12 files changed
+58 -35

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
# FancyBot
> 这是一个使用了 `ROneBot` 框架的示例机器人程序, 包含了几个简单的命令, 例如: 点歌, 今日人品, 签到...
> ROneBot项目地址: [Gitlab](https://repo.rtast.cn/RTAkland/ronebot) [Github](https://github.com/RTAkland/ROneBot)
> Github上的项目可能不是最新版本, 最新版本在Gitlab
+1 -1
View File
@@ -1,6 +1,6 @@
[versions]
kotlinVersion = "2.0.10"
ronebotVersion = "1.2.4"
ronebotVersion = "1.2.5"
shadowVersion = "8.3.0"
okhttpVersion = "5.0.0-alpha.14"
+6 -1
View File
@@ -8,6 +8,7 @@
package cn.rtast.fancybot
import cn.rtast.fancybot.entity.Config
import cn.rtast.fancybot.entity.enums.WSType
import com.google.gson.Gson
import com.google.gson.GsonBuilder
@@ -20,5 +21,9 @@ val gson: Gson = GsonBuilder()
const val ROOT_PATH = "./data"
val DEFAULT_CONFIG = Config(
cnmApi = "https://ncm.rtast.cn"
ncmAPI = "https://ncm.rtast.cn",
wsAddress = "ws://127.0.0.1",
wsType = WSType.Client,
accessToken = "114514",
port = 6760
)
+12 -25
View File
@@ -12,35 +12,17 @@ import cn.rtast.fancybot.commands.JrrpCommand
import cn.rtast.fancybot.commands.MusicCommand
import cn.rtast.fancybot.commands.MyPointCommand
import cn.rtast.fancybot.commands.SignCommand
import cn.rtast.fancybot.entity.enums.WSType
import cn.rtast.fancybot.util.file.ConfigManager
import cn.rtast.rob.ROneBotFactory
import cn.rtast.rob.entity.GroupMessage
import cn.rtast.rob.util.ob.OBMessage
import com.sun.net.httpserver.HttpServer
import org.java_websocket.WebSocket
import java.net.InetSocketAddress
class FancyBot : OBMessage {
override suspend fun onGroupMessage(websocket: WebSocket, message: GroupMessage, json: String) {
println(message.rawMessage)
}
override suspend fun onWebsocketError(webSocket: WebSocket, ex: Exception) {
println(ex.message)
}
}
fun createFakeServer() {
val server = HttpServer.create(InetSocketAddress(8000), 0)
server.createContext("/") { exchange ->
val response = "Hello, Kotlin HTTP Server!"
exchange.sendResponseHeaders(200, response.toByteArray().size.toLong())
val os = exchange.responseBody
os.write(response.toByteArray())
os.close()
}
server.start()
println("Server is running on port 8000...")
}
val commands = listOf(
@@ -54,11 +36,16 @@ val commands = listOf(
val configManager = ConfigManager()
fun main() {
val address = System.getenv("WS_ADDRESS")
val password = System.getenv("WS_PASSWORD")
val fancyBot = FancyBot()
val wsClient = ROneBotFactory.createClient(address, password, fancyBot)
val commandManager = wsClient.commandManager
commands.forEach { commandManager.register(it) }
createFakeServer()
val workType = configManager.wsType
val accessToken = configManager.accessToken
val rob = if (workType == WSType.Client) {
val address = configManager.wsAddress
ROneBotFactory.createClient(address, accessToken, fancyBot)
} else {
val port = configManager.wsPort
ROneBotFactory.createServer(port, accessToken, fancyBot)
}
val commandManager = rob.commandManager
commands.forEach { commandManager.register(it) }
}
@@ -12,7 +12,7 @@ import cn.rtast.rob.util.BaseCommand
import cn.rtast.rob.util.ob.OBMessage
class EchoCommand: BaseCommand() {
override val commandName = "/echo"
override val commandNames = listOf("/echo")
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
listener.sendGroupMessage(message.groupId, args.joinToString(" "))
@@ -13,7 +13,7 @@ import cn.rtast.rob.util.BaseCommand
import cn.rtast.rob.util.ob.OBMessage
class JrrpCommand : BaseCommand() {
override val commandName = "/jrrp"
override val commandNames = listOf("/jrrp", "/今日人品")
private val jrrpManager = JrrpManager()
@@ -18,7 +18,7 @@ import cn.rtast.rob.util.ob.OBMessage
import java.time.Instant
class MusicCommand : BaseCommand() {
override val commandName = "/music"
override val commandNames = listOf("/music", "/点歌")
private val searchedResult = mutableMapOf<Long, List<SearchedResult>>()
@@ -15,7 +15,7 @@ import cn.rtast.rob.util.ob.OBMessage
private val signManager = SignManager()
class SignCommand : BaseCommand() {
override val commandName = "/签到"
override val commandNames = listOf("/签到", "/sign")
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
if (signManager.isSigned(message.sender.userId)) {
@@ -28,7 +28,7 @@ class SignCommand : BaseCommand() {
}
class MyPointCommand: BaseCommand() {
override val commandName = "/我的分数"
override val commandNames = listOf("/我的分数", "/mp")
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
val status = signManager.getStatus(message.sender.userId)
@@ -7,6 +7,12 @@
package cn.rtast.fancybot.entity
import cn.rtast.fancybot.entity.enums.WSType
data class Config(
val cnmApi: String,
val ncmAPI: String,
val wsType: WSType,
val wsAddress: String,
val accessToken: String,
val port: Int,
)
@@ -0,0 +1,12 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/8/30
*/
package cn.rtast.fancybot.entity.enums
enum class WSType {
Client, Server
}
@@ -11,6 +11,9 @@ import cn.rtast.fancybot.entity.Config
import cn.rtast.fancybot.util.JsonFileHandler
class ConfigManager : JsonFileHandler<Config>("config.json") {
val ncmAPI get() = this.read<Config>().cnmApi
val ncmAPI get() = this.read<Config>().ncmAPI
val wsAddress get() = this.read<Config>().wsAddress
val wsPort get() = this.read<Config>().port
val accessToken get() = this.read<Config>().accessToken
val wsType get() = this.read<Config>().wsType
}
+5 -1
View File
@@ -1,3 +1,7 @@
{
"cnmApi": "https://ncm.rtast.cn"
"ncmAPI": "https://ncm.rtast.cn",
"wsType": "Client",
"wsAddress": "ws://127.0.0.1",
"accessToken": "114514",
"port": 6760
}