mirror of
https://github.com/jie65535/mirai-console-jnr-plugin.git
synced 2025-06-02 17:49:11 +08:00
特殊消息可以同时回复普通消息
This commit is contained in:
parent
393db710e8
commit
c608f517b6
19
README.md
19
README.md
@ -21,7 +21,7 @@ MiraiConsolePlugin 自定义戳一戳回复消息
|
|||||||
- `#group.mute:30` 禁言30s, 可以自定义禁言时间, 单位秒
|
- `#group.mute:30` 禁言30s, 可以自定义禁言时间, 单位秒
|
||||||
- `#ignore` 忽略
|
- `#ignore` 忽略
|
||||||
|
|
||||||
Tips:可以在#nudge之后直接添加消息以在回戳时同时回复消息
|
Tips:可以在特殊消息之后直接添加消息以在执行时同时回复消息
|
||||||
## 配置文件
|
## 配置文件
|
||||||
|
|
||||||
文件位置:`config/me.jie65535.mirai-console-jnr-plugin/jnr.yml`
|
文件位置:`config/me.jie65535.mirai-console-jnr-plugin/jnr.yml`
|
||||||
@ -38,23 +38,6 @@ priority: HIGH
|
|||||||
isIntercept: true
|
isIntercept: true
|
||||||
# 群回复间隔(秒),0表示无限制
|
# 群回复间隔(秒),0表示无限制
|
||||||
groupInterval: 0
|
groupInterval: 0
|
||||||
# 群共享冷却时间上界(分钟),0表示无限制
|
|
||||||
# 请不要和群回复间隔一起打开,避免出现问题
|
|
||||||
groupCoolDownTimeUpperBound: 0
|
|
||||||
# 群共享冷却时间下界(分钟)
|
|
||||||
# 以下界<=x<=上界为范围产生随机数随机休息时间
|
|
||||||
groupCoolDownTimeLowerBound: 0
|
|
||||||
# 冷却触发发送语句
|
|
||||||
# %s为占位符,可不加,用来在消息中显示冷却时长
|
|
||||||
replyMessageForRest: 呜呜,被戳傻了。休息%s分钟
|
|
||||||
# 群共享冷却默认触发最低次数
|
|
||||||
groupCoolDownTriggerCountMin: 6
|
|
||||||
# 群共享冷却默认触发最高次数,到此次数必定触发
|
|
||||||
groupCoolDownTriggerCountMax: 12
|
|
||||||
# 达到最低次数后的触发概率,1~100,按百分比触发
|
|
||||||
groupCoolDownTriggerProbability: 50
|
|
||||||
# 间隔多长时间重置计数(分钟),0表示不重置
|
|
||||||
groupCoolDownInterval: 10
|
|
||||||
# 用户私聊回复间隔(秒),0表示无限制
|
# 用户私聊回复间隔(秒),0表示无限制
|
||||||
userInterval: 0
|
userInterval: 0
|
||||||
```
|
```
|
||||||
|
@ -41,26 +41,6 @@ object JNRPluginConfig : AutoSavePluginConfig("jnr") {
|
|||||||
@ValueDescription("群回复间隔(秒),0表示无限制")
|
@ValueDescription("群回复间隔(秒),0表示无限制")
|
||||||
var groupInterval: Long by value(0L)
|
var groupInterval: Long by value(0L)
|
||||||
|
|
||||||
/**
|
|
||||||
* 群共享冷却时间
|
|
||||||
* 本设定优先级低于群间隔时间
|
|
||||||
* 如需使用请将群间隔时间设置为0
|
|
||||||
* 请不要一起打开
|
|
||||||
* */
|
|
||||||
@ValueDescription("群共享冷却时间上界(分钟),0表示无限制")
|
|
||||||
var groupCoolDownTimeUpperBound: Long by value(0L)
|
|
||||||
@ValueDescription("群共享冷却时间下界(分钟)")
|
|
||||||
var groupCoolDownTimeLowerBound: Long by value(0L)
|
|
||||||
@ValueDescription("冷却触发发送语句,%s为占位符,可不加,用来在消息中显示冷却时长")
|
|
||||||
var replyMessageForRest: String by value("呜呜,被戳傻了。休息%s分钟")
|
|
||||||
@ValueDescription("群共享冷却默认触发最低次数")
|
|
||||||
var groupCoolDownTriggerCountMin: Long by value(6L)
|
|
||||||
@ValueDescription("群共享冷却默认触发最高次数,到此次数必定触发")
|
|
||||||
var groupCoolDownTriggerCountMax: Long by value(12L)
|
|
||||||
@ValueDescription("达到最低次数后的触发概率,1~100,按百分比触发")
|
|
||||||
var groupCoolDownTriggerProbability: Int by value(50)
|
|
||||||
@ValueDescription("间隔多长时间重置计数(分钟),0表示不重置")
|
|
||||||
var groupCoolDownInterval: Long by value(10L)
|
|
||||||
/**
|
/**
|
||||||
* 用户间隔(单位秒)
|
* 用户间隔(单位秒)
|
||||||
* 0 表示无限制
|
* 0 表示无限制
|
||||||
|
@ -18,6 +18,8 @@ import net.mamoe.mirai.message.data.MessageChain
|
|||||||
import net.mamoe.mirai.utils.ExternalResource.Companion.uploadAsImage
|
import net.mamoe.mirai.utils.ExternalResource.Companion.uploadAsImage
|
||||||
import net.mamoe.mirai.utils.info
|
import net.mamoe.mirai.utils.info
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
import java.util.regex.Matcher
|
||||||
|
import java.util.regex.Pattern
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
object JNudgeReply : KotlinPlugin(
|
object JNudgeReply : KotlinPlugin(
|
||||||
@ -32,11 +34,6 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
) {
|
) {
|
||||||
private val groupLastReply = mutableMapOf<Long, LocalDateTime>()
|
private val groupLastReply = mutableMapOf<Long, LocalDateTime>()
|
||||||
private val userLastReply = mutableMapOf<Long, LocalDateTime>()
|
private val userLastReply = mutableMapOf<Long, LocalDateTime>()
|
||||||
private var groupJnrCount = mutableMapOf<Long, Long>()
|
|
||||||
private var coolDownTime = (JNRPluginConfig.groupCoolDownTimeLowerBound..JNRPluginConfig.groupCoolDownTimeUpperBound).random().toInt()
|
|
||||||
private var isReply = true
|
|
||||||
private val groupCoolDownTime = mutableMapOf<Long, LocalDateTime>()
|
|
||||||
private var groupCountingInterval = mutableMapOf<Long, LocalDateTime>()
|
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
JNRPluginConfig.reload()
|
JNRPluginConfig.reload()
|
||||||
@ -46,6 +43,7 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
if (target.id == bot.id && target.id != from.id && JNRPluginConfig.replyMessageList.isNotEmpty()) {
|
if (target.id == bot.id && target.id != from.id && JNRPluginConfig.replyMessageList.isNotEmpty()) {
|
||||||
var replyList: List<ReplyMessage> = JNRPluginConfig.replyMessageList
|
var replyList: List<ReplyMessage> = JNRPluginConfig.replyMessageList
|
||||||
val now = LocalDateTime.now()
|
val now = LocalDateTime.now()
|
||||||
|
var isReply = true
|
||||||
if (subject !is Group) {
|
if (subject !is Group) {
|
||||||
if (JNRPluginConfig.userInterval > 0) {
|
if (JNRPluginConfig.userInterval > 0) {
|
||||||
val t = userLastReply[subject.id]
|
val t = userLastReply[subject.id]
|
||||||
@ -64,31 +62,6 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
} else {
|
} else {
|
||||||
isReply = false
|
isReply = false
|
||||||
}
|
}
|
||||||
} else if (JNRPluginConfig.groupCoolDownTimeUpperBound > 0) {
|
|
||||||
val randomNumber = (1..100).random()
|
|
||||||
if (groupCoolDownTime[subject.id] == null) {
|
|
||||||
groupCoolDownTime[subject.id] = now
|
|
||||||
groupJnrCount[subject.id] = 1
|
|
||||||
groupCountingInterval[subject.id] = now
|
|
||||||
}
|
|
||||||
if (JNRPluginConfig.groupCoolDownInterval != 0L && groupCountingInterval[subject.id]?.plusMinutes(JNRPluginConfig.groupCoolDownInterval)!! <= now){
|
|
||||||
groupJnrCount[subject.id] = 1
|
|
||||||
groupCountingInterval[subject.id] = now
|
|
||||||
}
|
|
||||||
if (!isReply && (groupCoolDownTime[subject.id]?.plusMinutes(coolDownTime.toLong())!! > now)){
|
|
||||||
logger.info("cd中,跳过")
|
|
||||||
}else if ((randomNumber <= JNRPluginConfig.groupCoolDownTriggerProbability && groupJnrCount[subject.id]!! >= JNRPluginConfig.groupCoolDownTriggerCountMin) || (groupJnrCount[subject.id]!! >= JNRPluginConfig.groupCoolDownTriggerCountMax)){
|
|
||||||
groupCoolDownTime[subject.id] = now
|
|
||||||
isReply = false
|
|
||||||
groupJnrCount[subject.id] = 1
|
|
||||||
groupCountingInterval[subject.id] = now
|
|
||||||
val s = String.format(JNRPluginConfig.replyMessageForRest, coolDownTime.toString())
|
|
||||||
sendRecordMessage(this.subject,s.deserializeMiraiCode())
|
|
||||||
} else {
|
|
||||||
groupJnrCount[subject.id] = groupJnrCount[subject.id]!! + 1
|
|
||||||
coolDownTime = (JNRPluginConfig.groupCoolDownTimeLowerBound..JNRPluginConfig.groupCoolDownTimeUpperBound).random().toInt()
|
|
||||||
isReply = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ((from as Member).permission.level >= (subject as Group).botPermission.level) {
|
if ((from as Member).permission.level >= (subject as Group).botPermission.level) {
|
||||||
replyList = replyList.filter { !it.message.startsWith("#group.mute:") }
|
replyList = replyList.filter { !it.message.startsWith("#group.mute:") }
|
||||||
@ -140,14 +113,19 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 禁言
|
// 禁言
|
||||||
message.message.startsWith("#group.mute:") -> {
|
message.message.startsWith("#group.mute\\:") -> {
|
||||||
val duration = message.message.substringAfter(':').toIntOrNull()
|
val duration = RegexMatches.main(message.message)
|
||||||
if (duration == null) {
|
if (duration == 0) {
|
||||||
logger.warning("戳一戳禁言失败:\"${message.message}\" 格式不正确")
|
logger.warning("戳一戳禁言失败:\"${message.message}\" 格式不正确")
|
||||||
} else {
|
} else {
|
||||||
val member: Member = event.from as Member
|
val member: Member = event.from as Member
|
||||||
try {
|
try {
|
||||||
member.mute(duration)
|
member.mute(duration)
|
||||||
|
val s = duration.toString()
|
||||||
|
if (message.message.length > (13 + s.length)){
|
||||||
|
val messageTemp = String.format(message.message.substring(13 + s.length),s)
|
||||||
|
sendRecordMessage(event.subject, messageTemp.deserializeMiraiCode())
|
||||||
|
}
|
||||||
logger.info("戳一戳禁言目标 ${member.nameCardOrNick}(${member.id}) $duration 秒")
|
logger.info("戳一戳禁言目标 ${member.nameCardOrNick}(${member.id}) $duration 秒")
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logger.warning("戳一戳禁言失败", e)
|
logger.warning("戳一戳禁言失败", e)
|
||||||
@ -183,9 +161,24 @@ object JNudgeReply : KotlinPlugin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (it is Audio) {
|
} else if (it is Audio) {
|
||||||
// TODO
|
// val audioFile = resolveDataFile("audios/" + it.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subject.sendMessage(message)
|
subject.sendMessage(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object RegexMatches {
|
||||||
|
@JvmStatic
|
||||||
|
fun main(str: String): Int {
|
||||||
|
val pattern = "[0-9]+"
|
||||||
|
val r: Pattern = Pattern.compile(pattern)
|
||||||
|
val m: Matcher = r.matcher(str)
|
||||||
|
return if (m.find()){
|
||||||
|
m.group(0).toInt()
|
||||||
|
}else{
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user