2024-08-27 18:44:32 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 RTAkland
|
|
|
|
|
* Author: RTAkland
|
|
|
|
|
* Date: 2024/8/26
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package cn.rtast.fancybot
|
|
|
|
|
|
|
|
|
|
import cn.rtast.fancybot.commands.EchoCommand
|
|
|
|
|
import cn.rtast.fancybot.commands.JrrpCommand
|
2024-08-27 19:15:47 +08:00
|
|
|
import cn.rtast.fancybot.commands.MusicCommand
|
2024-08-30 14:24:46 +08:00
|
|
|
import cn.rtast.fancybot.commands.MyPointCommand
|
|
|
|
|
import cn.rtast.fancybot.commands.SignCommand
|
|
|
|
|
import cn.rtast.fancybot.util.file.ConfigManager
|
2024-08-27 18:44:32 +08:00
|
|
|
import cn.rtast.rob.ROneBotFactory
|
|
|
|
|
import cn.rtast.rob.entity.GroupMessage
|
|
|
|
|
import cn.rtast.rob.util.ob.OBMessage
|
2024-08-29 14:36:06 +08:00
|
|
|
import com.sun.net.httpserver.HttpServer
|
2024-08-27 18:44:32 +08:00
|
|
|
import org.java_websocket.WebSocket
|
2024-08-29 14:36:06 +08:00
|
|
|
import java.net.InetSocketAddress
|
2024-08-27 18:44:32 +08:00
|
|
|
|
|
|
|
|
class FancyBot : OBMessage {
|
2024-08-29 14:36:06 +08:00
|
|
|
override suspend fun onGroupMessage(websocket: WebSocket, message: GroupMessage, json: String) {
|
2024-08-27 18:44:32 +08:00
|
|
|
println(message.rawMessage)
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 14:24:46 +08:00
|
|
|
override suspend fun onWebsocketError(webSocket: WebSocket, ex: Exception) {
|
|
|
|
|
println(ex.message)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-27 19:15:47 +08:00
|
|
|
|
2024-08-29 14:36:06 +08:00
|
|
|
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...")
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 14:24:46 +08:00
|
|
|
val commands = listOf(
|
|
|
|
|
EchoCommand(),
|
|
|
|
|
JrrpCommand(),
|
|
|
|
|
MusicCommand(),
|
|
|
|
|
SignCommand(),
|
|
|
|
|
MyPointCommand()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val configManager = ConfigManager()
|
2024-08-29 14:36:06 +08:00
|
|
|
|
2024-08-27 18:44:32 +08:00
|
|
|
fun main() {
|
|
|
|
|
val address = System.getenv("WS_ADDRESS")
|
|
|
|
|
val password = System.getenv("WS_PASSWORD")
|
|
|
|
|
val fancyBot = FancyBot()
|
2024-08-27 19:15:47 +08:00
|
|
|
val wsClient = ROneBotFactory.createClient(address, password, fancyBot)
|
2024-08-27 18:44:32 +08:00
|
|
|
val commandManager = wsClient.commandManager
|
2024-08-29 14:36:06 +08:00
|
|
|
commands.forEach { commandManager.register(it) }
|
|
|
|
|
createFakeServer()
|
2024-08-27 18:44:32 +08:00
|
|
|
}
|