-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/PokeMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.mamoe.mirai.api.http.util | ||
|
||
import net.mamoe.mirai.message.data.PokeMessage | ||
import net.mamoe.mirai.message.data.PokeMessage.Types.Poke | ||
import kotlin.reflect.full.memberProperties | ||
|
||
class PokeMap { | ||
|
||
companion object { | ||
private val type2name = mutableMapOf<Int, String>() | ||
private val name2Poke = mutableMapOf<String, PokeMessage>() | ||
|
||
init { | ||
PokeMessage.Types::class.memberProperties.forEach { | ||
val n = it.name | ||
val p = it.get(PokeMessage.Types) as PokeMessage | ||
type2name[p.type] = n | ||
name2Poke[n] = p | ||
} | ||
} | ||
|
||
operator fun get(type: Int) = type2name[type] ?: "未知戳一戳" | ||
operator fun get(name: String) = name2Poke[name] ?: Poke | ||
} | ||
} |