Skip to content

Commit 91b3e0d

Browse files
authored
feat!: merge #18
feat!: restrict set command permission
2 parents c373e30 + b0543c5 commit 91b3e0d

File tree

12 files changed

+29
-42
lines changed

12 files changed

+29
-42
lines changed

.editorconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
root = true
2+
3+
[*]
4+
insert_final_newline = true
5+
16
[*.{kt, kts}]
27
max_line_length = 120
38
tab_width = 4
49
ij_continuation_indent_size = 4
5-
indent_size = 4
10+
indent_size = 4

build.gradle.kts

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

99
group = "com.github.samarium150"
10-
version = "1.5.2"
10+
version = "1.6"
1111

1212
repositories {
1313
mavenLocal()

src/main/kotlin/APIError.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package com.github.samarium150.mirai.plugin
2626
class APIError internal constructor(
2727
private val code: Int,
2828
override val message: String
29-
): Exception(message) {
29+
) : Exception(message) {
3030

3131
/**
3232
* Override toString() for logging
@@ -51,4 +51,4 @@ class APIError internal constructor(
5151
else -> throw Exception(this.toString())
5252
}
5353
}
54-
}
54+
}

src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ object Config: AutoSavePluginConfig("Config") {
4242
*/
4343
@ValueDescription("默认的冷却时间(单位: s)")
4444
var cooldown: Int by value(60)
45-
}
45+
}

src/main/kotlin/ImageData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ data class ImageData (
7373
"链接: $url"
7474
)
7575
}
76-
}
76+
}

src/main/kotlin/Lolicon.kt

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ package com.github.samarium150.mirai.plugin
1919
import com.github.kittinunf.fuel.core.FuelError
2020
import kotlinx.coroutines.*
2121
import kotlinx.io.errors.IOException
22-
import net.mamoe.mirai.Mirai
2322
import net.mamoe.mirai.console.command.CommandSender
2423
import net.mamoe.mirai.console.command.CompositeCommand
25-
import net.mamoe.mirai.contact.Contact
24+
import net.mamoe.mirai.contact.*
2625
import net.mamoe.mirai.contact.Contact.Companion.sendImage
27-
import net.mamoe.mirai.contact.Group
28-
import net.mamoe.mirai.contact.User
29-
import net.mamoe.mirai.message.MessageReceipt
3026
import java.net.URL
3127

3228
/**
@@ -52,24 +48,6 @@ object Lolicon: CompositeCommand(
5248
} else throw Exception("$helpFileName does not found")
5349
}
5450

55-
/**
56-
* Asynchronously recall the image sent by the bot
57-
*
58-
* @param receipt [MessageReceipt]<[Contact]> Receipt of sending the image
59-
* @return [Deferred]<[Boolean]> The result of the recall
60-
*/
61-
private suspend fun recallAsync(receipt: MessageReceipt<Contact>) = GlobalScope.async(
62-
start = CoroutineStart.LAZY
63-
) {
64-
delay(30000L)
65-
try {
66-
Mirai.recallMessage(receipt.target.bot, receipt.source)
67-
} catch (e: Exception) {
68-
return@async false
69-
}
70-
return@async true
71-
}
72-
7351
/**
7452
* Load necessary information
7553
*
@@ -124,12 +102,12 @@ object Lolicon: CompositeCommand(
124102
val receipt = subject?.sendImage(stream)
125103
sendMessage(imageData.toReadable())
126104
if (receipt != null) {
127-
Timer.setCooldown(subject)
105+
Timer.setCooldown(subject)
128106
GlobalScope.launch {
129-
val result = recallAsync(receipt).await()
107+
val result = receipt.recallIn(30000L).awaitIsSuccess()
130108
withContext(Dispatchers.Default) {
131-
if (!result) Main.logger.warning(receipt.target.toString()+"撤回失败")
132-
else Main.logger.info(receipt.target.toString()+"图片已撤回")
109+
if (!result) Main.logger.warning(receipt.target.toString() + "撤回失败")
110+
else Main.logger.info(receipt.target.toString() + "图片已撤回")
133111
}
134112
}
135113
GlobalScope.launch {
@@ -163,7 +141,11 @@ object Lolicon: CompositeCommand(
163141
@SubCommand("set")
164142
@Description("设置属性, 详见帮助信息")
165143
suspend fun CommandSender.set(property: String, value: String) {
166-
when(property) {
144+
if (subject is Group && (user as Member).permission == MemberPermission.MEMBER) {
145+
sendMessage("set仅限群主和管理员操作")
146+
return
147+
}
148+
when (property) {
167149
"r18" -> {
168150
if (subject is Group) {
169151
val setting: Int
@@ -228,4 +210,4 @@ object Lolicon: CompositeCommand(
228210
suspend fun CommandSender.help() {
229211
sendMessage(help)
230212
}
231-
}
213+
}

src/main/kotlin/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import net.mamoe.mirai.utils.info
4444
object Main: KotlinPlugin(
4545
JvmPluginDescription(
4646
id = "com.github.samarium150.mirai-console-lolicon",
47-
version = "1.5.2",
47+
version = "1.6",
4848
name = "mirai-console-lolicon"
4949
)
5050
) {
@@ -118,4 +118,4 @@ object Main: KotlinPlugin(
118118
Lolicon.unregister()
119119
logger.info { "Plugin mirai-console-lolicon unloaded" }
120120
}
121-
}
121+
}

src/main/kotlin/PluginData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ object PluginData: AutoSavePluginData("Data") {
5454
*/
5555
@ValueDescription("自定义了冷却时间的群和对应的值")
5656
var customCooldownGroups: MutableMap<Long, Int> by value()
57-
}
57+
}

src/main/kotlin/Request.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ data class Request(
6666
"num: $num"
6767
)
6868
}
69-
}
69+
}

src/main/kotlin/RequestHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ object RequestHandler {
6565
if (result is Result.Failure) throw result.getException()
6666
return ByteArrayInputStream(response.data)
6767
}
68-
}
68+
}

0 commit comments

Comments
 (0)