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()