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
067a9496
Commit
067a9496
authored
Feb 29, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `MessageSource.senderId` to `MessageSource.qqId`
parent
0cbc0f0e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
43 deletions
+65
-43
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+33
-17
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
...net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
+2
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt
...ai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt
+1
-2
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
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+14
-14
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
...mmonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
+3
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
...Main/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
+8
-1
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
067a9496
...
...
@@ -122,38 +122,54 @@ internal abstract class QQAndroidBotBase constructor(
}
override
suspend
fun
recall
(
source
:
MessageSource
)
{
if
(
source
.
senderId
!=
uin
)
{
if
(
source
.
qqId
!=
uin
&&
source
.
groupId
!=
0L
)
{
getGroup
(
source
.
groupId
).
checkBotPermissionOperator
()
}
source
.
ensureSequenceIdAvailable
()
network
.
run
{
val
response
:
PbMessageSvc
.
PbMsgWithDraw
.
Response
=
if
(
source
.
groupId
==
0L
)
{
PbMessageSvc
.
PbMsgWithDraw
.
Friend
(
bot
.
client
,
source
.
senderId
,
source
.
sequenceId
,
source
.
messageRandom
,
source
.
time
)
.
sendAndExpect
()
}
else
{
val
response
:
PbMessageSvc
.
PbMsgWithDraw
.
Response
=
if
(
source
.
groupId
==
0L
)
{
PbMessageSvc
.
PbMsgWithDraw
.
Friend
(
bot
.
client
,
source
.
qqId
,
source
.
sequenceId
,
source
.
messageRandom
,
source
.
time
)
.
sendAndExpect
()
}
else
{
PbMessageSvc
.
PbMsgWithDraw
.
Group
(
bot
.
client
,
source
.
groupId
,
source
.
sequenceId
,
source
.
messageRandom
)
.
sendAndExpect
()
}
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #${source.id}: $response"
}
}
}
PbMessageSvc
.
PbMsgWithDraw
.
Group
(
bot
.
client
,
source
.
groupId
,
source
.
sequenceId
,
source
.
messageRandom
)
override
suspend
fun
_lowLevelRecallFriendMessage
(
friendId
:
Long
,
messageId
:
Long
)
{
network
.
run
{
val
response
:
PbMessageSvc
.
PbMsgWithDraw
.
Response
=
PbMessageSvc
.
PbMsgWithDraw
.
Friend
(
client
,
friendId
,
(
messageId
shr
32
).
toInt
(),
messageId
.
toInt
(),
0
)
.
sendAndExpect
()
}
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #${
source.sequenc
eId}: $response"
}
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #${
messag
eId}: $response"
}
}
}
override
suspend
fun
recall
(
groupId
:
Long
,
senderId
:
Long
,
messageId
:
Long
)
{
if
(
senderId
!=
uin
)
{
getGroup
(
groupId
).
checkBotPermissionOperator
()
}
val
sequenceId
=
(
messageId
shr
32
).
toInt
()
override
suspend
fun
_lowLevelRecallGroupMessage
(
groupId
:
Long
,
messageId
:
Long
)
{
network
.
run
{
val
response
:
PbMessageSvc
.
PbMsgWithDraw
.
Response
=
PbMessageSvc
.
PbMsgWithDraw
.
Group
(
bot
.
client
,
groupId
,
sequenceId
,
messageId
.
toInt
())
PbMessageSvc
.
PbMsgWithDraw
.
Group
(
client
,
groupId
,
(
messageId
shr
32
).
toInt
()
,
messageId
.
toInt
())
.
sendAndExpect
()
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #$sequenceId: $response"
}
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #${messageId}: $response"
}
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
View file @
067a9496
...
...
@@ -33,7 +33,7 @@ internal inline class MessageSourceFromServer(
}
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
override
val
sender
Id
:
Long
get
()
=
delegate
.
senderUin
override
val
qq
Id
:
Long
get
()
=
delegate
.
senderUin
override
val
groupId
:
Long
get
()
=
Group
.
calculateGroupCodeByGroupUin
(
delegate
.
toUin
)
override
fun
toString
():
String
=
""
...
...
@@ -52,7 +52,7 @@ internal inline class MessageSourceFromMsg(
}
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
override
val
sender
Id
:
Long
get
()
=
delegate
.
msgHead
.
fromUin
override
val
qq
Id
:
Long
get
()
=
delegate
.
msgHead
.
fromUin
override
val
groupId
:
Long
get
()
=
delegate
.
msgHead
.
groupInfo
?.
groupCode
?:
0
fun
toJceData
():
ImMsgBody
.
SourceMsg
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt
View file @
067a9496
...
...
@@ -76,8 +76,7 @@ internal class PbMessageSvc {
toUin
:
Long
,
messageSequenceId
:
Int
,
// 56639
messageRandom
:
Int
,
// 921878719
time
:
Long
,
messageType
:
Int
=
0
time
:
Long
):
OutgoingPacket
=
buildOutgoingUniPacket
(
client
)
{
writeProtoBuf
(
MsgSvc
.
PbMsgWithDrawReq
.
serializer
(),
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
067a9496
...
...
@@ -272,7 +272,7 @@ internal class MessageSvc {
internal
class
MessageSourceFromSendFriend
(
val
messageRandom
:
Int
,
override
val
time
:
Long
,
override
val
sender
Id
:
Long
,
override
val
qq
Id
:
Long
,
override
val
groupId
:
Long
,
val
sequenceId
:
Int
)
:
MessageSource
{
...
...
@@ -293,7 +293,7 @@ internal class MessageSvc {
internal
class
MessageSourceFromSendGroup
(
val
messageRandom
:
Int
,
override
val
time
:
Long
,
override
val
sender
Id
:
Long
,
override
val
qq
Id
:
Long
,
override
val
groupId
:
Long
// ,
// override val sourceMessage: MessageChain
)
:
MessageSource
{
...
...
@@ -330,7 +330,7 @@ internal class MessageSvc {
):
OutgoingPacket
{
val
source
=
MessageSourceFromSendFriend
(
messageRandom
=
Random
.
nextInt
().
absoluteValue
,
senderId
=
client
.
u
in
,
qqId
=
toU
in
,
time
=
currentTimeSeconds
+
client
.
timeDifference
,
groupId
=
0
,
sequenceId
=
client
.
atomicNextMessageSequenceId
()
...
...
@@ -379,7 +379,7 @@ internal class MessageSvc {
val
source
=
MessageSourceFromSendGroup
(
messageRandom
=
Random
.
nextInt
().
absoluteValue
,
sender
Id
=
client
.
uin
,
qq
Id
=
client
.
uin
,
time
=
currentTimeSeconds
+
client
.
timeDifference
,
groupId
=
groupCode
//,
// sourceMessage = message
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
067a9496
...
...
@@ -21,6 +21,7 @@ import net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.data.FriendInfo
import
net.mamoe.mirai.data.GroupInfo
import
net.mamoe.mirai.data.MemberInfo
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.MessageSource
...
...
@@ -205,30 +206,29 @@ abstract class Bot : CoroutineScope {
// region actions
/**
* 撤回这条消息.
* 撤回这条消息.
可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
*
* [Bot] 撤回自己的消息不需要权限.
* [Bot] 撤回群员的消息需要管理员权限.
*
* @param source 消息源. 可从 [MessageReceipt.source] 获得, 或从消息事件中的 [MessageChain] 获得.
*
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
*/
// source.groupId, source.sequenceId, source.messageUid
*/
abstract
suspend
fun
recall
(
source
:
MessageSource
)
/**
* 撤回一条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
*
* [Bot] 撤回自己的消息不需要权限.
* [Bot] 撤回群员的消息需要管理员权限.
*
* @param senderId 这条消息的发送人. 可以为 [Bot.uin] 或 [Member.id]
* @param messageId 即 [MessageSource.id]
*
* @throws PermissionDeniedException 当 [Bot] 无权限操作时
* @see Bot.recall (扩展函数) 接受参数 [MessageChain]
* @see recall 请优先使用这个函数
* 撤回一条由机器人发送给好友的消息
*/
@MiraiExperimentalAPI
abstract
suspend
fun
_lowLevelRecallFriendMessage
(
friendId
:
Long
,
messageId
:
Long
)
/**
* 撤回一条群里的消息. 可以是机器人发送也可以是其他群员发送.
*/
abstract
suspend
fun
recall
(
groupId
:
Long
,
senderId
:
Long
,
messageId
:
Long
)
@MiraiExperimentalAPI
abstract
suspend
fun
_lowLevelRecallGroupMessage
(
groupId
:
Long
,
messageId
:
Long
)
/**
* 获取图片下载链接
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
View file @
067a9496
...
...
@@ -72,7 +72,7 @@ open class MessageReceipt<C : Contact>(
}
/**
*
撤回这条消息
. [recall] 或 [recallIn] 只能被调用一次.
*
在一段时间后撤回这条消息.
. [recall] 或 [recallIn] 只能被调用一次.
*
* @param millis 延迟时间, 单位为毫秒
*
...
...
@@ -91,7 +91,7 @@ open class MessageReceipt<C : Contact>(
}
/**
* 引用这条消息.
仅群消息能被引用
* 引用这条消息.
*
* @see MessageChain.quote 引用一条消息
*
...
...
@@ -105,7 +105,7 @@ open class MessageReceipt<C : Contact>(
}
/**
* 引用这条消息并回复.
仅群消息能被引用
* 引用这条消息并回复.
*
* @see MessageChain.quote 引用一条消息
*
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
View file @
067a9496
...
...
@@ -13,6 +13,7 @@
package
net.mamoe.mirai.message.data
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.contact.QQ
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
...
...
@@ -49,8 +50,14 @@ interface MessageSource : Message, MessageMetadata {
val
time
:
Long
/**
* 发送人号码
* 与这个消息相关的 [QQ] 的 [QQ.id]
*
* 群消息时为发送人的 id. 好友消息时为消息发送目标好友的 id
*/
val
qqId
:
Long
@Suppress
(
"unused"
)
// TODO: 2020/2/29 0.25: 删除 `MessageSource.senderId`
@Deprecated
(
"使用 qqId. 此 API 将在 0.25 删除"
,
level
=
DeprecationLevel
.
HIDDEN
,
replaceWith
=
ReplaceWith
(
"this.qqId"
))
val
senderId
:
Long
/**
...
...
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