mirror of
https://github.com/jie65535/mirai-console-jnr-plugin.git
synced 2025-06-02 17:49:11 +08:00
feat: 添加特殊响应动作
包括回戳 / 禁言用户 在抽取回复方式时会按需过滤掉仅群组可用的动作
This commit is contained in:
parent
551a792c04
commit
18adb49cdd
@ -1,8 +1,13 @@
|
|||||||
package top.jie65535.jnr
|
package top.jie65535.jnr
|
||||||
|
|
||||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
|
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
|
||||||
|
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
||||||
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
||||||
|
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||||
|
import net.mamoe.mirai.contact.Group
|
||||||
|
import net.mamoe.mirai.contact.Member
|
||||||
|
import net.mamoe.mirai.contact.PermissionDeniedException
|
||||||
import net.mamoe.mirai.event.EventPriority
|
import net.mamoe.mirai.event.EventPriority
|
||||||
import net.mamoe.mirai.event.events.NudgeEvent
|
import net.mamoe.mirai.event.events.NudgeEvent
|
||||||
import net.mamoe.mirai.event.globalEventChannel
|
import net.mamoe.mirai.event.globalEventChannel
|
||||||
@ -26,11 +31,17 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
Random.nextInt()
|
Random.nextInt()
|
||||||
globalEventChannel().subscribeAlways<NudgeEvent>(priority = JNRPluginConfig.priority) {
|
globalEventChannel().subscribeAlways<NudgeEvent>(priority = JNRPluginConfig.priority) {
|
||||||
if (target.id == bot.id && JNRPluginConfig.replyMessageList.isNotEmpty()) {
|
if (target.id == bot.id && JNRPluginConfig.replyMessageList.isNotEmpty()) {
|
||||||
val totalWeight = JNRPluginConfig.replyMessageList.sumOf { it.weight }
|
val replyList = if(subject is Group){
|
||||||
|
JNRPluginConfig.replyMessageList
|
||||||
|
}else{
|
||||||
|
// 非群聊时过滤部分特殊指令
|
||||||
|
JNRPluginConfig.replyMessageList.filter { !it.message.startsWith("#group") }
|
||||||
|
}
|
||||||
|
val totalWeight = replyList.sumOf { it.weight }
|
||||||
var w = Random.nextInt(totalWeight)
|
var w = Random.nextInt(totalWeight)
|
||||||
for (msg in JNRPluginConfig.replyMessageList) {
|
for (msg in replyList) {
|
||||||
if (w < msg.weight) {
|
if (w < msg.weight) {
|
||||||
subject.sendMessage(msg.message.deserializeMiraiCode())
|
doReply(msg, this)
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
w -= msg.weight
|
w -= msg.weight
|
||||||
@ -43,4 +54,30 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
|
|
||||||
logger.info { "Plugin loaded" }
|
logger.info { "Plugin loaded" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCommandDescriptors::class, ConsoleExperimentalApi::class)
|
||||||
|
suspend fun doReply(message: ReplyMessage, event: NudgeEvent) {
|
||||||
|
if(message.message.startsWith("#")) {
|
||||||
|
when{
|
||||||
|
message.message == "#nudge" -> {
|
||||||
|
event.from.nudge().sendTo(event.subject)
|
||||||
|
}
|
||||||
|
message.message.matches(Regex("#group\\.mute(\\\\)?:\\d+")) -> {
|
||||||
|
val (_, duration) = message.message.split(":")
|
||||||
|
val member: Member = event.from as Member
|
||||||
|
try {
|
||||||
|
member.mute(duration.toInt())
|
||||||
|
}catch (e: PermissionDeniedException){
|
||||||
|
logger.warning("权限不足,无法进行禁言")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
event.subject.sendMessage(message.message.deserializeMiraiCode())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event.subject.sendMessage(message.message.deserializeMiraiCode())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user