Files
FancyBot/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt
T

110 lines
3.7 KiB
Kotlin
Raw Normal View History

2024-08-27 18:44:32 +08:00
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/8/26
*/
package cn.rtast.fancybot
2024-09-02 11:30:58 +08:00
import cn.rtast.fancybot.commands.AntiRevokeCommand
2024-09-05 11:44:02 +08:00
import cn.rtast.fancybot.commands.CigaretteCommand
2024-08-27 18:44:32 +08:00
import cn.rtast.fancybot.commands.EchoCommand
2024-08-30 16:42:53 +08:00
import cn.rtast.fancybot.commands.FKXQSCommand
2024-09-03 16:15:26 +08:00
import cn.rtast.fancybot.commands.HelpCommand
2024-08-30 16:42:53 +08:00
import cn.rtast.fancybot.commands.HitokotoCommand
2024-08-27 18:44:32 +08:00
import cn.rtast.fancybot.commands.JrrpCommand
2024-09-03 16:15:26 +08:00
import cn.rtast.fancybot.commands.MCPingCommand
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-09-05 18:29:54 +08:00
import cn.rtast.fancybot.commands.PixivCommand
2024-08-30 21:07:08 +08:00
import cn.rtast.fancybot.commands.QRCodeCommand
2024-08-31 22:37:12 +08:00
import cn.rtast.fancybot.commands.RedeemCommand
2024-09-05 13:40:41 +08:00
import cn.rtast.fancybot.commands.RemakeCommand
2024-08-30 14:24:46 +08:00
import cn.rtast.fancybot.commands.SignCommand
2024-09-04 20:01:09 +08:00
import cn.rtast.fancybot.commands.WeatherCommand
2024-08-30 15:05:51 +08:00
import cn.rtast.fancybot.entity.enums.WSType
2024-09-03 14:37:00 +08:00
import cn.rtast.fancybot.items.BaisiItem
import cn.rtast.fancybot.items.HeisiItem
import cn.rtast.fancybot.items.SetuItem
2024-08-30 14:24:46 +08:00
import cn.rtast.fancybot.util.file.ConfigManager
2024-09-04 11:36:41 +08:00
import cn.rtast.fancybot.util.file.SignManager
import cn.rtast.fancybot.util.initDatabase
2024-09-03 16:15:26 +08:00
import cn.rtast.fancybot.util.item.ItemManager
2024-08-27 18:44:32 +08:00
import cn.rtast.rob.ROneBotFactory
2024-09-02 11:30:58 +08:00
import cn.rtast.rob.entity.GetMessage
2024-08-27 18:44:32 +08:00
import cn.rtast.rob.entity.GroupMessage
2024-09-02 11:30:58 +08:00
import cn.rtast.rob.entity.GroupRevokeMessage
import cn.rtast.rob.util.ob.MessageChain
2024-08-27 18:44:32 +08:00
import cn.rtast.rob.util.ob.OBMessage
import org.java_websocket.WebSocket
class FancyBot : OBMessage {
2024-09-02 11:30:58 +08:00
override suspend fun onGroupMessage(ws: WebSocket, message: GroupMessage, json: String) {
2024-09-03 12:32:52 +08:00
val sender = message.sender.nickname
val senderId = message.sender.userId
val msg = message.rawMessage
val groupId = message.groupId
println("$sender($senderId: $groupId): $msg")
2024-08-27 18:44:32 +08:00
}
2024-09-02 11:30:58 +08:00
override suspend fun onGroupMessageRevoke(ws: WebSocket, message: GroupRevokeMessage) {
val msg = MessageChain.Builder()
.addText("用户: ${message.userId} 被: ${message.operatorId} 撤回了一条消息")
.addNewLine()
.addText("使用/revoke ${message.messageId} 来获取被撤回的消息")
.build()
this.sendGroupMessage(message.groupId, msg)
}
override suspend fun onGetGroupMessageResponse(ws: WebSocket, message: GetMessage) {
if (message.data.id == "revoke") {
AntiRevokeCommand.getMessageCallback(this, message)
}
}
override suspend fun onWebsocketErrorEvent(ws: WebSocket, ex: Exception) {
ex.printStackTrace()
}
2024-08-29 14:36:06 +08:00
}
2024-09-04 20:01:09 +08:00
val configManager = ConfigManager()
val itemManager = ItemManager()
val signManager = SignManager()
2024-08-30 14:24:46 +08:00
2024-09-03 14:37:00 +08:00
val items = listOf(
HeisiItem(),
BaisiItem(),
SetuItem()
)
2024-09-04 20:01:09 +08:00
val commands = listOf(
EchoCommand(), JrrpCommand(),
MusicCommand(), SignCommand(),
RedeemCommand(), MyPointCommand(),
HitokotoCommand(), FKXQSCommand(),
QRCodeCommand(), AntiRevokeCommand(),
MCPingCommand(), HelpCommand(),
2024-09-05 13:40:41 +08:00
WeatherCommand(), CigaretteCommand(),
2024-09-05 18:29:54 +08:00
RemakeCommand(), PixivCommand()
2024-09-04 20:01:09 +08:00
)
2024-08-29 14:36:06 +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)
}
initDatabase()
2024-09-03 21:38:50 +08:00
val commandManager = rob.commandManager
2024-09-03 14:37:00 +08:00
commands.forEach { commandManager.register(it) }
items.forEach { itemManager.register(it) }
2024-09-03 21:38:50 +08:00
rob.addListeningGroups(*configManager.listeningGroups.toLongArray())
2024-08-27 18:44:32 +08:00
}