Skip to content

Commit

Permalink
feat: 添加忽略私聊的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
diyigemt committed Mar 10, 2023
1 parent 1af2b83 commit a49c6e8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ tools/pixiv.db
tools/pixiv.py
tools/pixiv.db-journal
tools/skip
/arona-doc/*
/arona-webui-frontend/*
/arona-webui-backend/*
2 changes: 1 addition & 1 deletion arona-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "net.diyigemt.arona"
version = "1.0.14"
version = "1.0.14+20230310"
val miraiVersion = "2.11.1"
val exposedVersion = "0.38.2"
val sqliteVersion = "3.36.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,8 @@ object AronaUpdateChecker: AronaQuartzService {
}.joinToString("\n")
val concat = "检测到版本更新,当前版本:${Arona.version}, 新版本:${nowVersion}\n更新日志:\n${newFuture}"
// 如果本机使用测试版
if (Arona.version.identifier != null) {
if (nowVersion > Arona.version) {
// 新的版本发布就提醒更新
if (Arona.version.major == nowVersion.major
&& Arona.version.minor == nowVersion.minor
&& Arona.version.patch == nowVersion.patch
&& Arona.version.identifier != nowVersion.identifier
) {
Arona.sendMessageToAdmin(concat)
}
} else {
if (nowVersion.identifier != null || Arona.version >= nowVersion) return // 忽略测试版和低版本
Arona.sendMessageToAdmin(concat)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.diyigemt.arona.config

import net.diyigemt.arona.extension.TempMessageIgnoreType
import net.mamoe.mirai.console.data.AutoSavePluginConfig
import net.mamoe.mirai.console.data.ValueDescription
import net.mamoe.mirai.console.data.value
Expand Down Expand Up @@ -45,4 +46,7 @@ object AronaConfig: AutoSavePluginConfig("arona") {
@ValueDescription("远端操作查询间隔 设置为0表示不开启, 单位是小时")
val remoteCheckInterval: Int by value(1)

@ValueDescription("是否忽略私聊指令, NONE: \"不忽略\";ONLY_SERVICE_GROUP: \"忽略不在groups群里的群友\";ALL: \"忽略所有\"")
val tempMessageIgnoreType: TempMessageIgnoreType by value(TempMessageIgnoreType.NONE)

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ object CommandInterceptorManager: InitializedFunction() {

override fun init() {
ExitCommandInterceptor.registerInterceptor()
TempMessageInterceptor.registerInterceptor()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.diyigemt.arona.extension

import net.diyigemt.arona.Arona
import net.diyigemt.arona.config.AronaConfig
import net.diyigemt.arona.service.AronaService
import net.diyigemt.arona.service.AronaServiceManager
Expand Down Expand Up @@ -48,10 +47,15 @@ private object CommandResolverInterceptor: CommandCallInterceptor {
super.interceptBeforeCall(message, caller)
}
}

private fun extraCommandName(message: Message): String {
val contentToString = message.contentToString().split(" ")
return contentToString[0]
}
}

fun extraCommandName(message: Message): String {
val contentToString = message.contentToString().split(" ")
return contentToString[0]
}

enum class TempMessageIgnoreType {
NONE,
ONLY_SERVICE_GROUP,
ALL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.diyigemt.arona.extension

import net.diyigemt.arona.config.AronaConfig
import net.diyigemt.arona.service.AronaGroupService
import net.mamoe.mirai.console.command.CommandManager
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.UserCommandSender
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.message.data.Message

@OptIn(ExperimentalCommandDescriptors::class, ConsoleExperimentalApi::class)
object TempMessageInterceptor: CommandInterceptor {
override val level: Int = 1

override fun interceptBeforeCall(message: Message, caller: CommandSender): String? {
val unreliableCommandName = extraCommandName(message)
val matchCommand = CommandManager.matchCommand(unreliableCommandName)
if (matchCommand !is AronaGroupService && caller is UserCommandSender) {
val callerId = caller.user.id
if (AronaConfig.managerGroup.contains(callerId)) {
return null
}
return when(AronaConfig.tempMessageIgnoreType) {
TempMessageIgnoreType.NONE -> {
null
}
TempMessageIgnoreType.ONLY_SERVICE_GROUP -> {
if (caller.bot.groups.any { group -> group.contains(callerId) }) {
return null
}
"忽略非服务群友私聊"
}
TempMessageIgnoreType.ALL -> {
"忽略所有群聊"
}
}
}
return null
}
}
2 changes: 1 addition & 1 deletion arona-core/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id: "net.diyigemt.arona"
version: "1.0.14"
version: "1.0.14+20230310"
name: "ba-activity-pusher"
author: "diyigemt"
info: "BA日服/国际服活动推送插件"
5 changes: 5 additions & 0 deletions doc/using.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ arona总的配置。
| sendStatus | Boolean | 是否允许arona收集匿名统计信息(未实装) |
| uuid | String | 识别id(无需修改) |
| remoteCheckInterval | Int | 远端操作查询间隔 设置为0表示不开启, 单位是小时 |
| tempMessageIgnoreType | Enum | 是否忽略私聊指令, NONE: \"不忽略\";ONLY_SERVICE_GROUP: \"忽略不在groups群里的群友\";ALL: \"忽略所有\" |

当`tempMessageIgnoreType`值为`NONE`时,该配置不生效, 为`ONLY_SERVICE_GROUP`时会忽略非服务群以外的私聊消息, 为`ALL`时将不会响应私聊消息<a id="ignore-message-type"> </a>

该配置不影响`managerGroup`的私聊消息

### 2.arona-service.yml<a id="service-names"> </a>

Expand Down

0 comments on commit a49c6e8

Please sign in to comment.