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
19bc7b80
Commit
19bc7b80
authored
Apr 04, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `MessageSource.senderId` to `MessageSource.fromId`
parent
039b3d75
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
43 deletions
+45
-43
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
...n/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
+4
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt
...in/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt
+11
-8
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt
...in/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/numbers.kt
...monMain/kotlin/net/mamoe/mirai/qqandroid/utils/numbers.kt
+2
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
...ommonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
+1
-19
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
...Main/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
+13
-9
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
...monMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
+13
-2
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
View file @
19bc7b80
...
@@ -200,7 +200,7 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -200,7 +200,7 @@ internal abstract class QQAndroidBotBase constructor(
group
.
checkBotPermissionOperator
()
group
.
checkBotPermissionOperator
()
MessageRecallEvent
.
GroupRecall
(
MessageRecallEvent
.
GroupRecall
(
this
,
this
,
source
.
sender
Id
,
source
.
from
Id
,
source
.
id
,
source
.
id
,
source
.
time
,
source
.
time
,
null
,
null
,
...
@@ -222,7 +222,7 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -222,7 +222,7 @@ internal abstract class QQAndroidBotBase constructor(
->
network
.
run
{
->
network
.
run
{
PbMessageSvc
.
PbMsgWithDraw
.
createForFriendMessage
(
PbMessageSvc
.
PbMsgWithDraw
.
createForFriendMessage
(
bot
.
client
,
bot
.
client
,
source
.
sender
Id
,
source
.
from
Id
,
source
.
sequenceId
,
source
.
sequenceId
,
source
.
id
,
source
.
id
,
source
.
time
source
.
time
...
@@ -231,6 +231,8 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -231,6 +231,8 @@ internal abstract class QQAndroidBotBase constructor(
else
->
error
(
"stub!"
)
else
->
error
(
"stub!"
)
}
}
// 1001: No message meets the requirements (实际上是没权限, 管理员在尝试撤回群主的消息)
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #${source.id}: $response"
}
check
(
response
is
PbMessageSvc
.
PbMsgWithDraw
.
Response
.
Success
)
{
"Failed to recall message #${source.id}: $response"
}
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt
View file @
19bc7b80
...
@@ -30,7 +30,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.SourceMsg
...
@@ -30,7 +30,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.SourceMsg
import
net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import
net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.OnlinePush
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.OnlinePush
import
net.mamoe.mirai.qqandroid.utils._miraiContentToString
import
net.mamoe.mirai.qqandroid.utils._miraiContentToString
import
net.mamoe.mirai.qqandroid.utils.coerceAtMostOrFail
import
net.mamoe.mirai.qqandroid.utils.io.serialization.loadAs
import
net.mamoe.mirai.qqandroid.utils.io.serialization.loadAs
import
net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
import
net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
...
@@ -146,6 +145,11 @@ internal class MessageSourceFromGroupImpl(
...
@@ -146,6 +145,11 @@ internal class MessageSourceFromGroupImpl(
internal
class
OfflineMessageSourceImpl
(
// from others' quotation
internal
class
OfflineMessageSourceImpl
(
// from others' quotation
val
delegate
:
ImMsgBody
.
SourceMsg
,
override
val
bot
:
Bot
val
delegate
:
ImMsgBody
.
SourceMsg
,
override
val
bot
:
Bot
)
:
OfflineMessageSource
(),
MessageSourceImpl
{
)
:
OfflineMessageSource
(),
MessageSourceImpl
{
init
{
println
(
delegate
.
_miraiContentToString
())
}
private
val
isRecalled
:
AtomicBoolean
=
atomic
(
false
)
private
val
isRecalled
:
AtomicBoolean
=
atomic
(
false
)
override
var
isRecalledOrPlanned
:
Boolean
override
var
isRecalledOrPlanned
:
Boolean
get
()
=
isRecalled
.
value
get
()
=
isRecalled
.
value
...
@@ -164,11 +168,10 @@ internal class OfflineMessageSourceImpl( // from others' quotation
...
@@ -164,11 +168,10 @@ internal class OfflineMessageSourceImpl( // from others' quotation
*/
*/
override
val
id
:
Int
override
val
id
:
Int
get
()
=
delegate
.
pbReserve
.
loadAs
(
SourceMsg
.
ResvAttr
.
serializer
()).
origUids
!!
get
()
=
delegate
.
pbReserve
.
loadAs
(
SourceMsg
.
ResvAttr
.
serializer
()).
origUids
!!
.
toInt
()
.
coerceAtMostOrFail
(
Int
.
MAX_VALUE
.
toLong
()).
toInt
()
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
// override val sourceMessage: MessageChain get() = delegate.toMessageChain()
override
val
sender
Id
:
Long
get
()
=
delegate
.
senderUin
override
val
from
Id
:
Long
get
()
=
delegate
.
senderUin
override
val
targetId
:
Long
get
()
=
Group
.
calculateGroupCodeByGroupUin
(
delegate
.
toUin
)
override
val
targetId
:
Long
get
()
=
Group
.
calculateGroupCodeByGroupUin
(
delegate
.
toUin
)
}
}
...
@@ -196,7 +199,7 @@ internal class MessageSourceToFriendImpl(
...
@@ -196,7 +199,7 @@ internal class MessageSourceToFriendImpl(
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
val
messageUid
:
Long
=
sequenceId
.
toLong
().
shl
(
32
)
or
id
.
toLong
().
and
(
0
xffFFffFF
)
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
sequenceId
),
origSeqs
=
listOf
(
sequenceId
),
senderUin
=
sender
Id
,
senderUin
=
from
Id
,
toUin
=
targetId
,
toUin
=
targetId
,
flag
=
1
,
flag
=
1
,
elems
=
elems
,
elems
=
elems
,
...
@@ -207,7 +210,7 @@ internal class MessageSourceToFriendImpl(
...
@@ -207,7 +210,7 @@ internal class MessageSourceToFriendImpl(
).
toByteArray
(
SourceMsg
.
ResvAttr
.
serializer
()),
).
toByteArray
(
SourceMsg
.
ResvAttr
.
serializer
()),
srcMsg
=
MsgComm
.
Msg
(
srcMsg
=
MsgComm
.
Msg
(
msgHead
=
MsgComm
.
MsgHead
(
msgHead
=
MsgComm
.
MsgHead
(
fromUin
=
sender
Id
,
// qq
fromUin
=
from
Id
,
// qq
toUin
=
targetId
,
// group
toUin
=
targetId
,
// group
msgType
=
9
,
// 82?
msgType
=
9
,
// 82?
c2cCmd
=
11
,
c2cCmd
=
11
,
...
@@ -271,7 +274,7 @@ internal class MessageSourceToGroupImpl(
...
@@ -271,7 +274,7 @@ internal class MessageSourceToGroupImpl(
fun
toJceDataImplForGroup
():
ImMsgBody
.
SourceMsg
{
fun
toJceDataImplForGroup
():
ImMsgBody
.
SourceMsg
{
return
ImMsgBody
.
SourceMsg
(
return
ImMsgBody
.
SourceMsg
(
origSeqs
=
listOf
(
sequenceId
),
origSeqs
=
listOf
(
sequenceId
),
senderUin
=
sender
Id
,
senderUin
=
from
Id
,
toUin
=
Group
.
calculateGroupUinByGroupCode
(
targetId
),
toUin
=
Group
.
calculateGroupUinByGroupCode
(
targetId
),
flag
=
1
,
flag
=
1
,
elems
=
elems
,
elems
=
elems
,
...
@@ -282,7 +285,7 @@ internal class MessageSourceToGroupImpl(
...
@@ -282,7 +285,7 @@ internal class MessageSourceToGroupImpl(
).
toByteArray
(
SourceMsg
.
ResvAttr
.
serializer
()),
).
toByteArray
(
SourceMsg
.
ResvAttr
.
serializer
()),
srcMsg
=
MsgComm
.
Msg
(
srcMsg
=
MsgComm
.
Msg
(
msgHead
=
MsgComm
.
MsgHead
(
msgHead
=
MsgComm
.
MsgHead
(
fromUin
=
sender
Id
,
// qq
fromUin
=
from
Id
,
// qq
toUin
=
Group
.
calculateGroupUinByGroupCode
(
targetId
),
// group
toUin
=
Group
.
calculateGroupUinByGroupCode
(
targetId
),
// group
msgType
=
82
,
// 82?
msgType
=
82
,
// 82?
c2cCmd
=
1
,
c2cCmd
=
1
,
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt
View file @
19bc7b80
...
@@ -241,7 +241,7 @@ internal inline fun <reified R> Iterable<*>.firstIsInstance(): R {
...
@@ -241,7 +241,7 @@ internal inline fun <reified R> Iterable<*>.firstIsInstance(): R {
return
it
return
it
}
}
}
}
throw
NoSuchElementException
(
"Collection contains no element
matching the predicate.
"
)
throw
NoSuchElementException
(
"Collection contains no element
is ${R::class}
"
)
}
}
internal
inline
fun
<
reified
R
>
Iterable
<*>.
firstIsInstanceOrNull
():
R
?
{
internal
inline
fun
<
reified
R
>
Iterable
<*>.
firstIsInstanceOrNull
():
R
?
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/numbers.kt
View file @
19bc7b80
...
@@ -38,10 +38,10 @@ internal fun Long.coerceAtLeastOrFail(min: Long): Long {
...
@@ -38,10 +38,10 @@ internal fun Long.coerceAtLeastOrFail(min: Long): Long {
*/
*/
@PublishedApi
@PublishedApi
internal
fun
Int
.
coerceAtMostOrFail
(
max
:
Int
):
Int
=
internal
fun
Int
.
coerceAtMostOrFail
(
max
:
Int
):
Int
=
if
(
this
>=
max
)
error
(
"value is greater than its expected maximum value $max"
)
if
(
this
>=
max
)
error
(
"value
$this
is greater than its expected maximum value $max"
)
else
this
else
this
@PublishedApi
@PublishedApi
internal
fun
Long
.
coerceAtMostOrFail
(
max
:
Long
):
Long
=
internal
fun
Long
.
coerceAtMostOrFail
(
max
:
Long
):
Long
=
if
(
this
>=
max
)
error
(
"value is greater than its expected maximum value $max"
)
if
(
this
>=
max
)
error
(
"value
$this
is greater than its expected maximum value $max"
)
else
this
else
this
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
View file @
19bc7b80
...
@@ -34,8 +34,6 @@ import net.mamoe.mirai.event.subscribingGetOrNull
...
@@ -34,8 +34,6 @@ import net.mamoe.mirai.event.subscribingGetOrNull
import
net.mamoe.mirai.event.whileSelectMessages
import
net.mamoe.mirai.event.whileSelectMessages
import
net.mamoe.mirai.message.data.*
import
net.mamoe.mirai.message.data.*
import
net.mamoe.mirai.qqandroid.network.Packet
import
net.mamoe.mirai.qqandroid.network.Packet
import
net.mamoe.mirai.recall
import
net.mamoe.mirai.recallIn
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.*
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
...
@@ -124,23 +122,7 @@ abstract class MessagePacketBase<out TSender : QQ, out TSubject : Contact> : Pac
...
@@ -124,23 +122,7 @@ abstract class MessagePacketBase<out TSender : QQ, out TSubject : Contact> : Pac
// endregion
// endregion
// region 撤回
// region 撤回
suspend
inline
fun
MessageChain
.
recall
()
=
bot
.
recall
(
this
)
suspend
inline
fun
MessageSource
.
recall
()
=
bot
.
recall
(
this
)
suspend
inline
fun
QuoteReply
.
recall
()
=
bot
.
recall
(
this
.
source
)
inline
fun
MessageChain
.
recallIn
(
millis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
)
=
bot
.
recallIn
(
this
,
millis
,
coroutineContext
)
inline
fun
MessageSource
.
recallIn
(
millis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
)
=
bot
.
recallIn
(
this
,
millis
,
coroutineContext
)
inline
fun
QuoteReply
.
recallIn
(
millis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
)
=
bot
.
recallIn
(
this
.
source
,
millis
,
coroutineContext
)
// endregion
// endregion
// region 上传图片
// region 上传图片
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
View file @
19bc7b80
...
@@ -63,7 +63,7 @@ sealed class MessageSource : Message, MessageMetadata {
...
@@ -63,7 +63,7 @@ sealed class MessageSource : Message, MessageMetadata {
/**
/**
* 发送人. 可能为机器人自己, 好友的 id, 或群 id
* 发送人. 可能为机器人自己, 好友的 id, 或群 id
*/
*/
abstract
val
sender
Id
:
Long
abstract
val
from
Id
:
Long
/**
/**
* 发送目标. 可能为机器人自己, 好友的 id, 或群 id
* 发送目标. 可能为机器人自己, 好友的 id, 或群 id
...
@@ -126,7 +126,7 @@ sealed class OnlineMessageSource : MessageSource() {
...
@@ -126,7 +126,7 @@ sealed class OnlineMessageSource : MessageSource() {
abstract
override
val
sender
:
Bot
abstract
override
val
sender
:
Bot
abstract
override
val
target
:
Contact
abstract
override
val
target
:
Contact
final
override
val
sender
Id
:
Long
get
()
=
sender
.
id
final
override
val
from
Id
:
Long
get
()
=
sender
.
id
final
override
val
targetId
:
Long
get
()
=
target
.
id
final
override
val
targetId
:
Long
get
()
=
target
.
id
abstract
class
ToFriend
:
Outgoing
()
{
abstract
class
ToFriend
:
Outgoing
()
{
...
@@ -155,7 +155,7 @@ sealed class OnlineMessageSource : MessageSource() {
...
@@ -155,7 +155,7 @@ sealed class OnlineMessageSource : MessageSource() {
abstract
override
val
sender
:
QQ
// out QQ
abstract
override
val
sender
:
QQ
// out QQ
abstract
override
val
target
:
Bot
abstract
override
val
target
:
Bot
final
override
val
sender
Id
:
Long
get
()
=
sender
.
id
final
override
val
from
Id
:
Long
get
()
=
sender
.
id
final
override
val
targetId
:
Long
get
()
=
target
.
id
final
override
val
targetId
:
Long
get
()
=
target
.
id
abstract
class
FromFriend
:
Incoming
()
{
abstract
class
FromFriend
:
Incoming
()
{
...
@@ -190,13 +190,10 @@ fun OnlineMessageSource.quote(): QuoteReply {
...
@@ -190,13 +190,10 @@ fun OnlineMessageSource.quote(): QuoteReply {
*/
*/
fun
MessageChain
.
quote
():
QuoteReply
{
fun
MessageChain
.
quote
():
QuoteReply
{
@OptIn
(
MiraiInternalAPI
::
class
)
@OptIn
(
MiraiInternalAPI
::
class
)
return
QuoteReply
(
this
.
source
)
return
QuoteReply
(
this
.
source
as
?
OnlineMessageSource
?:
error
(
"only online messages can be quoted"
)
)
}
}
/**
suspend
inline
fun
MessageSource
.
recall
()
=
bot
.
recall
(
this
)
* 撤回这条消息
*/
suspend
inline
fun
OnlineMessageSource
.
recall
()
=
bot
.
recall
(
this
)
/**
/**
* 撤回这条消息
* 撤回这条消息
...
@@ -237,4 +234,11 @@ inline val MessageChain.id: Int
...
@@ -237,4 +234,11 @@ inline val MessageChain.id: Int
*/
*/
@
get
:
JvmSynthetic
@
get
:
JvmSynthetic
inline
val
MessageChain
.
source
:
MessageSource
inline
val
MessageChain
.
source
:
MessageSource
get
()
=
this
[
MessageSource
]
get
()
=
this
[
MessageSource
]
\ No newline at end of file
suspend
inline
fun
MessageChain
.
recall
()
=
this
.
source
.
recall
()
inline
fun
MessageChain
.
recallIn
(
millis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
):
Job
=
source
.
recallIn
(
millis
,
coroutineContext
)
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
View file @
19bc7b80
...
@@ -9,11 +9,15 @@
...
@@ -9,11 +9,15 @@
@
file
:
JvmMultifileClass
@
file
:
JvmMultifileClass
@
file
:
JvmName
(
"MessageUtils"
)
@
file
:
JvmName
(
"MessageUtils"
)
@
file
:
Suppress
(
"NOTHING_TO_INLINE"
)
package
net.mamoe.mirai.message.data
package
net.mamoe.mirai.message.data
import
kotlinx.coroutines.Job
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
...
@@ -27,9 +31,16 @@ import kotlin.jvm.JvmName
...
@@ -27,9 +31,16 @@ import kotlin.jvm.JvmName
* @see MessageSource 获取更多信息
* @see MessageSource 获取更多信息
*/
*/
@SinceMirai
(
"0.33.0"
)
@SinceMirai
(
"0.33.0"
)
class
QuoteReply
(
val
source
:
MessageSource
)
:
Message
,
MessageMetadata
{
class
QuoteReply
(
val
source
:
Online
MessageSource
)
:
Message
,
MessageMetadata
{
// TODO: 2020/4/4 Metadata or Content?
// TODO: 2020/4/4 Metadata or Content?
companion
object
Key
:
Message
.
Key
<
QuoteReply
>
companion
object
Key
:
Message
.
Key
<
QuoteReply
>
override
fun
toString
():
String
=
"[mirai:quote]"
override
fun
toString
():
String
=
"[mirai:quote]"
}
}
\ No newline at end of file
suspend
inline
fun
QuoteReply
.
recall
()
=
this
.
source
.
recall
()
inline
fun
QuoteReply
.
recallIn
(
millis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
):
Job
=
this
.
source
.
recallIn
(
millis
,
coroutineContext
)
\ 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