mirror of
https://github.com/jie65535/mirai-console-jnr-plugin.git
synced 2025-06-02 17:49:11 +08:00
版本更新为v0.1.1
新增 在对话环境下发送空参数指令时,允许在一定时间内回复一条消息作为预设消息 新增 空白消息参数表示清空预设消息
This commit is contained in:
parent
4443777049
commit
310d843477
@ -7,7 +7,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "me.jie65535"
|
group = "me.jie65535"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://maven.aliyun.com/repository/public")
|
maven("https://maven.aliyun.com/repository/public")
|
||||||
|
@ -1,16 +1,53 @@
|
|||||||
package me.jie65535.jnr
|
package me.jie65535.jnr
|
||||||
|
|
||||||
|
import kotlinx.coroutines.TimeoutCancellationException
|
||||||
import net.mamoe.mirai.console.command.CommandSender
|
import net.mamoe.mirai.console.command.CommandSender
|
||||||
import net.mamoe.mirai.console.command.RawCommand
|
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.MessageChain
|
||||||
|
import net.mamoe.mirai.message.data.isContentBlank
|
||||||
|
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||||
|
|
||||||
object JNRCommand : RawCommand(
|
object JNRCommand : RawCommand(
|
||||||
JNudgeReply, "jnr", "setPokeReply", "setNudgeReply",
|
JNudgeReply, "jnr", "setPokeReply", "setNudgeReply",
|
||||||
usage = "/jnr|setPokeReply|setNudgeReply <message> # 设置戳一戳回复消息",
|
usage = "/jnr|setPokeReply|setNudgeReply <message> # 设置戳一戳回复消息",
|
||||||
description = "设置戳一戳回复消息"
|
description = "设置戳一戳回复消息"
|
||||||
) {
|
) {
|
||||||
|
private const val WAIT_REPLY_TIMEOUT_MS = 30000L
|
||||||
|
|
||||||
|
@OptIn(MiraiExperimentalApi::class)
|
||||||
override suspend fun CommandSender.onCommand(args: MessageChain) {
|
override suspend fun CommandSender.onCommand(args: MessageChain) {
|
||||||
JNRPluginConfig.replyMessage = args.serializeToMiraiCode()
|
if (args.isContentBlank()) {
|
||||||
sendMessage("OK")
|
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}\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
JvmPluginDescription(
|
JvmPluginDescription(
|
||||||
id = "me.jie65535.mirai-console-jnr-plugin",
|
id = "me.jie65535.mirai-console-jnr-plugin",
|
||||||
name = "J Nudge Reply",
|
name = "J Nudge Reply",
|
||||||
version = "0.1.0",
|
version = "0.1.1",
|
||||||
) {
|
) {
|
||||||
author("jie65535")
|
author("jie65535")
|
||||||
info("""自定义戳一戳回复插件""")
|
info("""自定义戳一戳回复插件""")
|
||||||
@ -29,7 +29,7 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
JNRCommand.register()
|
JNRCommand.register()
|
||||||
|
|
||||||
globalEventChannel().subscribeAlways<NudgeEvent>(priority = JNRPluginConfig.priority) {
|
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())
|
subject.sendMessage(JNRPluginConfig.replyMessage.deserializeMiraiCode())
|
||||||
if (JNRPluginConfig.priority != EventPriority.MONITOR && JNRPluginConfig.isIntercept)
|
if (JNRPluginConfig.priority != EventPriority.MONITOR && JNRPluginConfig.isIntercept)
|
||||||
intercept()
|
intercept()
|
||||||
|
Loading…
Reference in New Issue
Block a user