Skip to content

Commit

Permalink
fix: DebugRequestEventData
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Oct 10, 2021
1 parent 9d0e0c8 commit 24afdb1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 8 additions & 1 deletion build.gradle.kts
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "io.github.gnuf0rce"
version = "1.0.9"
version = "1.1.0"

mavenCentralPublish {
useCentralS01()
Expand All @@ -28,6 +28,7 @@ repositories {

dependencies {
compileOnly("net.mamoe:mirai-core-jvm:2.7.1")
testImplementation(kotlin("test-junit5"))
}

kotlin {
Expand All @@ -39,3 +40,9 @@ kotlin {
}
}
}

tasks {
test {
useJUnitPlatform()
}
}
Expand Up @@ -8,7 +8,7 @@ import net.mamoe.mirai.console.util.*
import net.mamoe.mirai.event.*

object DebugHelperPlugin : KotlinPlugin(
JvmPluginDescription(id = "xyz.cssxsh.mirai.plugin.debug-helper", version = "1.0.9") {
JvmPluginDescription(id = "xyz.cssxsh.mirai.plugin.debug-helper", version = "1.1.0") {
name("debug-helper")
author("cssxsh")
}
Expand Down
Expand Up @@ -9,10 +9,17 @@ import net.mamoe.mirai.event.events.*

object DebugRequestEventData : AutoSavePluginData("DebugRequestEventData") {

private val requests by value<MutableMap<Long, List<RequestEventData>>>().mapKeys(Bot::getInstance, Bot::id)
private val friends by value<MutableMap<Long, List<RequestEventData.NewFriendRequest>>>()
.mapKeys(Bot::getInstance, Bot::id)

private val groups by value<MutableMap<Long, List<RequestEventData.BotInvitedJoinGroupRequest>>>()
.mapKeys(Bot::getInstance, Bot::id)

private val members by value<MutableMap<Long, List<RequestEventData.MemberJoinRequest>>>()
.mapKeys(Bot::getInstance, Bot::id)

fun detail(): String = buildString {
for ((bot, list) in requests) {
for ((bot, list) in friends + groups + members) {
if (list.isEmpty()) continue
appendLine("--- ${bot.nick} ${bot.id} ---")
for (request in list) {
Expand Down Expand Up @@ -44,7 +51,7 @@ object DebugRequestEventData : AutoSavePluginData("DebugRequestEventData") {
}

suspend fun handle(id: Long, accept: Boolean, black: Boolean, message: String): RequestEventData? {
for ((bot, list) in requests) {
for ((bot, list) in friends + groups + members) {
val request = list[id] ?: continue
if (accept) {
request.accept(bot)
Expand All @@ -66,19 +73,19 @@ object DebugRequestEventData : AutoSavePluginData("DebugRequestEventData") {
}

operator fun plusAssign(event: NewFriendRequestEvent) {
requests.compute(event.bot) { _, list ->
friends.compute(event.bot) { _, list ->
list.orEmpty() + event.toRequestEventData()
}
}

operator fun plusAssign(event: BotInvitedJoinGroupRequestEvent) {
requests.compute(event.bot) { _, list ->
groups.compute(event.bot) { _, list ->
list.orEmpty() + event.toRequestEventData()
}
}

operator fun plusAssign(event: MemberJoinRequestEvent) {
requests.compute(event.bot) { _, list ->
members.compute(event.bot) { _, list ->
list.orEmpty() + event.toRequestEventData()
}
}
Expand Down

0 comments on commit 24afdb1

Please sign in to comment.