Commit 5292b224 authored by Him188's avatar Him188

Small updates

parent f51790e7
...@@ -23,7 +23,12 @@ import net.mamoe.mirai.contact.QQ ...@@ -23,7 +23,12 @@ import net.mamoe.mirai.contact.QQ
* *
* 但注意: 不能 `String + Message`. 只能 `Message + String` * 但注意: 不能 `String + Message`. 只能 `Message + String`
* *
* @see Contact.sendMessage * @see PlainText 纯文本
* @see Image 图片
* @see Face 表情
* @see MessageChain 消息链(即 `List<Message>`)
*
* @see Contact.sendMessage 发送消息
*/ */
sealed class Message { sealed class Message {
/** /**
...@@ -45,7 +50,7 @@ sealed class Message { ...@@ -45,7 +50,7 @@ sealed class Message {
*/ */
infix fun eq(other: String): Boolean = this.stringValue == other infix fun eq(other: String): Boolean = this.stringValue == other
abstract operator fun contains(sub: String): Boolean open operator fun contains(sub: String): Boolean = false
/** /**
* 把这个消息连接到另一个消息的头部. 类似于字符串相加 * 把这个消息连接到另一个消息的头部. 类似于字符串相加
...@@ -59,10 +64,14 @@ sealed class Message { ...@@ -59,10 +64,14 @@ sealed class Message {
infix operator fun plus(another: Number): MessageChain = this.concat(another.toString().toMessage()) infix operator fun plus(another: Number): MessageChain = this.concat(another.toString().toMessage())
} }
// ==================================== PlainText ====================================
data class PlainText(override val stringValue: String) : Message() { data class PlainText(override val stringValue: String) : Message() {
override operator fun contains(sub: String): Boolean = this.stringValue.contains(sub) override operator fun contains(sub: String): Boolean = this.stringValue.contains(sub)
} }
// ==================================== Image ====================================
/** /**
* 图片消息. * 图片消息.
* 由接收消息时构建, 可直接发送 * 由接收消息时构建, 可直接发送
...@@ -71,27 +80,30 @@ data class PlainText(override val stringValue: String) : Message() { ...@@ -71,27 +80,30 @@ data class PlainText(override val stringValue: String) : Message() {
*/ */
data class Image(val imageId: String) : Message() { data class Image(val imageId: String) : Message() {
override val stringValue: String = "[$imageId]" override val stringValue: String = "[$imageId]"
override operator fun contains(sub: String): Boolean = false //No string can be contained in a image
} }
// ==================================== At ====================================
/** /**
* At 一个人 * At 一个人
*/ */
data class At(val target: Long) : Message() { data class At(val targetQQ: Long) : Message() {
constructor(target: QQ) : this(target.number) constructor(target: QQ) : this(target.number)
override val stringValue: String = "[@$target]" override val stringValue: String = "[@$targetQQ]"
override operator fun contains(sub: String): Boolean = false
} }
// ==================================== Face ====================================
/** /**
* QQ 自带表情 * QQ 自带表情
*/ */
data class Face(val id: FaceID) : Message() { data class Face(val id: FaceID) : Message() {
override val stringValue: String = "[face${id.id}]" override val stringValue: String = "[face${id.id}]"
override operator fun contains(sub: String): Boolean = false
} }
// ==================================== MessageChain ====================================
data class MessageChain( data class MessageChain(
/** /**
* Elements will not be instances of [MessageChain] * Elements will not be instances of [MessageChain]
......
...@@ -19,7 +19,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.login.ServerSKeyResponsePacke ...@@ -19,7 +19,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.login.ServerSKeyResponsePacke
import net.mamoe.mirai.task.MiraiThreadPool import net.mamoe.mirai.task.MiraiThreadPool
import net.mamoe.mirai.utils.getGTK import net.mamoe.mirai.utils.getGTK
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
import java.io.Closeable
import java.util.* import java.util.*
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import java.util.concurrent.ScheduledFuture import java.util.concurrent.ScheduledFuture
...@@ -94,7 +93,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) { ...@@ -94,7 +93,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
val future = CompletableFuture<AddFriendResult>() val future = CompletableFuture<AddFriendResult>()
val session = AddFriendSession(qqNumber, future, message) val session = AddFriendSession(qqNumber, future, message)
// uploadImageSessions.add(session) // uploadImageSessions.add(session)
session.sendAddRequest(); session.sendAddRequest()
return future return future
} }
...@@ -117,7 +116,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) { ...@@ -117,7 +116,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
private val group: Long, private val group: Long,
private val future: CompletableFuture<AddFriendResult>, private val future: CompletableFuture<AddFriendResult>,
private val image: BufferedImage private val image: BufferedImage
) : Closeable { ) {
lateinit var id: ByteArray lateinit var id: ByteArray
...@@ -161,7 +160,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) { ...@@ -161,7 +160,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
} }
override fun close() { fun close() {
uploadImageSessions.remove(this) uploadImageSessions.remove(this)
} }
} }
...@@ -170,7 +169,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) { ...@@ -170,7 +169,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
private val qq: Long, private val qq: Long,
private val future: CompletableFuture<AddFriendResult>, private val future: CompletableFuture<AddFriendResult>,
private val message: Lazy<String> private val message: Lazy<String>
) : Closeable { ) {
lateinit var id: ByteArray lateinit var id: ByteArray
...@@ -215,7 +214,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) { ...@@ -215,7 +214,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
session.socket.sendPacket(ClientCanAddFriendPacket(session.bot.account.qqNumber, qq, session.sessionKey).also { this.id = it.packetIdLast }) session.socket.sendPacket(ClientCanAddFriendPacket(session.bot.account.qqNumber, qq, session.sessionKey).also { this.id = it.packetIdLast })
} }
override fun close() { fun close() {
// uploadImageSessions.remove(this) // uploadImageSessions.remove(this)
} }
} }
......
...@@ -15,7 +15,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket ...@@ -15,7 +15,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
* @author Him188moe * @author Him188moe
*/ */
interface DataPacketSocket { interface DataPacketSocket {
fun getOwner(): Bot val owner: Bot
/** /**
* 分发数据包给 [PacketHandler] * 分发数据包给 [PacketHandler]
......
...@@ -2,17 +2,16 @@ package net.mamoe.mirai.network.protocol.tim.handler ...@@ -2,17 +2,16 @@ package net.mamoe.mirai.network.protocol.tim.handler
import net.mamoe.mirai.network.LoginSession import net.mamoe.mirai.network.LoginSession
import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import java.io.Closeable
/** /**
* 数据包(接受/发送)处理器 * 数据包(接受/发送)处理器
*/ */
abstract class PacketHandler( abstract class PacketHandler(
val session: LoginSession val session: LoginSession
) : Closeable { ) {
abstract suspend fun onPacketReceived(packet: ServerPacket) abstract suspend fun onPacketReceived(packet: ServerPacket)
override fun close() { open fun close() {
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment