From 310d8434770f1ce54c7f4e23192b5cd4cc5f5ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= <840465812@qq.com> Date: Thu, 4 Nov 2021 13:10:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E4=B8=BAv0?= =?UTF-8?q?.1.1=20=E6=96=B0=E5=A2=9E=20=E5=9C=A8=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E5=8F=91=E9=80=81=E7=A9=BA=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=8C=87=E4=BB=A4=E6=97=B6=EF=BC=8C=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E5=9C=A8=E4=B8=80=E5=AE=9A=E6=97=B6=E9=97=B4=E5=86=85=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E4=B8=80=E6=9D=A1=E6=B6=88=E6=81=AF=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E9=A2=84=E8=AE=BE=E6=B6=88=E6=81=AF=20=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E6=B6=88=E6=81=AF=E5=8F=82=E6=95=B0=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E6=B8=85=E7=A9=BA=E9=A2=84=E8=AE=BE=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- src/main/kotlin/me/jie65535/jnr/JNRCommand.kt | 41 ++++++++++++++++++- .../kotlin/me/jie65535/jnr/JNudgeReply.kt | 4 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5fa953c..eafe0c4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "me.jie65535" -version = "0.1.0" +version = "0.1.1" repositories { maven("https://maven.aliyun.com/repository/public") diff --git a/src/main/kotlin/me/jie65535/jnr/JNRCommand.kt b/src/main/kotlin/me/jie65535/jnr/JNRCommand.kt index 6f246b2..6b2c1fc 100644 --- a/src/main/kotlin/me/jie65535/jnr/JNRCommand.kt +++ b/src/main/kotlin/me/jie65535/jnr/JNRCommand.kt @@ -1,16 +1,53 @@ package me.jie65535.jnr +import kotlinx.coroutines.TimeoutCancellationException import net.mamoe.mirai.console.command.CommandSender import net.mamoe.mirai.console.command.RawCommand +import net.mamoe.mirai.console.command.isUser +import net.mamoe.mirai.event.events.MessageEvent +import net.mamoe.mirai.event.nextEventAsync import net.mamoe.mirai.message.data.MessageChain +import net.mamoe.mirai.message.data.isContentBlank +import net.mamoe.mirai.utils.MiraiExperimentalApi object JNRCommand : RawCommand( JNudgeReply, "jnr", "setPokeReply", "setNudgeReply", usage = "/jnr|setPokeReply|setNudgeReply # 设置戳一戳回复消息", description = "设置戳一戳回复消息" ) { + private const val WAIT_REPLY_TIMEOUT_MS = 30000L + + @OptIn(MiraiExperimentalApi::class) override suspend fun CommandSender.onCommand(args: MessageChain) { - JNRPluginConfig.replyMessage = args.serializeToMiraiCode() - sendMessage("OK") + if (args.isContentBlank()) { + if (this.isUser()) { + try { + sendMessage("请在${WAIT_REPLY_TIMEOUT_MS / 1000}秒内发送要回复的消息内容,你可以发送空白消息来清空预设回复。") + val msg = subject.nextEventAsync( + WAIT_REPLY_TIMEOUT_MS, + coroutineContext = this.coroutineContext + ) { it.sender == user } .await() + if (msg.message.isContentBlank()) { + setReplyMessage(null) + } else { + setReplyMessage(msg.message) + } + sendMessage("OK") + } catch (e: TimeoutCancellationException) { + sendMessage("已取消") + } + } else { + setReplyMessage(null) + sendMessage("已清空预设回复") + } + } else { + setReplyMessage(args) + sendMessage("OK") + } + } + + private fun setReplyMessage(message: MessageChain?) { + JNRPluginConfig.replyMessage = message?.serializeToMiraiCode() ?: "" + JNudgeReply.logger.info("已设置戳一戳回复内容 \"${JNRPluginConfig.replyMessage}\"") } } \ No newline at end of file diff --git a/src/main/kotlin/me/jie65535/jnr/JNudgeReply.kt b/src/main/kotlin/me/jie65535/jnr/JNudgeReply.kt index e992d5e..97784a4 100644 --- a/src/main/kotlin/me/jie65535/jnr/JNudgeReply.kt +++ b/src/main/kotlin/me/jie65535/jnr/JNudgeReply.kt @@ -18,7 +18,7 @@ object JNudgeReply : KotlinPlugin( JvmPluginDescription( id = "me.jie65535.mirai-console-jnr-plugin", name = "J Nudge Reply", - version = "0.1.0", + version = "0.1.1", ) { author("jie65535") info("""自定义戳一戳回复插件""") @@ -29,7 +29,7 @@ object JNudgeReply : KotlinPlugin( JNRCommand.register() globalEventChannel().subscribeAlways(priority = JNRPluginConfig.priority) { - if (target.id == bot.id && JNRPluginConfig.replyMessage.isNotEmpty()) { + if (target.id == bot.id && JNRPluginConfig.replyMessage.isNotBlank()) { subject.sendMessage(JNRPluginConfig.replyMessage.deserializeMiraiCode()) if (JNRPluginConfig.priority != EventPriority.MONITOR && JNRPluginConfig.isIntercept) intercept()