From 18adb49cdd406e513610adef44fb814edac26973 Mon Sep 17 00:00:00 2001 From: YehowahLiu Date: Fri, 15 Apr 2022 16:34:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=8A=A8=E4=BD=9C=20=E5=8C=85=E6=8B=AC?= =?UTF-8?q?=E5=9B=9E=E6=88=B3=20/=20=E7=A6=81=E8=A8=80=E7=94=A8=E6=88=B7?= =?UTF-8?q?=20=E5=9C=A8=E6=8A=BD=E5=8F=96=E5=9B=9E=E5=A4=8D=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E6=97=B6=E4=BC=9A=E6=8C=89=E9=9C=80=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E6=8E=89=E4=BB=85=E7=BE=A4=E7=BB=84=E5=8F=AF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/top/jie65535/jnr/JNudgeReply.kt | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/top/jie65535/jnr/JNudgeReply.kt b/src/main/kotlin/top/jie65535/jnr/JNudgeReply.kt index c7de7fc..24e63a5 100644 --- a/src/main/kotlin/top/jie65535/jnr/JNudgeReply.kt +++ b/src/main/kotlin/top/jie65535/jnr/JNudgeReply.kt @@ -1,8 +1,13 @@ package top.jie65535.jnr 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.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.events.NudgeEvent import net.mamoe.mirai.event.globalEventChannel @@ -26,11 +31,17 @@ object JNudgeReply : KotlinPlugin( Random.nextInt() globalEventChannel().subscribeAlways(priority = JNRPluginConfig.priority) { 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) - for (msg in JNRPluginConfig.replyMessageList) { + for (msg in replyList) { if (w < msg.weight) { - subject.sendMessage(msg.message.deserializeMiraiCode()) + doReply(msg, this) break } else { w -= msg.weight @@ -43,4 +54,30 @@ object JNudgeReply : KotlinPlugin( 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()) + } + } }