mirror of
https://github.com/jie65535/mirai-console-jnr-plugin.git
synced 2025-12-15 18:41:35 +08:00
Compare commits
14 Commits
v1.0.0-alp
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 630b163f2f | |||
| 3c4e73efbd | |||
| 2664f07cc1 | |||
| 3a445f0e79 | |||
|
|
e6882a1c7a | ||
|
|
b3ad996e68 | ||
|
|
a531cab16c | ||
|
|
b20a92cc9c | ||
|
|
6094637f03 | ||
|
|
18adb49cdd | ||
|
|
551a792c04 | ||
| 04fedc9db1 | |||
| 8231312bc8 | |||
| be51440f4e |
22
README.md
22
README.md
@@ -1,4 +1,24 @@
|
||||
# mirai-console-jnr-plugin
|
||||
|
||||
MiraiConsolePlugin 自定义戳一戳回复消息
|
||||
|
||||

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

|
||||
|
||||
@@ -7,7 +7,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "top.jie65535"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
||||
BIN
doc/example.jpg
BIN
doc/example.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 198 KiB |
BIN
doc/example.png
Normal file
BIN
doc/example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
src/test/kotlin/RegexTest.kt
Normal file
5
src/test/kotlin/RegexTest.kt
Normal 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())
|
||||
}
|
||||
14
src/test/kotlin/RunMirai.kt
Normal file
14
src/test/kotlin/RunMirai.kt
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user