1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-24 20:43:33 +08:00

Change sendMessage to extension

This commit is contained in:
Him188 2019-12-04 22:45:10 +08:00
parent 39ad1599ae
commit 2621c15519
3 changed files with 22 additions and 28 deletions
gradle.properties
mirai-core/src/commonMain/kotlin/net.mamoe.mirai
contact/internal
network/protocol/tim/packet/action

View File

@ -1,7 +1,7 @@
# style guide
kotlin.code.style=official
# config
mirai_version=0.6.1
mirai_version=0.7.0
kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
# kotlin

View File

@ -7,10 +7,7 @@ import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.contact.data.Profile
import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.message.Message
import net.mamoe.mirai.message.MessageChain
import net.mamoe.mirai.message.chain
import net.mamoe.mirai.message.singleChain
import net.mamoe.mirai.network.protocol.tim.packet.action.*
import net.mamoe.mirai.network.protocol.tim.packet.event.MemberJoinEventPacket
import net.mamoe.mirai.network.protocol.tim.packet.event.MemberQuitEvent
@ -26,11 +23,6 @@ import kotlin.coroutines.CoroutineContext
internal sealed class ContactImpl : Contact {
abstract override suspend fun sendMessage(message: MessageChain)
//这两个方法应写为扩展函数, 但为方便 import 还是写在这里
override suspend fun sendMessage(plain: String) = sendMessage(plain.singleChain())
override suspend fun sendMessage(message: Message) = sendMessage(message.chain())
/**
* 开始监听事件, 以同步更新资料
*/

View File

@ -9,6 +9,7 @@ import net.mamoe.mirai.network.protocol.tim.TIMProtocol
import net.mamoe.mirai.network.protocol.tim.packet.*
import net.mamoe.mirai.network.protocol.tim.packet.event.EventPacket
import net.mamoe.mirai.utils.io.*
import net.mamoe.mirai.withSession
/**
@ -87,26 +88,27 @@ object CanAddFriendPacket : SessionPacketFactory<CanAddFriendResponse>() {
writeQQ(qq)
}
override suspend fun ByteReadPacket.decode(id: PacketId, sequenceId: UShort, handler: BotNetworkHandler<*>): CanAddFriendResponse = with(handler.bot) {
if (remaining > 20) {//todo check
return CanAddFriendResponse.AlreadyAdded(readUInt().qq())
override suspend fun ByteReadPacket.decode(id: PacketId, sequenceId: UShort, handler: BotNetworkHandler<*>): CanAddFriendResponse =
handler.bot.withSession {
if (remaining > 20) {//todo check
return CanAddFriendResponse.AlreadyAdded(readUInt().qq())
}
val qq: QQ = readUInt().qq()
// debugDiscardExact(1)
return when (val state = readUByte().toUInt()) {
//09 4E A4 B1 00 03
0x00u -> CanAddFriendResponse.ReadyToAdd(qq)
0x01u -> CanAddFriendResponse.RequireVerification(qq)
0x99u -> CanAddFriendResponse.AlreadyAdded(qq)
0x03u,
0x04u -> CanAddFriendResponse.Rejected(qq)
else -> error(state.toString())
}
}
val qq: QQ = readUInt().qq()
// debugDiscardExact(1)
return when (val state = readUByte().toUInt()) {
//09 4E A4 B1 00 03
0x00u -> CanAddFriendResponse.ReadyToAdd(qq)
0x01u -> CanAddFriendResponse.RequireVerification(qq)
0x99u -> CanAddFriendResponse.AlreadyAdded(qq)
0x03u,
0x04u -> CanAddFriendResponse.Rejected(qq)
else -> error(state.toString())
}
}
}