版本更新为v0.1.1

新增 在对话环境下发送空参数指令时,允许在一定时间内回复一条消息作为预设消息
新增 空白消息参数表示清空预设消息
This commit is contained in:
筱傑 2021-11-04 13:10:06 +08:00
parent 4443777049
commit 310d843477
3 changed files with 42 additions and 5 deletions

View File

@ -7,7 +7,7 @@ plugins {
}
group = "me.jie65535"
version = "0.1.0"
version = "0.1.1"
repositories {
maven("https://maven.aliyun.com/repository/public")

View File

@ -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 <message> # 设置戳一戳回复消息",
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<MessageEvent>(
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}\"")
}
}

View File

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