Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
5292b224
Commit
5292b224
authored
Oct 10, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small updates
parent
f51790e7
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
64 deletions
+70
-64
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/Message.kt
...ore/src/jvmMain/kotlin/net/mamoe/mirai/message/Message.kt
+19
-7
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/TIMBotNetworkHandler.kt
.../mamoe/mirai/network/protocol/tim/TIMBotNetworkHandler.kt
+43
-47
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/ActionPacketHandler.kt
...mirai/network/protocol/tim/handler/ActionPacketHandler.kt
+5
-6
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/DataPacketSocket.kt
...oe/mirai/network/protocol/tim/handler/DataPacketSocket.kt
+1
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt
...mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt
+2
-3
No files found.
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/message/Message.kt
View file @
5292b224
...
...
@@ -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
target
QQ
:
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]
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/TIMBotNetworkHandler.kt
View file @
5292b224
This diff is collapsed.
Click to expand it.
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/ActionPacketHandler.kt
View file @
5292b224
...
...
@@ -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)
}
}
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/DataPacketSocket.kt
View file @
5292b224
...
...
@@ -15,7 +15,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
* @author Him188moe
*/
interface
DataPacketSocket
{
fun
getOwner
()
:
Bot
val
owner
:
Bot
/**
* 分发数据包给 [PacketHandler]
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/network/protocol/tim/handler/PacketHandler.kt
View file @
5292b224
...
...
@@ -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
)
o
verride
fun
close
()
{
o
pen
fun
close
()
{
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment