mirror of
https://github.com/jie65535/mirai-console-jnr-plugin.git
synced 2025-10-20 17:13:00 +08:00
Initial commit
This commit is contained in:
16
src/main/kotlin/me/jie65535/jnr/JNRCommand.kt
Normal file
16
src/main/kotlin/me/jie65535/jnr/JNRCommand.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package me.jie65535.jnr
|
||||
|
||||
import net.mamoe.mirai.console.command.CommandSender
|
||||
import net.mamoe.mirai.console.command.RawCommand
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
|
||||
object JNRCommand : RawCommand(
|
||||
JNudgeReply, "jnr", "setPokeReply", "setNudgeReply",
|
||||
usage = "/jnr|setPokeReply|setNudgeReply <message> # 设置戳一戳回复消息",
|
||||
description = "设置戳一戳回复消息"
|
||||
) {
|
||||
override suspend fun CommandSender.onCommand(args: MessageChain) {
|
||||
JNRPluginConfig.replyMessage = args.serializeToMiraiCode()
|
||||
sendMessage("OK")
|
||||
}
|
||||
}
|
36
src/main/kotlin/me/jie65535/jnr/JNRPluginConfig.kt
Normal file
36
src/main/kotlin/me/jie65535/jnr/JNRPluginConfig.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package me.jie65535.jnr
|
||||
|
||||
import net.mamoe.mirai.console.data.AutoSavePluginConfig
|
||||
import net.mamoe.mirai.console.data.ValueDescription
|
||||
import net.mamoe.mirai.console.data.value
|
||||
import net.mamoe.mirai.event.EventPriority
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
import net.mamoe.mirai.message.data.MessageChainBuilder
|
||||
|
||||
/**
|
||||
* 插件配置
|
||||
*/
|
||||
object JNRPluginConfig : AutoSavePluginConfig("jnr") {
|
||||
/**
|
||||
* 回复的消息
|
||||
* @see Message
|
||||
*/
|
||||
@ValueDescription("戳一戳回复的消息")
|
||||
var replyMessage: String by value()
|
||||
|
||||
/**
|
||||
* 优先级 默认为高
|
||||
* @see EventPriority
|
||||
*/
|
||||
@ValueDescription("事件优先级 从高到低可选 HIGHEST, HIGH, NORMAL, LOW, LOWEST, MONITOR\n" +
|
||||
"设置后需要重启插件生效")
|
||||
var priority: EventPriority by value(EventPriority.HIGH)
|
||||
|
||||
/**
|
||||
* 是否拦截事件 为true时优先级较低的
|
||||
* @see EventPriority
|
||||
*/
|
||||
@ValueDescription("是否拦截事件 回复后可阻止其它插件响应戳一戳事件 优先级为MONITOR时拦截无效")
|
||||
var isIntercept: Boolean by value(true)
|
||||
}
|
41
src/main/kotlin/me/jie65535/jnr/JNudgeReply.kt
Normal file
41
src/main/kotlin/me/jie65535/jnr/JNudgeReply.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package me.jie65535.jnr
|
||||
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister
|
||||
import net.mamoe.mirai.console.data.AutoSavePluginConfig
|
||||
import net.mamoe.mirai.console.data.value
|
||||
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
||||
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
||||
import net.mamoe.mirai.event.EventPriority
|
||||
import net.mamoe.mirai.event.events.NudgeEvent
|
||||
import net.mamoe.mirai.event.globalEventChannel
|
||||
import net.mamoe.mirai.message.code.MiraiCode.deserializeMiraiCode
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.isContentBlank
|
||||
import net.mamoe.mirai.utils.info
|
||||
|
||||
object JNudgeReply : KotlinPlugin(
|
||||
JvmPluginDescription(
|
||||
id = "me.jie65535.mirai-console-jnr-plugin",
|
||||
name = "J Nudge Reply",
|
||||
version = "0.1.0",
|
||||
) {
|
||||
author("jie65535")
|
||||
info("""自定义戳一戳回复插件""")
|
||||
}
|
||||
) {
|
||||
override fun onEnable() {
|
||||
JNRPluginConfig.reload()
|
||||
JNRCommand.register()
|
||||
|
||||
globalEventChannel().subscribeAlways<NudgeEvent>(priority = JNRPluginConfig.priority) {
|
||||
if (target.id == bot.id && JNRPluginConfig.replyMessage.isNotEmpty()) {
|
||||
subject.sendMessage(JNRPluginConfig.replyMessage.deserializeMiraiCode())
|
||||
if (JNRPluginConfig.priority != EventPriority.MONITOR && JNRPluginConfig.isIntercept)
|
||||
intercept()
|
||||
}
|
||||
}
|
||||
|
||||
logger.info { "Plugin loaded" }
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
me.jie65535.jnr.JNudgeReply
|
Reference in New Issue
Block a user