Skip to content

Commit f9fa0f9

Browse files
authored
Merge pull request #13 from EnkanSakura/main
1.启用/停用随机操作指令; 2.指令消息回复(QuoteReply)使用者
2 parents 1d5ef38 + 1f3a686 commit f9fa0f9

File tree

7 files changed

+96
-13
lines changed

7 files changed

+96
-13
lines changed

build.gradle.kts

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

88
group = "org.stg.verification.bot"
9-
version = "1.2.4"
9+
version = "1.2.5"
1010

1111
repositories {
1212
maven("https://maven.aliyun.com/repository/public")

src/main/kotlin/CommandHandler.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ interface CommandHandler {
9191
/**
9292
* 指令处理器列表
9393
*/
94-
val handlers = arrayOf(
94+
val allCmd = arrayOf(
9595
ShowTips,
9696
AddAdmin, RemoveAdmin, ListAllAdmin,
9797
RandOperation, DeleteRecord, ClearRecord, ModifyTag,
98-
GetRecord, GetAllRecord
98+
GetRecord, GetAllRecord,
99+
EnableGroup, DisableGroup
100+
)
101+
private val groupCmd = arrayOf(
102+
EnableGroup, DisableGroup
99103
)
100104

101105
/**
@@ -104,7 +108,11 @@ interface CommandHandler {
104108
*/
105109
suspend fun handle(event: GroupMessageEvent) {
106110
// 排除非工作QQ群
107-
if (event.group.id !in TRVGConfig.qq.qqGroup) return
111+
val handlers =
112+
if (event.group.id !in TRVGConfig.qq.qqGroup)
113+
if (TRVGConfig.isSuperAdmin(event.sender.id)) groupCmd
114+
else return
115+
else allCmd
108116
// 从群消息事件中获取消息链并忽略空消息
109117
val message = event.message
110118
if (message.size <= 1) return
@@ -141,7 +149,7 @@ interface CommandHandler {
141149
}
142150
// 执行指令
143151
val groupMsg = it.execute(event, content)
144-
event.group.sendMessage(groupMsg)
152+
event.group.sendMessage(QuoteReply(event.source) + groupMsg)
145153
}
146154
}
147155
}

src/main/kotlin/PluginMain.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal object PluginMain : KotlinPlugin(
1717
JvmPluginDescription(
1818
id = "org.stg.verification.bot",
1919
name = "Touhou Replay Verification Code Generator Bot",
20-
version = "1.2.4"
20+
version = "1.2.5"
2121
)
2222
) {
2323
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.stg.verification.bot.command
2+
3+
import net.mamoe.mirai.event.events.GroupMessageEvent
4+
import net.mamoe.mirai.message.data.Message
5+
import net.mamoe.mirai.message.data.PlainText
6+
import org.stg.verification.bot.CommandHandler
7+
import org.stg.verification.bot.storage.TRVGConfig
8+
9+
object DisableGroup : CommandHandler {
10+
override val name: String = "停用随机操作"
11+
12+
override val permLevel: CommandHandler.PermLevel = CommandHandler.PermLevel.SUPER_ADMIN
13+
14+
override val cooldown: MutableMap<Long, Long> = mutableMapOf()
15+
16+
override fun showTips(groupCode: Long, senderId: Long) = "$name"
17+
18+
override fun showInstruction(groupCode: Long, senderId: Long) = "$name"
19+
20+
override suspend fun execute(event: GroupMessageEvent, content: String): Message {
21+
val groupId = event.group.id
22+
val (succeed, failed) = listOf(groupId).partition { TRVGConfig.isGroupEnabled(it) && TRVGConfig.disableGroup(it) }
23+
val result =
24+
if (succeed.isNotEmpty()) "OK"
25+
else failed.joinToString(postfix = "不是工作群")
26+
return PlainText(result)
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.stg.verification.bot.command
2+
3+
import net.mamoe.mirai.event.events.GroupMessageEvent
4+
import net.mamoe.mirai.message.data.Message
5+
import net.mamoe.mirai.message.data.PlainText
6+
import org.stg.verification.bot.CommandHandler
7+
import org.stg.verification.bot.storage.TRVGConfig
8+
9+
object EnableGroup : CommandHandler {
10+
override val name: String = "启用随机操作"
11+
12+
override val permLevel: CommandHandler.PermLevel = CommandHandler.PermLevel.SUPER_ADMIN
13+
14+
override val cooldown: MutableMap<Long, Long> = mutableMapOf()
15+
16+
override fun showTips(groupCode: Long, senderId: Long) = "$name"
17+
18+
override fun showInstruction(groupCode: Long, senderId: Long) = "$name"
19+
20+
override suspend fun execute(event: GroupMessageEvent, content: String): Message {
21+
val groupId = event.group.id
22+
val (succeed, failed) = listOf(groupId).partition { !TRVGConfig.isGroupEnabled(it) && TRVGConfig.enableGroup(it) }
23+
val result =
24+
if (succeed.isNotEmpty()) "OK"
25+
else failed.joinToString(postfix = "是工作群")
26+
return PlainText(result)
27+
}
28+
}

src/main/kotlin/command/ShowTips.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import net.mamoe.mirai.event.events.GroupMessageEvent
44
import net.mamoe.mirai.message.data.Message
55
import net.mamoe.mirai.message.data.PlainText
66
import org.stg.verification.bot.CommandHandler
7-
import org.stg.verification.bot.CommandHandler.Companion.handlers
7+
import org.stg.verification.bot.CommandHandler.Companion.allCmd
88

99
object ShowTips : CommandHandler {
1010
override val name = "指令说明"
@@ -19,12 +19,12 @@ object ShowTips : CommandHandler {
1919

2020
override suspend fun execute(event: GroupMessageEvent, content: String): Message {
2121
if (content.isEmpty()) {
22-
val tips = handlers.filter { it.checkAuth(event.sender.id) }
22+
val tips = allCmd.filter { it.checkAuth(event.sender.id) }
2323
.mapNotNull { it.showTips(event.group.id, event.sender.id) }
2424
val result = tips.joinToString(separator = "\n", prefix = "你可以使用以下功能:\n")
2525
return PlainText(result)
2626
} else {
27-
for (handler in handlers) {
27+
for (handler in allCmd) {
2828
if (content == handler.name) {
2929
return PlainText(handler.showInstruction(event.group.id, event.sender.id)?:"")
3030
}

src/main/kotlin/storage/TRVGConfig.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,39 @@ object TRVGConfig : AutoSavePluginConfig("TRVGConfig") {
1414

1515
@SerialName("qq_group")
1616
/** 主要功能的QQ群 */
17-
val qqGroup: LongArray,
17+
var qqGroup: MutableList<Long>,
1818
)
1919

2020
@ValueDescription("QQ相关配置")
2121
val qq: QQConfig by value(
2222
QQConfig(
23-
superAdminQQ = 12345678,
24-
qqGroup = longArrayOf(12345678)
23+
superAdminQQ = 12345678L,
24+
qqGroup = mutableListOf(12345678L)
2525
)
2626
)
2727

28-
fun isSuperAdmin(qq: Long) =
28+
fun isSuperAdmin(qq: Long): Boolean =
2929
qq == this.qq.superAdminQQ
3030

31+
fun enableGroup(groupId: Long): Boolean {
32+
synchronized(TRVGConfig) {
33+
if (groupId in qq.qqGroup) return false
34+
qq.qqGroup += groupId
35+
return true
36+
}
37+
}
38+
39+
fun disableGroup(groupId: Long): Boolean {
40+
synchronized(TRVGConfig) {
41+
if (groupId !in qq.qqGroup) return false
42+
qq.qqGroup -= groupId
43+
return true
44+
}
45+
}
46+
47+
fun isGroupEnabled(groupId: Long): Boolean =
48+
groupId in qq.qqGroup
49+
3150
@Serializable
3251
class RandOperationConfig(
3352
/** 一个验证码包含的随机操作的次数 */

0 commit comments

Comments
 (0)