Skip to content

Commit

Permalink
Update to mirai-core 0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Apr 3, 2020
1 parent a90ae33 commit 513023e
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
16 changes: 7 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# build
httpVersion=v1.4.0

# style guide
kotlin.code.style=official
# config
miraiVersion=0.31.4
miraiConsoleVersion=0.3.9
miraiVersion=0.32.0
miraiConsoleVersion=0.4.2
kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
# kotlin
kotlinVersion=1.4-M1
kotlinVersion=1.3.71
# kotlin libraries
serializationVersion=0.20.0-1.4-M1
coroutinesVersion=1.3.5-1.4-M1
atomicFuVersion=0.14.2-1.4-M1
serializationVersion=0.20.0
coroutinesVersion=1.3.5
atomicFuVersion=0.14.2
kotlinXIoVersion=0.1.16

coroutinesIoVersion=0.1.16
# utility
ktorVersion=1.3.2-1.4-M1
ktorVersion=1.3.2
klockVersion=1.7.0
# gradle plugin
protobufJavaVersion=3.10.0
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Thu Feb 27 13:09:44 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
#Fri Feb 28 20:15:46 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
2 changes: 1 addition & 1 deletion mirai-api-http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ kotlin {
api(ktor("server-cio"))
api(ktor("http-jvm"))
api(ktor("websockets"))
api(kotlinx("io-jvm"))
compileOnly(kotlinx("io-jvm"))
api("org.slf4j:slf4j-simple:1.7.26")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import net.mamoe.mirai.api.http.queue.MessageQueue
import net.mamoe.mirai.event.Listener
import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.message.MessagePacket
import net.mamoe.mirai.message.ContactMessage
import net.mamoe.mirai.utils.currentTimeSeconds
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
Expand Down Expand Up @@ -124,7 +124,7 @@ class AuthedSession internal constructor(val bot: Bot, originKey: String, corout
enableWebsocket = HttpApiPluginBase.enableWebsocket
)
private var _listener: Listener<BotEvent>
private val _cache: Listener<MessagePacket<*, *>>
private val _cache: Listener<ContactMessage>
private val releaseJob: Job //手动释放将会在下一次检查时回收Session

internal var latestUsed = currentTimeSeconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ package net.mamoe.mirai.api.http.data.common
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.event.events.*
import net.mamoe.mirai.message.MessagePacket
import net.mamoe.mirai.message.ContactMessage

@Serializable
sealed class BotEventDTO : EventDTO()

suspend fun BotEvent.toDTO() = when (this) {
is MessagePacket<*, *> -> toDTO()
is ContactMessage -> toDTO()
else -> when (this) {
is BotOnlineEvent -> BotOnlineEventDTO(bot.uin)
is BotOfflineEvent.Active -> BotOfflineEventActiveDTO(bot.uin)
is BotOfflineEvent.Force -> BotOfflineEventForceDTO(bot.uin, title, message)
is BotOfflineEvent.Dropped -> BotOfflineEventDroppedDTO(bot.uin)
is BotReloginEvent -> BotReloginEventDTO(bot.uin)
is BotOnlineEvent -> BotOnlineEventDTO(bot.id)
is BotOfflineEvent.Active -> BotOfflineEventActiveDTO(bot.id)
is BotOfflineEvent.Force -> BotOfflineEventForceDTO(bot.id, title, message)
is BotOfflineEvent.Dropped -> BotOfflineEventDroppedDTO(bot.id)
is BotReloginEvent -> BotReloginEventDTO(bot.id)
is MessageRecallEvent.GroupRecall -> GroupRecallEventDTO(
authorId,
messageId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ suspend fun MessageDTO.toMessage(contact: Contact) = when (this) {
// ignore
is QuoteDTO,
is MessageSourceDTO,
is UnknownMessageDTO,
is UnknownMessageDTO
-> null
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@

package net.mamoe.mirai.api.http.queue

import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.message.MessagePacket
import net.mamoe.mirai.message.ContactMessage
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.utils.firstKey

class CacheQueue : LinkedHashMap<Long, MessagePacket<*, *>>() {
class CacheQueue : LinkedHashMap<Long, ContactMessage>() {

var cacheSize = 4096

override fun get(key: Long): MessagePacket<*, *> = super.get(key) ?: throw NoSuchElementException()
override fun get(key: Long): ContactMessage = super.get(key) ?: throw NoSuchElementException()

override fun put(key: Long, value: MessagePacket<*, *>): MessagePacket<*, *>? = super.put(key, value).also {
override fun put(key: Long, value: ContactMessage): ContactMessage? = super.put(key, value).also {
if (size > cacheSize) {
remove(firstKey())
remove(this.entries.first().key)
}
}

fun add(packet: MessagePacket<*, *>) {
fun add(packet: ContactMessage) {
put(packet[MessageSource].id, packet)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import net.mamoe.mirai.api.http.data.common.EventDTO
import net.mamoe.mirai.api.http.data.common.IgnoreEventDTO
import net.mamoe.mirai.api.http.data.common.toDTO
import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.message.MessagePacket
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.utils.firstKey
import java.util.concurrent.ConcurrentLinkedDeque

class MessageQueue : ConcurrentLinkedDeque<BotEvent>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import net.mamoe.mirai.api.http.data.StateCode
import net.mamoe.mirai.api.http.data.common.AuthDTO
import net.mamoe.mirai.api.http.data.common.DTO
import net.mamoe.mirai.api.http.data.common.VerifyDTO
import kotlin.coroutines.EmptyCoroutineContext


fun Application.authModule() {
Expand All @@ -43,7 +42,7 @@ fun Application.authModule() {
miraiVerify<BindDTO>("/release") {
val bot = getBotOrThrow(it.qq)
val session = SessionManager[it.sessionKey] as AuthedSession
if (bot.uin == session.bot.uin) {
if (bot.id == session.bot.id) {
SessionManager.closeSession(it.sessionKey)
call.respondStateCode(StateCode.Success)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ data class CommandDTO(
val name: String,
val friend: Long,
val group: Long,
val args: List<String>,
val args: List<String>
) : DTO

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import net.mamoe.mirai.api.http.util.toJson
import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.message.MessagePacket
import net.mamoe.mirai.message.ContactMessage

fun Application.websocketRouteModule() {
routing {
Expand All @@ -51,7 +51,7 @@ fun Application.websocketRouteModule() {

miraiWebsocket("/event") {
val listener = it.bot.subscribeAlways<BotEvent> {
if (this !is MessagePacket<*, *>) {
if (this !is ContactMessage) {
this.toDTO().takeIf { dto -> dto != IgnoreEventDTO }?.apply {
outgoing.send(Frame.Text(this.toJson()))
}
Expand Down

0 comments on commit 513023e

Please sign in to comment.