Commit 5292b224 authored by Him188's avatar Him188

Small updates

parent f51790e7
......@@ -23,7 +23,12 @@ import net.mamoe.mirai.contact.QQ
*
* 但注意: 不能 `String + Message`. 只能 `Message + String`
*
* @see Contact.sendMessage
* @see PlainText 纯文本
* @see Image 图片
* @see Face 表情
* @see MessageChain 消息链(即 `List<Message>`)
*
* @see Contact.sendMessage 发送消息
*/
sealed class Message {
/**
......@@ -45,7 +50,7 @@ sealed class Message {
*/
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 {
infix operator fun plus(another: Number): MessageChain = this.concat(another.toString().toMessage())
}
// ==================================== PlainText ====================================
data class PlainText(override val stringValue: String) : Message() {
override operator fun contains(sub: String): Boolean = this.stringValue.contains(sub)
}
// ==================================== Image ====================================
/**
* 图片消息.
* 由接收消息时构建, 可直接发送
......@@ -71,27 +80,30 @@ data class PlainText(override val stringValue: String) : Message() {
*/
data class Image(val imageId: String) : Message() {
override val stringValue: String = "[$imageId]"
override operator fun contains(sub: String): Boolean = false //No string can be contained in a image
}
// ==================================== At ====================================
/**
* At 一个人
*/
data class At(val target: Long) : Message() {
data class At(val targetQQ: Long) : Message() {
constructor(target: QQ) : this(target.number)
override val stringValue: String = "[@$target]"
override operator fun contains(sub: String): Boolean = false
override val stringValue: String = "[@$targetQQ]"
}
// ==================================== Face ====================================
/**
* QQ 自带表情
*/
data class Face(val id: FaceID) : Message() {
override val stringValue: String = "[face${id.id}]"
override operator fun contains(sub: String): Boolean = false
}
// ==================================== MessageChain ====================================
data class MessageChain(
/**
* Elements will not be instances of [MessageChain]
......
......@@ -19,7 +19,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.login.ServerSKeyResponsePacke
import net.mamoe.mirai.task.MiraiThreadPool
import net.mamoe.mirai.utils.getGTK
import java.awt.image.BufferedImage
import java.io.Closeable
import java.util.*
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ScheduledFuture
......@@ -94,7 +93,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
val future = CompletableFuture<AddFriendResult>()
val session = AddFriendSession(qqNumber, future, message)
// uploadImageSessions.add(session)
session.sendAddRequest();
session.sendAddRequest()
return future
}
......@@ -117,7 +116,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
private val group: Long,
private val future: CompletableFuture<AddFriendResult>,
private val image: BufferedImage
) : Closeable {
) {
lateinit var id: ByteArray
......@@ -161,7 +160,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
}
override fun close() {
fun close() {
uploadImageSessions.remove(this)
}
}
......@@ -170,7 +169,7 @@ class ActionPacketHandler(session: LoginSession) : PacketHandler(session) {
private val qq: Long,
private val future: CompletableFuture<AddFriendResult>,
private val message: Lazy<String>
) : Closeable {
) {
lateinit var id: ByteArray
......@@ -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 })
}
override fun close() {
fun close() {
// uploadImageSessions.remove(this)
}
}
......
......@@ -15,7 +15,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
* @author Him188moe
*/
interface DataPacketSocket {
fun getOwner(): Bot
val owner: Bot
/**
* 分发数据包给 [PacketHandler]
......
......@@ -2,17 +2,16 @@ package net.mamoe.mirai.network.protocol.tim.handler
import net.mamoe.mirai.network.LoginSession
import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import java.io.Closeable
/**
* 数据包(接受/发送)处理器
*/
abstract class PacketHandler(
val session: LoginSession
) : Closeable {
) {
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