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
|
2024-08-30 16:42:53 +08:00
|
|
|
import cn.rtast.fancybot.commands.FKXQSCommand
|
|
|
|
|
import cn.rtast.fancybot.commands.HitokotoCommand
|
2024-08-27 18:44:32 +08:00
|
|
|
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
|
2024-08-30 21:07:08 +08:00
|
|
|
import cn.rtast.fancybot.commands.QRCodeCommand
|
2024-08-30 14:24:46 +08:00
|
|
|
import cn.rtast.fancybot.commands.SignCommand
|
2024-08-30 15:05:51 +08:00
|
|
|
import cn.rtast.fancybot.entity.enums.WSType
|
2024-08-30 14:24:46 +08:00
|
|
|
import cn.rtast.fancybot.util.file.ConfigManager
|
2024-08-30 17:50:01 +08:00
|
|
|
import cn.rtast.fancybot.util.initDatabase
|
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
|
|
|
|
|
import org.java_websocket.WebSocket
|
|
|
|
|
|
|
|
|
|
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 17:50:01 +08:00
|
|
|
|
|
|
|
|
override suspend fun onWebsocketError(webSocket: WebSocket, ex: Exception) {
|
|
|
|
|
println(ex.printStackTrace())
|
|
|
|
|
}
|
2024-08-29 14:36:06 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-30 14:24:46 +08:00
|
|
|
val commands = listOf(
|
|
|
|
|
EchoCommand(),
|
|
|
|
|
JrrpCommand(),
|
|
|
|
|
MusicCommand(),
|
|
|
|
|
SignCommand(),
|
2024-08-30 16:42:53 +08:00
|
|
|
MyPointCommand(),
|
|
|
|
|
HitokotoCommand(),
|
2024-08-30 21:07:08 +08:00
|
|
|
FKXQSCommand(),
|
|
|
|
|
QRCodeCommand()
|
2024-08-30 14:24:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val configManager = ConfigManager()
|
2024-08-29 14:36:06 +08:00
|
|
|
|
2024-08-30 17:50:01 +08:00
|
|
|
suspend fun main() {
|
2024-08-27 18:44:32 +08:00
|
|
|
val fancyBot = FancyBot()
|
2024-08-30 15:05:51 +08:00
|
|
|
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
|
2024-08-29 14:36:06 +08:00
|
|
|
commands.forEach { commandManager.register(it) }
|
2024-08-30 17:50:01 +08:00
|
|
|
initDatabase()
|
2024-08-27 18:44:32 +08:00
|
|
|
}
|