14 Commits

Author SHA1 Message Date
630b163f2f 更新文档,增加指令列表 2022-04-17 09:28:41 +08:00
3c4e73efbd 更新版本至v1.1.0 2022-04-17 09:24:39 +08:00
2664f07cc1 优化代码,减少转换,取消正则 2022-04-17 09:24:11 +08:00
3a445f0e79 Merge pull request #6 from YehowahLiu/feat_actions
新增特殊动作响应
 - 戳回去
 - 禁言
2022-04-17 09:16:31 +08:00
YehowahLiu
e6882a1c7a fix: 修复禁言动作的正则检查 2022-04-17 03:12:42 +08:00
YehowahLiu
b3ad996e68 refactor: 使用正则提取时间 2022-04-17 02:53:48 +08:00
YehowahLiu
a531cab16c doc: 更新特殊动作的文档 2022-04-17 02:22:33 +08:00
YehowahLiu
b20a92cc9c fix: 权限判断
在发送人权限不低于bot时, 过滤掉禁言等特权动作
2022-04-15 17:12:49 +08:00
YehowahLiu
6094637f03 fix: 避免响应bot帐号的戳一戳 2022-04-15 16:44:20 +08:00
YehowahLiu
18adb49cdd feat: 添加特殊响应动作
包括回戳 / 禁言用户
在抽取回复方式时会按需过滤掉仅群组可用的动作
2022-04-15 16:35:18 +08:00
YehowahLiu
551a792c04 test: 添加调试启动类 2022-04-15 16:32:17 +08:00
04fedc9db1 Update README.md 2022-03-22 09:03:38 +08:00
8231312bc8 Add files via upload 2022-03-22 09:02:57 +08:00
be51440f4e Delete example.jpg 2022-03-22 09:00:55 +08:00
7 changed files with 84 additions and 7 deletions

View File

@@ -1,4 +1,24 @@
# mirai-console-jnr-plugin
MiraiConsolePlugin 自定义戳一戳回复消息
![Use example image](doc/example.jpg)
## 指令列表
```bash
/jnr add [weight] # 添加回复消息权重默认为1
/jnr add <message> [weight] # 添加简单回复消息权重默认为1
/jnr clear # 清空回复消息列表
/jnr list # 列出当前回复消息列表
/jnr remove <index> # 删除指定索引的回复消息
```
## 特殊消息
设置回复消息为以下内容,代表特殊含义
- `#nudge` 戳回去
- `#group.mute:30` 禁言30s, 可以自定义禁言时间, 单位秒
## 用例
![Use example image](doc/example.png)

View File

@@ -7,7 +7,7 @@ plugins {
}
group = "top.jie65535"
version = "1.0.0"
version = "1.1.0"
repositories {
mavenLocal()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

BIN
doc/example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View File

@@ -3,6 +3,8 @@ package top.jie65535.jnr
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.event.EventPriority
import net.mamoe.mirai.event.events.NudgeEvent
import net.mamoe.mirai.event.globalEventChannel
@@ -14,7 +16,7 @@ object JNudgeReply : KotlinPlugin(
JvmPluginDescription(
id = "me.jie65535.mirai-console-jnr-plugin",
name = "J Nudge Reply",
version = "1.0.0",
version = "1.1.0",
) {
author("jie65535")
info("""自定义戳一戳回复插件""")
@@ -25,12 +27,20 @@ object JNudgeReply : KotlinPlugin(
JNRCommand.register()
Random.nextInt()
globalEventChannel().subscribeAlways<NudgeEvent>(priority = JNRPluginConfig.priority) {
if (target.id == bot.id && JNRPluginConfig.replyMessageList.isNotEmpty()) {
val totalWeight = JNRPluginConfig.replyMessageList.sumOf { it.weight }
if (target.id == bot.id && target.id != from.id && JNRPluginConfig.replyMessageList.isNotEmpty()) {
var replyList: List<ReplyMessage> = JNRPluginConfig.replyMessageList
if(subject !is Group){
replyList = replyList.filter { !it.message.startsWith("#group") }
}else{
if((from as Member).permission.level >= (subject as Group).botPermission.level){
replyList = replyList.filter { !it.message.startsWith("#group.mute:") }
}
}
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 +53,32 @@ object JNudgeReply : KotlinPlugin(
logger.info { "Plugin loaded" }
}
private suspend fun doReply(message: ReplyMessage, event: NudgeEvent) {
if (message.message.startsWith("#")) {
when {
message.message == "#nudge" -> {
event.from.nudge().sendTo(event.subject)
}
message.message.startsWith("#group.mute:") -> {
val duration = message.message.substringAfter(':').toIntOrNull()
if (duration == null) {
logger.warning("戳一戳禁言失败:\"${message.message}\" 格式不正确")
} else {
val member: Member = event.from as Member
try {
member.mute(duration)
} catch (e: Throwable) {
logger.warning("戳一戳禁言失败", e)
}
}
}
else -> {
event.subject.sendMessage(message.message.deserializeMiraiCode())
}
}
} else {
event.subject.sendMessage(message.message.deserializeMiraiCode())
}
}
}

View File

@@ -0,0 +1,5 @@
fun main(){
val regex = Regex("(?<=#group\\.mute(\\\\)?:)\\d+")
println(regex.find("#group.mute:abc")?.value?.toLong())
println(regex.find("#group.mute:12345")?.value?.toLong())
}

View File

@@ -0,0 +1,14 @@
import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.enable
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.load
import net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import top.jie65535.jnr.JNudgeReply
@OptIn(ConsoleExperimentalApi::class)
suspend fun main(){
MiraiConsoleTerminalLoader.startAsDaemon()
JNudgeReply.load()
JNudgeReply.enable()
MiraiConsole.job.join()
}