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
17aff7d5
Commit
17aff7d5
authored
Feb 23, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `quoteReply` common to MessagePacket
parent
c441043d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
34 deletions
+39
-34
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
...ndroid/network/protocol/packet/chat/receive/MessageSvc.kt
+0
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/FriendMessage.kt
...ommonMain/kotlin/net.mamoe.mirai/message/FriendMessage.kt
+0
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt
...commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt
+0
-12
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
...ommonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
+20
-13
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
...commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
...monMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
+17
-6
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
17aff7d5
...
@@ -212,7 +212,6 @@ internal class MessageSvc {
...
@@ -212,7 +212,6 @@ internal class MessageSvc {
msg
.
msgHead
.
fromUin
==
bot
.
uin
->
null
msg
.
msgHead
.
fromUin
==
bot
.
uin
->
null
!
bot
.
firstLoginSucceed
->
null
!
bot
.
firstLoginSucceed
->
null
else
->
FriendMessage
(
else
->
FriendMessage
(
bot
,
bot
.
getFriend
(
msg
.
msgHead
.
fromUin
),
bot
.
getFriend
(
msg
.
msgHead
.
fromUin
),
msg
.
toMessageChain
()
msg
.
toMessageChain
()
)
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/FriendMessage.kt
View file @
17aff7d5
...
@@ -17,7 +17,6 @@ import net.mamoe.mirai.utils.getValue
...
@@ -17,7 +17,6 @@ import net.mamoe.mirai.utils.getValue
import
net.mamoe.mirai.utils.unsafeWeakRef
import
net.mamoe.mirai.utils.unsafeWeakRef
class
FriendMessage
(
class
FriendMessage
(
bot
:
Bot
,
sender
:
QQ
,
sender
:
QQ
,
override
val
message
:
MessageChain
override
val
message
:
MessageChain
)
:
MessagePacket
<
QQ
,
QQ
>(),
BroadcastControllable
{
)
:
MessagePacket
<
QQ
,
QQ
>(),
BroadcastControllable
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt
View file @
17aff7d5
...
@@ -43,18 +43,6 @@ class GroupMessage(
...
@@ -43,18 +43,6 @@ class GroupMessage(
inline
fun
Long
.
member
():
Member
=
group
[
this
]
inline
fun
Long
.
member
():
Member
=
group
[
this
]
/**
* 给这个消息事件的主体发送引用回复消息
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
*/
suspend
inline
fun
quoteReply
(
message
:
MessageChain
):
MessageReceipt
<
Group
>
=
reply
(
this
.
message
.
quote
()
+
message
)
suspend
inline
fun
quoteReply
(
message
:
Message
):
MessageReceipt
<
Group
>
=
reply
(
this
.
message
.
quote
()
+
message
)
suspend
inline
fun
quoteReply
(
plain
:
String
):
MessageReceipt
<
Group
>
=
reply
(
this
.
message
.
quote
()
+
plain
)
@JvmName
(
"reply2"
)
@JvmName
(
"reply2"
)
suspend
inline
fun
String
.
quoteReply
():
MessageReceipt
<
Group
>
=
quoteReply
(
this
)
suspend
inline
fun
String
.
quoteReply
():
MessageReceipt
<
Group
>
=
quoteReply
(
this
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
View file @
17aff7d5
...
@@ -91,27 +91,34 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
...
@@ -91,27 +91,34 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
suspend
inline
fun
MessageChain
.
reply
():
MessageReceipt
<
TSubject
>
=
reply
(
this
)
suspend
inline
fun
MessageChain
.
reply
():
MessageReceipt
<
TSubject
>
=
reply
(
this
)
// endregion
// endregion
// region
/**
* 引用这个消息. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException]
*/
inline
fun
MessageChain
.
quote
():
MessageChain
=
this
.
quote
(
sender
as
?
Member
?:
error
(
"only group message can be quoted"
))
// endregion
// region 上传图片
// region 上传图片
suspend
inline
fun
ExternalImage
.
upload
():
Image
=
this
.
upload
(
subject
)
suspend
inline
fun
ExternalImage
.
upload
():
Image
=
this
.
upload
(
subject
)
// endregion
// endregion
// region 发送图片
// region 发送图片
suspend
inline
fun
ExternalImage
.
send
()
=
this
.
sendTo
(
subject
)
suspend
inline
fun
ExternalImage
.
send
()
:
MessageReceipt
<
TSubject
>
=
this
.
sendTo
(
subject
)
suspend
inline
fun
Image
.
send
()
=
this
.
sendTo
(
subject
)
suspend
inline
fun
Image
.
send
()
:
MessageReceipt
<
TSubject
>
=
this
.
sendTo
(
subject
)
suspend
inline
fun
Message
.
send
()
=
this
.
sendTo
(
subject
)
suspend
inline
fun
Message
.
send
()
:
MessageReceipt
<
TSubject
>
=
this
.
sendTo
(
subject
)
suspend
inline
fun
String
.
send
()
=
this
.
toMessage
().
sendTo
(
subject
)
suspend
inline
fun
String
.
send
()
:
MessageReceipt
<
TSubject
>
=
this
.
toMessage
().
sendTo
(
subject
)
// endregion
// endregion
/**
* 给这个消息事件的主体发送引用回复消息
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
*/
suspend
inline
fun
quoteReply
(
message
:
MessageChain
):
MessageReceipt
<
TSubject
>
=
reply
(
this
.
message
.
quote
()
+
message
)
suspend
inline
fun
quoteReply
(
message
:
Message
):
MessageReceipt
<
TSubject
>
=
reply
(
this
.
message
.
quote
()
+
message
)
suspend
inline
fun
quoteReply
(
plain
:
String
):
MessageReceipt
<
TSubject
>
=
reply
(
this
.
message
.
quote
()
+
plain
)
/**
* 引用这个消息. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException]
*/
inline
fun
MessageChain
.
quote
():
MessageChain
=
this
.
quote
(
sender
)
operator
fun
<
M
:
Message
>
get
(
at
:
Message
.
Key
<
M
>):
M
{
operator
fun
<
M
:
Message
>
get
(
at
:
Message
.
Key
<
M
>):
M
{
return
this
.
message
[
at
]
return
this
.
message
[
at
]
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
View file @
17aff7d5
...
@@ -13,6 +13,7 @@ package net.mamoe.mirai.message.data
...
@@ -13,6 +13,7 @@ package net.mamoe.mirai.message.data
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.message.MessageReceipt
import
kotlin.jvm.JvmSynthetic
import
kotlin.jvm.JvmSynthetic
/**
/**
...
@@ -108,4 +109,4 @@ interface SingleOnly : Message
...
@@ -108,4 +109,4 @@ interface SingleOnly : Message
/**
/**
* 将 [this] 发送给指定联系人
* 将 [this] 发送给指定联系人
*/
*/
suspend
inline
fun
Message
.
sendTo
(
contact
:
Contact
)
=
contact
.
sendMessage
(
this
)
suspend
inline
fun
<
C
:
Contact
>
Message
.
sendTo
(
contact
:
C
):
MessageReceipt
<
C
>
=
contact
.
sendMessage
(
this
)
\ No newline at end of file
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
View file @
17aff7d5
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
package
net.mamoe.mirai.message.data
package
net.mamoe.mirai.message.data
import
net.mamoe.mirai.contact.Member
import
net.mamoe.mirai.contact.Member
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
...
@@ -32,10 +33,15 @@ class QuoteReply @MiraiInternalAPI constructor(val source: MessageSource) : Mess
...
@@ -32,10 +33,15 @@ class QuoteReply @MiraiInternalAPI constructor(val source: MessageSource) : Mess
* 引用这条消息.
* 引用这条消息.
* 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
* 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
*/
*/
fun
MessageChain
.
quote
(
sender
:
Member
):
MessageChain
{
@UseExperimental
(
MiraiInternalAPI
::
class
)
fun
MessageChain
.
quote
(
sender
:
QQ
):
MessageChain
{
this
.
firstOrNull
<
MessageSource
>()
?.
let
{
this
.
firstOrNull
<
MessageSource
>()
?.
let
{
@UseExperimental
(
MiraiInternalAPI
::
class
)
return
if
(
it
.
groupId
==
0L
)
{
return
QuoteReply
(
it
)
+
sender
.
at
()
+
" "
// required
QuoteReply
(
it
)
+
" "
// required
}
else
{
check
(
sender
is
Member
)
{
"sender must be Member to quote a GroupMessage"
}
QuoteReply
(
it
)
+
sender
.
at
()
+
" "
// required
}
}
}
error
(
"cannot find MessageSource"
)
error
(
"cannot find MessageSource"
)
}
}
...
@@ -44,7 +50,12 @@ fun MessageChain.quote(sender: Member): MessageChain {
...
@@ -44,7 +50,12 @@ fun MessageChain.quote(sender: Member): MessageChain {
* 引用这条消息.
* 引用这条消息.
* 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
* 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
*/
*/
fun
MessageSource
.
quote
(
sender
:
Member
):
MessageChain
{
@UseExperimental
(
MiraiInternalAPI
::
class
)
@UseExperimental
(
MiraiInternalAPI
::
class
)
fun
MessageSource
.
quote
(
sender
:
QQ
):
MessageChain
{
return
QuoteReply
(
this
)
+
sender
.
at
()
+
" "
// required
return
if
(
this
.
groupId
==
0L
)
{
QuoteReply
(
this
)
+
" "
// required
}
else
{
check
(
sender
is
Member
)
{
"sender must be Member to quote a GroupMessage"
}
QuoteReply
(
this
)
+
sender
.
at
()
+
" "
// required
}
}
}
\ No newline at end of file
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