Skip to content

Commit d2fbdc7

Browse files
committed
fix: blacklisted users can use commands in normal groups
Closes #59
1 parent 92474c0 commit d2fbdc7

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "com.github.samarium150"
14-
version = "4.1.3"
14+
version = "4.1.4"
1515

1616
repositories {
1717
mavenLocal()

src/main/kotlin/Lolicon.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.coroutines.*
2020
import kotlinx.serialization.decodeFromString
2121
import kotlinx.serialization.json.Json
2222
import net.mamoe.mirai.console.command.CommandSender
23+
import net.mamoe.mirai.console.command.CommandSenderOnMessage
2324
import net.mamoe.mirai.console.command.CompositeCommand
2425
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
2526
import net.mamoe.mirai.console.plugin.jvm.reloadPluginConfig
@@ -86,8 +87,8 @@ object Lolicon: CompositeCommand(
8687
@OptIn(DelicateCoroutinesApi::class)
8788
@SubCommand("get", "来一张")
8889
@Description("根据标签发送涩图, 不提供则随机发送一张")
89-
suspend fun CommandSender.get(tags: String = "") {
90-
if (!Utils.isPermitted(subject)) {
90+
suspend fun CommandSenderOnMessage<*>.get(tags: String = "") {
91+
if (!Utils.isPermitted(subject, user)) {
9192
val where = if (subject is Group) "@${(subject as Group).id}" else ""
9293
Main.logger.info("当前模式为'${PluginConfig.mode}',${user?.id}${where}的命令已被无视")
9394
return
@@ -191,7 +192,7 @@ object Lolicon: CompositeCommand(
191192
@SubCommand("adv", "高级")
192193
@Description("根据JSON字符串发送涩图")
193194
suspend fun CommandSender.advanced(json: String) {
194-
if (!Utils.isPermitted(subject)) {
195+
if (!Utils.isPermitted(subject, user)) {
195196
val where = if (subject is Group) "@${(subject as Group).id}" else ""
196197
Main.logger.info("当前模式为'${PluginConfig.mode}',${user?.id}${where}的命令已被无视")
197198
return

src/main/kotlin/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import java.net.Proxy
4141
object Main: KotlinPlugin(
4242
JvmPluginDescription(
4343
id = "com.github.samarium150.mirai-console-lolicon",
44-
version = "4.1.3",
44+
version = "4.1.4",
4545
name = "mirai-console-lolicon"
4646
)
4747
) {

src/main/kotlin/PluginConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
9292
* 自定义代理
9393
*/
9494
@ValueDescription("获取Pixiv图片的代理")
95-
val proxy: String by value("i.pixiv.cat")
95+
val proxy: String by value("i.pixiv.re")
9696

9797
/**
9898
* Default recall time

src/main/kotlin/Utils.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,31 @@ object Utils {
135135
}
136136

137137
/**
138-
* Is the subject permitted to use the bot
138+
* Is the subject/user permitted to use the bot
139139
* <br>
140140
* 是否能执行命令
141141
*
142142
* @param subject
143+
* @param user
143144
* @return
144145
*/
145-
fun isPermitted(subject: Contact?): Boolean {
146+
fun isPermitted(subject: Contact?, user: User?): Boolean {
146147
return when (PluginConfig.mode) {
147148
"whitelist" -> {
148149
when {
149150
subject == null -> true
150151
subject is User && PluginData.userSet.contains(subject.id) -> true
151-
subject is Group && PluginData.groupSet.contains(subject.id) -> true
152+
subject is Group &&
153+
PluginData.groupSet.contains(subject.id) && PluginData.userSet.contains(user?.id) -> true
152154
else -> false
153155
}
154156
}
155157
"blacklist" -> {
156158
when {
157159
subject == null -> true
158160
subject is User && !PluginData.userSet.contains(subject.id) -> true
159-
subject is Group && !PluginData.groupSet.contains(subject.id) -> true
161+
subject is Group &&
162+
!PluginData.groupSet.contains(subject.id) && !PluginData.userSet.contains(user?.id) -> true
160163
else -> false
161164
}
162165
}

0 commit comments

Comments
 (0)