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
dcdee6b8
Commit
dcdee6b8
authored
Nov 25, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
At supported
parent
bf8e65e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
12 deletions
+33
-12
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
+2
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageType.kt
.../commonMain/kotlin/net.mamoe.mirai/message/MessageType.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt
...n/net.mamoe.mirai/message/internal/MessageDataInternal.kt
+25
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Ignored.kt
....mamoe.mirai/network/protocol/tim/packet/event/Ignored.kt
+2
-1
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
...rai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
+3
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
View file @
dcdee6b8
...
@@ -218,10 +218,10 @@ suspend inline fun ImageId.sendTo(contact: Contact) = contact.sendMessage(this.i
...
@@ -218,10 +218,10 @@ suspend inline fun ImageId.sendTo(contact: Contact) = contact.sendMessage(this.i
/**
/**
* At 一个人
* At 一个人
*/
*/
inline
class
At
(
val
target
QQ
:
UInt
)
:
Message
{
inline
class
At
(
val
target
:
UInt
)
:
Message
{
constructor
(
target
:
QQ
)
:
this
(
target
.
id
)
constructor
(
target
:
QQ
)
:
this
(
target
.
id
)
override
val
stringValue
:
String
get
()
=
"[@$target
QQ]"
override
val
stringValue
:
String
get
()
=
"[@$target
]"
// TODO: 2019/11/25 使用群名称进行 at. 因为手机端只会显示这个文字
override
fun
toString
():
String
=
stringValue
override
fun
toString
():
String
=
stringValue
companion
object
Key
:
Message
.
Key
<
At
>
companion
object
Key
:
Message
.
Key
<
At
>
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageType.kt
View file @
dcdee6b8
...
@@ -6,7 +6,7 @@ package net.mamoe.mirai.message
...
@@ -6,7 +6,7 @@ package net.mamoe.mirai.message
@Suppress
(
"unused"
)
@Suppress
(
"unused"
)
enum
class
MessageType
(
val
value
:
UByte
)
{
enum
class
MessageType
(
val
value
:
UByte
)
{
PLAIN_TEXT
(
0
x01u
),
PLAIN_TEXT
(
0
x01u
),
AT
(
0
x0
6u
),
AT
(
0
x0
1u
),
// same as PLAIN
FACE
(
0
x02u
),
FACE
(
0
x02u
),
/**
/**
* [ImageId.value] 长度为 42 的图片
* [ImageId.value] 长度为 42 的图片
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt
View file @
dcdee6b8
...
@@ -18,9 +18,16 @@ internal fun IoBuffer.parseMessageFace(): Face {
...
@@ -18,9 +18,16 @@ internal fun IoBuffer.parseMessageFace(): Face {
return
Face
(
id1
)
return
Face
(
id1
)
}
}
internal
fun
IoBuffer
.
parsePlainText
():
PlainText
{
internal
fun
IoBuffer
.
parsePlainTextOrAt
():
Message
{
discardExact
(
1
)
//0x01
// 06 00 0D 00 01 00 00 00 08 00 76 E4 B8 DD 00 00
return
PlainText
(
readUShortLVString
())
discardExact
(
1
)
// 0x01 whenever plain or at
val
msg
=
readUShortLVString
()
return
if
(
this
.
readRemaining
==
0
)
{
PlainText
(
msg
)
}
else
{
discardExact
(
10
)
At
(
readUInt
())
}
}
}
internal
fun
IoBuffer
.
parseLongText0x19
():
PlainText
{
internal
fun
IoBuffer
.
parseLongText0x19
():
PlainText
{
...
@@ -59,7 +66,7 @@ internal fun IoBuffer.parseMessageImage0x06(): Image {
...
@@ -59,7 +66,7 @@ internal fun IoBuffer.parseMessageImage0x06(): Image {
internal
fun
IoBuffer
.
parseMessageImage0x03
():
Image
{
internal
fun
IoBuffer
.
parseMessageImage0x03
():
Image
{
//discardExact(1)
//discardExact(1)
val
tlv
=
readTLVMap
(
expectingEOF
=
true
,
tagSize
=
1
)
val
tlv
=
readTLVMap
(
expectingEOF
=
true
,
tagSize
=
1
)
tlv
.
printTLVMap
(
"parseMessageImage0x03"
)
//
tlv.printTLVMap("parseMessageImage0x03")
// 02 [ ] IMAGE ID
// 02 [ ] IMAGE ID
// 04 [00 04] 8B 88 95 C1
// 04 [00 04] 8B 88 95 C1
// 05 [00 04] 3B 24 59 FC
// 05 [00 04] 3B 24 59 FC
...
@@ -85,7 +92,7 @@ internal fun IoBuffer.parseMessageImage0x03(): Image {
...
@@ -85,7 +92,7 @@ internal fun IoBuffer.parseMessageImage0x03(): Image {
uniqueId
=
tlv
[
0
x04u
]
!!
.
read
{
readUInt
()
},
uniqueId
=
tlv
[
0
x04u
]
!!
.
read
{
readUInt
()
},
height
=
tlv
[
0
x16u
]
!!
.
toUInt
().
toInt
(),
height
=
tlv
[
0
x16u
]
!!
.
toUInt
().
toInt
(),
width
=
tlv
[
0
x15u
]
!!
.
toUInt
().
toInt
()
width
=
tlv
[
0
x15u
]
!!
.
toUInt
().
toInt
()
).
also
{
debugPrintln
(
"ImageId: $it"
)
}
)
//
.also { debugPrintln("ImageId: $it") }
)
)
//} else {
//} else {
// Image(
// Image(
...
@@ -113,8 +120,7 @@ internal fun ByteReadPacket.readMessage(): Message? {
...
@@ -113,8 +120,7 @@ internal fun ByteReadPacket.readMessage(): Message? {
return
try
{
return
try
{
when
(
messageType
)
{
when
(
messageType
)
{
//todo 在每个parse里面都 discard 了第一 byte.
0
x01
->
sectionData
.
parsePlainTextOrAt
()
0
x01
->
sectionData
.
parsePlainText
()
0
x02
->
sectionData
.
parseMessageFace
()
0
x02
->
sectionData
.
parseMessageFace
()
0
x03
->
sectionData
.
parseMessageImage0x03
()
0
x03
->
sectionData
.
parseMessageImage0x03
()
0
x06
->
sectionData
.
parseMessageImage0x06
()
0
x06
->
sectionData
.
parseMessageImage0x06
()
...
@@ -196,7 +202,18 @@ fun MessageChain.toPacket(): ByteReadPacket = buildPacket {
...
@@ -196,7 +202,18 @@ fun MessageChain.toPacket(): ByteReadPacket = buildPacket {
}
}
}
}
is
At
->
throw
UnsupportedOperationException
(
"At is not supported now but is expecting to be supported"
)
is
At
->
buildPacket
{
writeUByte
(
MessageType
.
AT
.
value
)
writeShortLVPacket
{
writeByte
(
0
x01
)
writeShortLVString
(
stringValue
)
// 这个应该是 "@群名", 手机上面会显示这个消息, 电脑会显示下面那个
// 06 00 0D 00 01 00 00 00 08 00 76 E4 B8 DD 00 00
writeHex
(
"06 00 0D 00 01 00 00 00 08 00"
)
writeUInt
(
target
)
writeZero
(
2
)
}
}
is
Image
->
buildPacket
{
is
Image
->
buildPacket
{
when
(
id
.
value
.
length
)
{
when
(
id
.
value
.
length
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/Ignored.kt
View file @
dcdee6b8
...
@@ -4,9 +4,10 @@ package net.mamoe.mirai.network.protocol.tim.packet.event
...
@@ -4,9 +4,10 @@ package net.mamoe.mirai.network.protocol.tim.packet.event
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.ByteReadPacket
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.utils.io.toUHexString
inline
class
IgnoredEventPacket
(
val
id
:
UShort
)
:
EventPacket
{
inline
class
IgnoredEventPacket
(
val
id
:
UShort
)
:
EventPacket
{
override
fun
toString
():
String
=
"IgnoredEventPacket(id=
$id
)"
override
fun
toString
():
String
=
"IgnoredEventPacket(id=
0x${id.toUHexString("")}
)"
}
}
object
IgnoredEventIds
:
List
<
IgnoredEventParserAndHandler
>
by
{
object
IgnoredEventIds
:
List
<
IgnoredEventParserAndHandler
>
by
{
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
View file @
dcdee6b8
...
@@ -12,6 +12,7 @@ import net.mamoe.mirai.contact.MemberPermission
...
@@ -12,6 +12,7 @@ import net.mamoe.mirai.contact.MemberPermission
import
net.mamoe.mirai.event.Subscribable
import
net.mamoe.mirai.event.Subscribable
import
net.mamoe.mirai.event.subscribeAlways
import
net.mamoe.mirai.event.subscribeAlways
import
net.mamoe.mirai.event.subscribeMessages
import
net.mamoe.mirai.event.subscribeMessages
import
net.mamoe.mirai.message.At
import
net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.getValue
import
net.mamoe.mirai.message.getValue
import
net.mamoe.mirai.message.sendAsImageTo
import
net.mamoe.mirai.message.sendAsImageTo
...
@@ -60,6 +61,8 @@ suspend fun main() {
...
@@ -60,6 +61,8 @@ suspend fun main() {
}
}
bot
.
subscribeMessages
{
bot
.
subscribeMessages
{
case
(
"at me"
)
{
At
(
sender
).
reply
()
}
"你好"
reply
"你好!"
"你好"
reply
"你好!"
startsWith
(
"profile"
,
removePrefix
=
true
)
{
startsWith
(
"profile"
,
removePrefix
=
true
)
{
...
...
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