mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-24 06:50:08 +08:00
Avoid using enum
This commit is contained in:
parent
d50610115b
commit
8139a4df2b
@ -5,6 +5,7 @@ package net.mamoe.mirai.event
|
||||
import net.mamoe.mirai.event.internal.Handler
|
||||
import net.mamoe.mirai.event.internal.Listener
|
||||
import net.mamoe.mirai.event.internal.subscribeInternal
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/*
|
||||
@ -14,9 +15,13 @@ import kotlin.reflect.KClass
|
||||
/**
|
||||
* 订阅者的状态
|
||||
*/
|
||||
enum class ListeningStatus {
|
||||
LISTENING,
|
||||
STOPPED
|
||||
inline class ListeningStatus(inline val listening: Boolean) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val LISTENING = ListeningStatus(true)
|
||||
@JvmStatic
|
||||
val STOPPED = ListeningStatus(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -141,13 +146,17 @@ class ListenerBuilder<out E : Subscribable>(
|
||||
|
||||
suspend inline fun always(noinline listener: suspend (E) -> Unit) = handler { listener(it); ListeningStatus.LISTENING }
|
||||
|
||||
suspend inline fun <T> until(until: T, noinline listener: suspend (E) -> T) = handler { if (listener(it) === until) ListeningStatus.STOPPED else ListeningStatus.LISTENING }
|
||||
suspend inline fun <T> until(until: T, noinline listener: suspend (E) -> T) =
|
||||
handler { if (listener(it) === until) ListeningStatus.STOPPED else ListeningStatus.LISTENING }
|
||||
|
||||
suspend inline fun untilFalse(noinline listener: suspend (E) -> Boolean) = until(false, listener)
|
||||
suspend inline fun untilTrue(noinline listener: suspend (E) -> Boolean) = until(true, listener)
|
||||
suspend inline fun untilNull(noinline listener: suspend (E) -> Any?) = until(null, listener)
|
||||
|
||||
|
||||
suspend inline fun <T> `while`(until: T, noinline listener: suspend (E) -> T) = handler { if (listener(it) !== until) ListeningStatus.STOPPED else ListeningStatus.LISTENING }
|
||||
suspend inline fun <T> `while`(until: T, noinline listener: suspend (E) -> T) =
|
||||
handler { if (listener(it) !== until) ListeningStatus.STOPPED else ListeningStatus.LISTENING }
|
||||
|
||||
suspend inline fun whileFalse(noinline listener: suspend (E) -> Boolean) = `while`(false, listener)
|
||||
suspend inline fun whileTrue(noinline listener: suspend (E) -> Boolean) = `while`(true, listener)
|
||||
suspend inline fun whileNull(noinline listener: suspend (E) -> Any?) = `while`(null, listener)
|
||||
|
@ -55,10 +55,6 @@ internal fun IoBuffer.parseMessageImage0x06(): Image {
|
||||
// 00 04 00 00 00 2E 1A 00 04 00 00 00 2E FF
|
||||
// 00 63 16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 36 36 38 65 35 43 36 38 45 36 42 44 32 46 35 38 34 31 42 30 39 37 39 45 37 46 32 35 34 33 38 38 31 33 43 33 2E 6A 70 67 66 2F 32 65 37 61 65 33 36 66 2D 61 39 31 63 2D 34 31 32 39 2D 62 61 34 32 2D 37 65 30 31 32 39 37 37 35 63 63 38 41
|
||||
|
||||
fun main() {
|
||||
println(".".repeat(1000))
|
||||
}
|
||||
|
||||
internal fun IoBuffer.parseMessageImage0x03(): Image {
|
||||
discardExact(1)
|
||||
|
||||
|
@ -2,43 +2,51 @@
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* QQ 在线状态
|
||||
*
|
||||
* @author Him188moe
|
||||
* @see net.mamoe.mirai.network.protocol.tim.packet.login.ChangeOnlineStatusPacket
|
||||
*/
|
||||
enum class OnlineStatus(
|
||||
val id: UByte//1 ubyte
|
||||
inline class OnlineStatus(
|
||||
inline val id: UByte
|
||||
) {
|
||||
/**
|
||||
* 我在线上
|
||||
*/
|
||||
ONLINE(0x0Au),
|
||||
companion object {
|
||||
/**
|
||||
* 我在线上
|
||||
*/
|
||||
@JvmStatic
|
||||
val ONLINE = OnlineStatus(0x0Au)
|
||||
|
||||
/**
|
||||
* 忙碌
|
||||
*/
|
||||
BUSY(0x32u),
|
||||
/**
|
||||
* 忙碌
|
||||
*/
|
||||
@JvmStatic
|
||||
val BUSY = OnlineStatus(0x32u)
|
||||
|
||||
/**
|
||||
* 离线 ? 也可能是被删好友 TODO confirm that
|
||||
*/
|
||||
OFFLINE(0x02u),
|
||||
/**
|
||||
* 离线 ? 也可能是被删好友 TODO confirm that
|
||||
*/
|
||||
@JvmStatic
|
||||
val OFFLINE = OnlineStatus(0x02u)
|
||||
|
||||
UNKNOWN1(0x20u),
|
||||
UNKNOWN2(0x46u),
|
||||
UNKNOWN3(0x14u),
|
||||
UNKNOWN4(0xC9u),
|
||||
UNKNOWN5(0x1Eu),
|
||||
;
|
||||
@JvmStatic
|
||||
val UNKNOWN1 = OnlineStatus(0x20u)
|
||||
@JvmStatic
|
||||
val UNKNOWN2 = OnlineStatus(0x46u)
|
||||
@JvmStatic
|
||||
val UNKNOWN3 = OnlineStatus(0x14u)
|
||||
@JvmStatic
|
||||
val UNKNOWN4 = OnlineStatus(0xC9u)
|
||||
@JvmStatic
|
||||
val UNKNOWN5 = OnlineStatus(0x1Eu)
|
||||
}
|
||||
|
||||
// TODO: 2019/10/29 what is 0x20u
|
||||
// TODO: 2019/11/11 what is 0x46u
|
||||
// TODO: 2019/11/11 what is 0x14u
|
||||
// TODO: 2019/11/11 0xC9u
|
||||
// TODO: 2019/11/11 0x1Eu
|
||||
companion object {
|
||||
fun ofId(id: UByte): OnlineStatus? = values().firstOrNull { it.id == id }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user