From b2090cc09b884aeaf6886b517581a992c4ca3a69 Mon Sep 17 00:00:00 2001 From: dongRogen <3601778801@qq.com> Date: Tue, 9 Aug 2022 20:32:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E9=97=B2=E7=BD=AE=E7=8A=B6=E6=80=81=E7=9A=84=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/top/jie65535/jcf/PluginCommands.kt | 41 ++++++++++++++++++- .../kotlin/top/jie65535/jcf/PluginConfig.kt | 4 +- .../kotlin/top/jie65535/jcf/PluginMain.kt | 2 +- .../top/jie65535/jcf/SubscribeHandler.kt | 3 +- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/top/jie65535/jcf/PluginCommands.kt b/src/main/kotlin/top/jie65535/jcf/PluginCommands.kt index e5a1b63..e78a0c7 100644 --- a/src/main/kotlin/top/jie65535/jcf/PluginCommands.kt +++ b/src/main/kotlin/top/jie65535/jcf/PluginCommands.kt @@ -20,4 +20,43 @@ object PluginCommands : CompositeCommand(PluginMain, "jcf") { } sendMessage(msg.toString()) } -} \ No newline at end of file + + @SubCommand + @Description("设置订阅信息推送bot(qq id)") + suspend fun CommandSender.setSubsSender(sender: Long) { + PluginConfig.subscribeSender = sender + sendMessage("OK! ") + } + + @SubCommand + @Description("设置检查间隔(单位:秒)") + suspend fun CommandSender.setCheckInterval(second: Long) { + PluginConfig.checkInterval = second + sendMessage("OK! 将在下次检查结束后应用") + } + + @SubCommand + @Description("查看订阅处理的状态") + suspend fun CommandSender.subStat() { + val subs = PluginMain.subscribeHandler + if (subs.isIdle) { + sendMessage("订阅器闲置中") + } else { + sendMessage("订阅处理正常运行中") + } + } + + @SubCommand + @Description("使订阅器闲置") + suspend fun CommandSender.idleSubs() { + PluginMain.subscribeHandler.idle() + sendMessage("OK,已闲置") + } + + @SubCommand + @Description("使订阅器恢复运行") + suspend fun CommandSender.runSubs() { + PluginMain.subscribeHandler.start() + sendMessage("OK,已恢复订阅处理") + } +} diff --git a/src/main/kotlin/top/jie65535/jcf/PluginConfig.kt b/src/main/kotlin/top/jie65535/jcf/PluginConfig.kt index cf2f418..39d78b2 100644 --- a/src/main/kotlin/top/jie65535/jcf/PluginConfig.kt +++ b/src/main/kotlin/top/jie65535/jcf/PluginConfig.kt @@ -25,11 +25,11 @@ object PluginConfig : AutoSavePluginConfig("JCurseforgeConfig") { * 订阅信息推送bot */ @ValueDescription("订阅信息推送bot(qq id)") - val subscribeSender: Long by value(-1L) + var subscribeSender: Long by value(-1L) /** * 检查间隔 */ @ValueDescription("检查间隔(单位:秒)") - val checkInterval: Long by value(60 * 60 * 4L) + var checkInterval: Long by value(60 * 60 * 4L) } diff --git a/src/main/kotlin/top/jie65535/jcf/PluginMain.kt b/src/main/kotlin/top/jie65535/jcf/PluginMain.kt index ebe9a1f..21e941d 100644 --- a/src/main/kotlin/top/jie65535/jcf/PluginMain.kt +++ b/src/main/kotlin/top/jie65535/jcf/PluginMain.kt @@ -43,7 +43,7 @@ object PluginMain: KotlinPlugin( launch { subscribeHandler.load(this) } - subscribeHandler.start()// TODO 添加可切换闲置状态的命令 + subscribeHandler.start() logger.info { "Plugin Enabled" } } } diff --git a/src/main/kotlin/top/jie65535/jcf/SubscribeHandler.kt b/src/main/kotlin/top/jie65535/jcf/SubscribeHandler.kt index 980df73..0a8b3ac 100644 --- a/src/main/kotlin/top/jie65535/jcf/SubscribeHandler.kt +++ b/src/main/kotlin/top/jie65535/jcf/SubscribeHandler.kt @@ -224,14 +224,13 @@ class SubscribeHandler( */ private fun CoroutineScope.loop() = launch { val senderQQ = PluginConfig.subscribeSender - val interval = PluginConfig.checkInterval if (senderQQ < 0) { logger.warning("必须配置订阅信息推送bot(qq id)才可以进行订阅推送!") logger.warning("插件会持续收集订阅与检查mod更新,但无法进行消息推送。") } logger.info("subscription listening") while (true) { - delay(1000 * interval) + delay(1000 * PluginConfig.checkInterval) if (isIdle) continue val subSet = HashMap(PluginData.subscriptionSet)