chore: bump dep version
This commit is contained in:
12 files changed
+58
-35
No files matched your search
@@ -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,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
|
||||
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) }
|
||||
createFakeServer()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user