From 41463b8b181523f172c7151dff117cbd93b1c157 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Thu, 24 Oct 2024 16:55:14 +0800 Subject: [PATCH] feat: migrate to multi-instance ronebot --- gradle/libs.versions.toml | 2 +- src/main/kotlin/cn/rtast/fancybot/Const.kt | 3 +- src/main/kotlin/cn/rtast/fancybot/FancyBot.kt | 54 ++++++++++--------- .../cn/rtast/fancybot/commands/EchoCommand.kt | 5 +- .../fancybot/commands/lookup/AICommand.kt | 5 +- .../commands/lookup/AnimeSearchCommand.kt | 3 +- .../fancybot/commands/lookup/MusicCommand.kt | 10 ++-- .../fancybot/commands/lookup/ShotCommand.kt | 9 ++-- .../commands/lookup/WeatherCommand.kt | 6 +-- .../commands/misc/AntiRevokeCommand.kt | 5 +- .../fancybot/commands/misc/CompilerCommand.kt | 2 +- .../fancybot/commands/misc/JrrpCommand.kt | 4 +- .../fancybot/commands/misc/JueCommand.kt | 2 +- .../commands/misc/MinecraftCommand.kt | 1 - .../fancybot/commands/misc/RUACommand.kt | 6 +-- .../commands/misc/RandomMusicCommand.kt | 2 +- .../fancybot/commands/misc/ReactionCommand.kt | 12 ++--- .../fancybot/commands/misc/RemakeCommand.kt | 2 +- .../fancybot/commands/misc/RepeatCommand.kt | 14 ----- .../fancybot/commands/misc/SendLikeCommand.kt | 5 +- .../fancybot/commands/misc/TTSCommand.kt | 2 +- .../fancybot/commands/misc/ZiBiCommand.kt | 3 +- .../fancybot/commands/niuzi/MyNiuziCommand.kt | 2 +- .../commands/niuzi/NiuziBankCommand.kt | 3 +- .../commands/niuzi/NiuziJiJianCommand.kt | 4 +- .../commands/niuzi/NiuziManagerCommand.kt | 1 - .../commands/niuzi/NiuziSignCommand.kt | 2 +- .../commands/parse/BilibiliParseCommand.kt | 4 +- .../cn/rtast/fancybot/util/misc/ImageBed.kt | 4 +- .../cn/rtast/fancybot/util/misc/Misc.kt | 12 ++--- 30 files changed, 88 insertions(+), 101 deletions(-) delete mode 100644 src/main/kotlin/cn/rtast/fancybot/commands/misc/RepeatCommand.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c6b85bb..6cdc9e8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] kotlinVersion = "2.0.20" -ronebotVersion = "1.14.1" +ronebotVersion = "2.0.2-SNAPSHOT" shadowVersion = "8.3.0" okhttpVersion = "5.0.0-alpha.14" exposedVersion = "0.53.0" diff --git a/src/main/kotlin/cn/rtast/fancybot/Const.kt b/src/main/kotlin/cn/rtast/fancybot/Const.kt index 84d614f..fa80adb 100644 --- a/src/main/kotlin/cn/rtast/fancybot/Const.kt +++ b/src/main/kotlin/cn/rtast/fancybot/Const.kt @@ -34,7 +34,6 @@ import cn.rtast.fancybot.util.file.NiuziBankManager import cn.rtast.fancybot.util.file.NiuziManager import cn.rtast.fancybot.util.file.RCONManager import cn.rtast.fancybot.util.item.ItemManager -import cn.rtast.rob.ROneBotFactory import com.google.gson.Gson import com.google.gson.GsonBuilder import java.time.Instant @@ -115,7 +114,7 @@ val items = listOf( val tasks = mapOf( 10000000L to suspend { configManager.admins.forEach { - ROneBotFactory.action.sendLike(it, 1) + instance.action.sendLike(it, 1) } } ) diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index 9b07ea8..2f10e92 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -31,6 +31,7 @@ import cn.rtast.rob.util.ob.MessageChain import cn.rtast.rob.util.ob.OneBotListener import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import java.io.File import java.net.URI @@ -41,7 +42,7 @@ class FancyBot : OneBotListener { private val coroutineScope = CoroutineScope(Dispatchers.IO) override suspend fun onWebsocketOpenEvent() { - this.sendPrivateMessage(configManager.noticeUser, "FancyBot启动完成~") + instance.action.sendPrivateMessage(configManager.noticeUser, "FancyBot启动完成~") } override suspend fun onGroupMessage(message: GroupMessage, json: String) { @@ -57,11 +58,11 @@ class FancyBot : OneBotListener { message.reply("你发牛魔的火车呢, 我直接就是打断") } - if (message.rawMessage.contains("原神")) { - (0..10).forEach { _ -> - message.reaction(QQFace.entries.random()) - } + if (message.text.contains("原神")) { + (0..10).forEach { _ -> message.reaction(QQFace.entries.random()) } message.reply("你原神牛魔呢") + delay(1500L) + message.reply("但是话又说回来.....启动!!") } GitHubParseCommand.parse(message) @@ -73,7 +74,7 @@ class FancyBot : OneBotListener { DouyinVideoParseCommand.parse(message) YoutubeVideoParseCommand.parse(message) - if (message.rawMessage.toList().any { it in arrayListOf('*', '-', '/', '+', '=') }) { + if (message.text.toList().any { it in arrayListOf('*', '-', '/', '+', '=') }) { val calculateResult = CalculateCommand.parse(message.rawMessage) calculateResult?.let { message.reply(calculateResult) } } @@ -81,7 +82,7 @@ class FancyBot : OneBotListener { if (message.message.any { it.type == ArrayMessageType.reply }) { val command = message.message.reversed().find { it.type == ArrayMessageType.text }!!.data.text!! val replyId = message.message.find { it.type == ArrayMessageType.reply }!!.data.id!! - val getMsg = this.getMessage(replyId.toString().toLong()) + val getMsg = instance.action.getMessage(replyId.toString().toLong()) val plainTextContent = getMsg.message .filter { it.type == ArrayMessageType.text } .joinToString { it.data.text!! } @@ -110,7 +111,7 @@ class FancyBot : OneBotListener { } if (command.contains("reaction")) { // 使用reaction刷屏回应一条消息 - ReactionCommand.reaction(this, message, getMsg.messageId) + ReactionCommand.reaction(message) } if (command.contains("图床")) { // 将一个图片上传到图床 @@ -139,7 +140,7 @@ class FancyBot : OneBotListener { .addNewLine() .addText("使用/revoke ${message.messageId} 来获取被撤回的消息") .build() - this.sendGroupMessage(message.groupId, msg) + instance.action.sendGroupMessage(message.groupId, msg) } override suspend fun onWebsocketErrorEvent(ex: Exception) { @@ -162,7 +163,7 @@ class FancyBot : OneBotListener { .addNewLine() .addText("下次再见吧~~~") .build() - this.sendGroupMessage(groupId, msg) + instance.action.sendGroupMessage(groupId, msg) } override suspend fun onGroupPoke(event: PokeEvent) { @@ -171,36 +172,37 @@ class FancyBot : OneBotListener { .addAt(event.userId) .addText("你${event.action.first()}牛魔呢") .build() - this.sendGroupMessage(event.groupId!!, msg) + instance.action.sendGroupMessage(event.groupId!!, msg) } } override suspend fun onBeKicked(groupId: Long, operator: Long, time: Long) { blackListManager.insertGroup(groupId, operator, time) - this.sendPrivateMessage( + instance.action.sendPrivateMessage( configManager.noticeUser, "被: ${groupId}踢出! 操作人: $operator 时间: ${time.convertToDate()} 已将其拉入黑名单!" ) } } +val fancyBot = FancyBot() +val workType = configManager.wsType +val accessToken = configManager.accessToken +val instance = if (workType == WSType.Client) { + val address = configManager.wsAddress + ROneBotFactory.createClient(address, accessToken, fancyBot) + .also { it.addListeningGroups(*configManager.listeningGroups.toLongArray()) } +} else { + val port = configManager.wsPort + ROneBotFactory.createServer(port, accessToken, fancyBot) + .also { it.addListeningGroups(*configManager.listeningGroups.toLongArray()) } +} + suspend fun main() { - val fancyBot = FancyBot() - val workType = configManager.wsType - val accessToken = configManager.accessToken - val rob = if (workType == WSType.Client) { - val address = configManager.wsAddress - ROneBotFactory.createClient(address, accessToken, fancyBot) - .also { it.addListeningGroups(*configManager.listeningGroups.toLongArray()) } - } else { - val port = configManager.wsPort - ROneBotFactory.createServer(port, accessToken, fancyBot) - .also { it.addListeningGroups(*configManager.listeningGroups.toLongArray()) } - } initDatabase() initFilesDir() - initCommand(rob) + initCommand() initSetuIndex() initItems() - initBackgroundTasks(rob) + initBackgroundTasks(instance) } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/EchoCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/EchoCommand.kt index 68a9ec9..866d5fe 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/EchoCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/EchoCommand.kt @@ -8,7 +8,6 @@ package cn.rtast.fancybot.commands import cn.rtast.fancybot.annotations.CommandDescription -import cn.rtast.fancybot.configManager import cn.rtast.fancybot.enums.CommandAction import cn.rtast.fancybot.util.file.insertActionRecord import cn.rtast.rob.entity.GroupMessage @@ -21,7 +20,7 @@ class EchoCommand : BaseCommand() { override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { if (message.sender.isAdmin || message.sender.isOwner) { - listener.sendGroupMessage(message.groupId, args.joinToString(" ")) + message.reply(args.joinToString(" ")) insertActionRecord(CommandAction.Echo, message.sender.userId) } else { message.reply("你不许用echo") @@ -37,7 +36,7 @@ class ShuffleEchoCommand : BaseCommand() { if (message.sender.isAdmin || message.sender.isOwner) { message.reply(message.rawMessage.toList().shuffled().joinToString("")) insertActionRecord(CommandAction.Echo, message.sender.userId) - } else{ + } else { message.reply("你不许用echo") } } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AICommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AICommand.kt index 0ba2f17..b8c0383 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AICommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AICommand.kt @@ -14,6 +14,7 @@ import cn.rtast.fancybot.entity.gpt.ChatCompletionsResponse import cn.rtast.fancybot.entity.gpt.LlamaResponse import cn.rtast.fancybot.entity.gpt.ModelList import cn.rtast.fancybot.enums.CommandAction +import cn.rtast.fancybot.instance import cn.rtast.fancybot.util.Http import cn.rtast.fancybot.util.file.insertActionRecord import cn.rtast.fancybot.util.str.toJson @@ -69,7 +70,7 @@ class AICommand : BaseCommand() { .addText(response.choices.first().message.content) .build() nodeMsg.addMessageChain(msg, configManager.selfId) - listener.sendGroupForwardMsg(message.groupId, nodeMsg.build()) + instance.action.sendGroupForwardMsg(message.groupId, nodeMsg.build()) insertActionRecord(CommandAction.AI, message.sender.userId, "$content-$model-GPT") } } @@ -96,7 +97,7 @@ class LlamaCommand : BaseCommand() { .addText(response.message.content) .build() nodeMsg.addMessageChain(msg, configManager.selfId) - listener.sendGroupForwardMsg(message.groupId, nodeMsg.build()) + instance.action.sendGroupForwardMsg(message.groupId, nodeMsg.build()) insertActionRecord(CommandAction.AI, message.sender.userId, "$prompt-LLAMA") } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AnimeSearchCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AnimeSearchCommand.kt index 0923985..e65940d 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AnimeSearchCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/AnimeSearchCommand.kt @@ -10,6 +10,7 @@ package cn.rtast.fancybot.commands.lookup import cn.rtast.fancybot.annotations.CommandDescription import cn.rtast.fancybot.configManager import cn.rtast.fancybot.entity.bgm.BGMSearch +import cn.rtast.fancybot.instance import cn.rtast.fancybot.util.Http import cn.rtast.fancybot.util.str.encodeToBase64 import cn.rtast.rob.entity.GroupMessage @@ -58,7 +59,7 @@ class AnimeSearchCommand : BaseCommand() { } val footerNode = MessageChain.Builder().addText("数据来源: Bangumi").build() nodeMsg.addMessageChain(footerNode, configManager.selfId) - listener.sendGroupForwardMsg(message.groupId, nodeMsg.build()) + instance.action.sendGroupForwardMsg(message.groupId, nodeMsg.build()) } catch (_: Exception) { message.reply("没有搜索到结果呢~") } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/MusicCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/MusicCommand.kt index 904e365..38ed459 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/MusicCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/MusicCommand.kt @@ -63,7 +63,7 @@ class MusicCommand : BaseCommand() { val msg = MessageChain.Builder() .addMusicShare(MusicShareType.Netease, finalResult.id.toString()) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } catch (_: Exception) { message.reply("输入有误请重新搜索本次搜索结果已清除") } @@ -105,7 +105,7 @@ class MusicCommand : BaseCommand() { .addNewLine() .addText("发送`点歌 <歌名> [l|legacy]`即可使用旧版点歌系统") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } @@ -114,7 +114,7 @@ class MusicCommand : BaseCommand() { val msg = MessageChain.Builder() .addMusicShare(MusicShareType.Netease, result.toString()) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } @@ -141,7 +141,7 @@ class MusicPlayUrlCommand : BaseCommand() { .addReply(message.messageId) .addText(url) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } @@ -162,6 +162,6 @@ class QQMusicCommand : BaseCommand() { mapOf("key" to keyword) ).response.data.song.list.first().songId val msg = MessageChain.Builder().addMusicShare(MusicShareType.QQ, response.toString()).build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/ShotCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/ShotCommand.kt index 47e43d0..870dec4 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/ShotCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/ShotCommand.kt @@ -8,6 +8,7 @@ package cn.rtast.fancybot.commands.lookup import cn.rtast.fancybot.annotations.CommandDescription +import cn.rtast.fancybot.instance import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.enums.ArrayMessageType import cn.rtast.rob.util.BaseCommand @@ -30,7 +31,7 @@ class ShotSelfCommand : BaseCommand() { override val commandNames = listOf("骂我") override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { - listener.sendGroupForwardMsg(message.groupId, generateNodeMessage(message.sender.userId.toString())) + instance.action.sendGroupForwardMsg(message.groupId, generateNodeMessage(message.sender.userId.toString())) } } @@ -40,12 +41,14 @@ class ShotOtherCommand : BaseCommand() { override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { if (args.isEmpty()) { - listener.sendGroupForwardMsg(message.groupId, generateNodeMessage(message.sender.userId.toString(), 20)) + instance.action.sendGroupForwardMsg( + message.groupId, generateNodeMessage(message.sender.userId.toString(), 20) + ) return } var times = if (args.size == 1) 10 else if (args.last() == "") 10 else args.last().toInt() if (times >= 200) times = 10 val target = message.message.find { it.type == ArrayMessageType.at }?.data!! - listener.sendGroupForwardMsg(message.groupId, generateNodeMessage(target.qq!!, times)) + instance.action.sendGroupForwardMsg(message.groupId, generateNodeMessage(target.qq!!, times)) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/WeatherCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/WeatherCommand.kt index 7f30ea0..e9cde2d 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/WeatherCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/WeatherCommand.kt @@ -64,7 +64,7 @@ class WeatherCommand : BaseCommand() { .addAt(message.sender.userId) .addText("发送/weather <地区名>即可查看实时天气哦~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } try { @@ -81,13 +81,13 @@ class WeatherCommand : BaseCommand() { .addReply(message.messageId) .addImage(this.createWeatherCard(weather, lookupLocation), true) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } catch (_: NullPointerException) { val msg = MessageChain.Builder() .addAt(message.sender.userId) .addText("没有查询到该城市的天气信息哦~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/AntiRevokeCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/AntiRevokeCommand.kt index bcd542b..071dbf6 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/AntiRevokeCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/AntiRevokeCommand.kt @@ -9,6 +9,7 @@ package cn.rtast.fancybot.commands.misc import cn.rtast.fancybot.annotations.CommandDescription import cn.rtast.fancybot.enums.CommandAction +import cn.rtast.fancybot.instance import cn.rtast.fancybot.util.file.insertActionRecord import cn.rtast.rob.entity.ArrayMessage import cn.rtast.rob.entity.GroupMessage @@ -23,12 +24,12 @@ class AntiRevokeCommand : BaseCommand() { override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { if (message.sender.isAdmin || message.sender.isOwner) { val messageId = args.first().toLong() - val getMsg = listener.getMessage(messageId) + val getMsg = instance.action.getMessage(messageId) val msgList = mutableListOf() msgList.add(ArrayMessage(ArrayMessageType.at, ArrayMessage.Data(qq = message.sender.userId.toString()))) msgList.add(ArrayMessage(ArrayMessageType.text, ArrayMessage.Data(text = "\n被撤回的消息如下: \n"))) msgList.addAll(getMsg.message) - listener.sendGroupMessage(message.groupId, msgList) + instance.action.sendGroupMessage(message.groupId, msgList) insertActionRecord(CommandAction.AntiRevoke, message.sender.userId, getMsg.messageId.toString()) } else { message.reply("你不许用防撤回") diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/CompilerCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/CompilerCommand.kt index 1995d1e..6b01ced 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/CompilerCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/CompilerCommand.kt @@ -63,7 +63,7 @@ class CompilerCommand : BaseCommand() { .addNewLine() .addText(response.replace("", "").replace("", "")) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } catch (e: Exception) { message.reply("执行错误: ${e.message}") } finally { diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/JrrpCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/JrrpCommand.kt index 693f710..0ab48c2 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/JrrpCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/JrrpCommand.kt @@ -26,7 +26,7 @@ class JrrpCommand : BaseCommand() { .addAt(message.sender.userId) .addText("你今天已经今日人品过啦, 明天再来吧~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } val randomPoint = jrrpManager.jrrp(message.sender.userId) @@ -41,6 +41,6 @@ class JrrpCommand : BaseCommand() { .addAt(message.sender.userId) .addText("$scoreDesc($randomPoint)") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/JueCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/JueCommand.kt index 51ccb0d..3ac6ef9 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/JueCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/JueCommand.kt @@ -62,6 +62,6 @@ class JueCommand : BaseCommand() { val source = message.sender.userId.toString() val gif = this.createJueGIF(source, target) val msg = MessageChain.Builder().addImage(gif, true).build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/MinecraftCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/MinecraftCommand.kt index 556c817..f1e46f4 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/MinecraftCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/MinecraftCommand.kt @@ -57,7 +57,6 @@ import okhttp3.FormBody import java.awt.AlphaComposite import java.awt.Color import java.awt.image.BufferedImage -import java.net.InetAddress import java.net.SocketException import java.net.URI import java.util.concurrent.Executors diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RUACommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RUACommand.kt index 80430c8..d894b18 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RUACommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RUACommand.kt @@ -25,7 +25,7 @@ class RUACommand : BaseCommand() { .addText("使用rua @xxxx") .addText("即可rua某人啦~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } try { @@ -38,13 +38,13 @@ class RUACommand : BaseCommand() { .addText(" ") .addText("rua了你~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } catch (_: NullPointerException) { val msg = MessageChain.Builder() .addAt(message.sender.userId) .addText("要@才有用哦~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RandomMusicCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RandomMusicCommand.kt index 2f107f5..0266999 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RandomMusicCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RandomMusicCommand.kt @@ -28,6 +28,6 @@ class RandomMusicCommand : BaseCommand() { val msg = MessageChain.Builder() .addMusicShare(MusicShareType.Netease, id.toString()) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/ReactionCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/ReactionCommand.kt index 8b9db01..e3ea9e8 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/ReactionCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/ReactionCommand.kt @@ -18,17 +18,11 @@ class ReactionCommand : BaseCommand() { override val commandNames = listOf("reaction", "回应") companion object { - suspend fun reaction(listener: OneBotListener, message: GroupMessage, messageId: Long, limit: Int = 30) { - (0..limit - 1).forEach { - listener.reaction( - message.groupId, - messageId, - QQFace.entries.random().id.toString() - ) - } + suspend fun reaction(message: GroupMessage, limit: Int = 30) { + (0..limit - 1).forEach { message.reaction(QQFace.entries.random()) } } } override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) = - reaction(listener, message, message.messageId) + reaction(message) } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RemakeCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RemakeCommand.kt index b9d688a..65ab2a7 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RemakeCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RemakeCommand.kt @@ -40,6 +40,6 @@ class RemakeCommand : BaseCommand() { msg.addText("重开成功! 你转生在${country.chineseName}的$location, 是一个$role") } else msg.addText("转生失败~") - listener.sendGroupMessage(message.groupId, msg.build()) + message.reply(msg.build()) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RepeatCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/RepeatCommand.kt deleted file mode 100644 index add7043..0000000 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/RepeatCommand.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright © 2024 RTAkland - * Author: RTAkland - * Date: 2024/10/15 - */ - - -package cn.rtast.fancybot.commands.misc - -import cn.rtast.fancybot.annotations.CommandDescription - -@CommandDescription("复读鸡") -object RepeatCommand { -} \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/SendLikeCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/SendLikeCommand.kt index b9fb04b..6f4440e 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/SendLikeCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/SendLikeCommand.kt @@ -8,6 +8,7 @@ package cn.rtast.fancybot.commands.misc import cn.rtast.fancybot.annotations.CommandDescription +import cn.rtast.fancybot.instance import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.util.BaseCommand import cn.rtast.rob.util.ob.MessageChain @@ -18,11 +19,11 @@ class SendLikeCommand : BaseCommand() { override val commandNames = listOf("赞我") override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { - listener.sendLike(message.sender.userId, 10) + instance.action.sendLike(message.sender.userId, 10) val msg = MessageChain.Builder() .addReply(message.messageId) .addText("👍了你十下~~😁") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/TTSCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/TTSCommand.kt index 2263089..4ea284f 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/TTSCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/TTSCommand.kt @@ -38,6 +38,6 @@ class TTSCommand : BaseCommand() { val msg = MessageChain.Builder() .addRecord(response.url.proxy) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/ZiBiCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/ZiBiCommand.kt index ea573e6..8dd709d 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/ZiBiCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/ZiBiCommand.kt @@ -8,6 +8,7 @@ package cn.rtast.fancybot.commands.misc import cn.rtast.fancybot.annotations.CommandDescription +import cn.rtast.fancybot.instance import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.entity.PrivateMessage import cn.rtast.rob.util.BaseCommand @@ -55,7 +56,7 @@ class UnsetZiBiCommand : BaseCommand() { message.reply(msg) return } - listener.setGroupBan(users.getValue(message.sender.userId), message.sender.userId, 0) + instance.action.setGroupBan(users.getValue(message.sender.userId), message.sender.userId, 0) val msg = MessageChain.Builder() .addText("祝你天天开心不要自闭~~") .build() diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/MyNiuziCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/MyNiuziCommand.kt index 76a089b..921d979 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/MyNiuziCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/MyNiuziCommand.kt @@ -37,6 +37,6 @@ class MyNiuziCommand : BaseCommand() { else -> "牛子也太长啦把天捅穿啦!!!!!!" } msg.addText(niuziString) - listener.sendGroupMessage(message.groupId, msg.build()) + message.reply(msg.build()) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt index b41fee7..54c94bd 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt @@ -9,6 +9,7 @@ package cn.rtast.fancybot.commands.niuzi import cn.rtast.fancybot.annotations.CommandDescription import cn.rtast.fancybot.commands +import cn.rtast.fancybot.instance import cn.rtast.fancybot.niuziBankManager import cn.rtast.fancybot.niuziManager import cn.rtast.fancybot.util.misc.getUserName @@ -68,7 +69,7 @@ class CreateBankAccountCommand : BaseCommand() { message.reply("你已经有账户了!") return } - val userInfo = listener.getGroupMemberInfo(message.groupId, message.sender.userId) + val userInfo = instance.action.getGroupMemberInfo(message.groupId, message.sender.userId) niuziBankManager.createBlankAccount(message.sender.userId, userInfo.card ?: userInfo.nickname) message.reply("成功创建了一个账户!") } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziJiJianCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziJiJianCommand.kt index e7e6085..5cdc455 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziJiJianCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziJiJianCommand.kt @@ -34,7 +34,7 @@ class NiuziJiJianCommand : BaseCommand() { .addNewLine() .addText("所以你不能和他们击剑~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } if (message.sender.userId == targetId) { @@ -69,7 +69,7 @@ class NiuziJiJianCommand : BaseCommand() { .addNewLine() .addText("对方的牛子增加了${result.second}cm~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziManagerCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziManagerCommand.kt index dbe34dc..23f7ea4 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziManagerCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziManagerCommand.kt @@ -8,7 +8,6 @@ package cn.rtast.fancybot.commands.niuzi import cn.rtast.fancybot.annotations.CommandDescription -import cn.rtast.fancybot.configManager import cn.rtast.fancybot.niuziBankManager import cn.rtast.fancybot.niuziManager import cn.rtast.fancybot.util.misc.getUserName diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt index 38a17cd..f271200 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt @@ -32,6 +32,6 @@ class NiuziSignCommand : BaseCommand() { .addNewLine() .addText("你的牛子增加了${afterStatus.first}cm~ 总长度为: ${afterStatus.second?.length}") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/parse/BilibiliParseCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/parse/BilibiliParseCommand.kt index 8bc0833..77c4704 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/parse/BilibiliParseCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/parse/BilibiliParseCommand.kt @@ -233,7 +233,7 @@ object BiliVideoParseCommand { .addImage(image, true) .addText(shortUrl) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } catch (_: Exception) { } } @@ -285,7 +285,7 @@ object BiliUserParseCommand { val msg = MessageChain.Builder() .addImage(userCardImage, true) .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/util/misc/ImageBed.kt b/src/main/kotlin/cn/rtast/fancybot/util/misc/ImageBed.kt index 208b3c0..4d9fb2d 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/misc/ImageBed.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/misc/ImageBed.kt @@ -11,11 +11,11 @@ import cn.rtast.fancybot.configManager import cn.rtast.fancybot.entity.github.UploadContentPayload import cn.rtast.fancybot.entity.github.UploadContentResponse import cn.rtast.fancybot.enums.ImageBedType +import cn.rtast.fancybot.instance import cn.rtast.fancybot.util.Http import cn.rtast.fancybot.util.str.encodeToBase64 import cn.rtast.fancybot.util.str.proxy import cn.rtast.fancybot.util.str.toJson -import cn.rtast.rob.ROneBotFactory import software.amazon.awssdk.auth.credentials.AwsBasicCredentials import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider import software.amazon.awssdk.core.sync.RequestBody @@ -68,7 +68,7 @@ object ImageBed { return "${configManager.cloudflareR2PublicUrl}/$key".proxy } - ImageBedType.QQ -> ROneBotFactory.action.uploadImage(file.encodeToBase64(), true) + ImageBedType.QQ -> instance.action.uploadImage(file.encodeToBase64(), true) } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/util/misc/Misc.kt b/src/main/kotlin/cn/rtast/fancybot/util/misc/Misc.kt index 821afbc..99d5258 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/misc/Misc.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/misc/Misc.kt @@ -9,6 +9,7 @@ package cn.rtast.fancybot.util.misc import cn.rtast.fancybot.* import cn.rtast.fancybot.util.Http +import cn.rtast.rob.BotInstance import cn.rtast.rob.ROneBotFactory import cn.rtast.rob.util.ob.OneBotListener import java.io.File @@ -20,13 +21,12 @@ fun randomBooleanWithProbability(probability: Double): Boolean { } suspend fun OneBotListener.getUserName(groupId: Long, userId: Long): String { - val info = this.getGroupMemberInfo(groupId, userId) + val info = instance.action.getGroupMemberInfo(groupId, userId) return info.card ?: info.nickname } -fun initCommand(rob: ROneBotFactory) { - val commandManager = rob.commandManager - commands.forEach { commandManager.register(it) } +fun initCommand() { + commands.forEach { ROneBotFactory.commandManager.register(it) } } fun initFilesDir() { @@ -47,6 +47,6 @@ fun initItems() { items.forEach { itemManager.register(it) } } -fun initBackgroundTasks(rob: ROneBotFactory) { - tasks.forEach { rob.scheduler.scheduleTask(it.value, 1000L, it.key) } +fun initBackgroundTasks(instance: BotInstance) { + tasks.forEach { instance.scheduler.scheduleTask(it.value, 1000L, it.key) } } \ No newline at end of file