mirror of
https://github.com/jie65535/mirai-console-jnr-plugin.git
synced 2025-12-15 18:41:35 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3feff8d40e | |||
|
|
369e591ce3 | ||
|
|
310d843477 |
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# mirai-console-jnr-plugin
|
||||
MiraiConsolePlugin 自定义戳一戳回复消息
|
||||
|
||||

|
||||
@@ -7,7 +7,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "me.jie65535"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
|
||||
repositories {
|
||||
maven("https://maven.aliyun.com/repository/public")
|
||||
|
||||
BIN
doc/example.jpg
Normal file
BIN
doc/example.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 KiB |
@@ -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}\"")
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user