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
455f408e
Commit
455f408e
authored
Feb 03, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
f63a077e
e2dd51e0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
64 additions
and
46 deletions
+64
-46
mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt
...n/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+2
-6
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+28
-7
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
+7
-10
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+10
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt
...-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/FriendMessage.kt
...ommonMain/kotlin/net.mamoe.mirai/message/FriendMessage.kt
+0
-11
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
...ommonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
+13
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/InputUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/io/InputUtils.kt
+1
-1
mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt
...n/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt
+1
-1
No files found.
mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt
View file @
455f408e
...
...
@@ -71,7 +71,7 @@ fun Application.mirai() {
routing
{
mirai
(
"/sendFriendMessage"
)
{
// TODO: 2019/11/21 解析图片消息等为 Message
Bot
.
instanceWhose
(
qq
=
param
(
"bot"
)).
get
QQ
(
param
(
"qq"
)).
sendMessage
(
param
<
String
>(
"message"
))
Bot
.
instanceWhose
(
qq
=
param
(
"bot"
)).
get
Friend
(
param
(
"qq"
)).
sendMessage
(
param
<
String
>(
"message"
))
call
.
ok
()
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
455f408e
...
...
@@ -33,12 +33,8 @@ internal abstract class QQAndroidBotBase constructor(
val
selfQQ
:
QQ
by
lazy
{
QQ
(
uin
)
}
override
fun
getQQ
(
id
:
Long
):
QQ
{
return
qqs
.
delegate
.
filteringGetOrAdd
({
it
.
id
==
id
},
{
QQImpl
(
this
as
QQAndroidBot
,
coroutineContext
,
id
)
})
}
fun
getQQOrAdd
(
id
:
Long
):
QQ
{
return
qqs
.
delegate
.
filteringGetOrAdd
({
it
.
id
==
id
},
{
QQImpl
(
this
as
QQAndroidBot
,
coroutineContext
,
id
)
})
override
fun
getFriend
(
id
:
Long
):
QQ
{
return
qqs
.
delegate
[
id
]
}
override
fun
QQ
(
id
:
Long
):
QQ
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
455f408e
...
...
@@ -115,7 +115,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
//val msg = MessageSvc.PbGetMsg(bot.client, MsgSvc.SyncFlag.START, currentTimeSeconds).sendAndExpect<MessageSvc.PbGetMsg.Response>()
//println(msg.contentToString())
bot
.
qqs
.
delegate
.
clear
()
bot
.
groups
.
delegate
.
clear
()
val
startTime
=
currentTimeMillis
try
{
...
...
@@ -134,7 +135,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
totalFriendCount
=
data
.
totalFriendCount
data
.
friendList
.
forEach
{
// atomic add
bot
.
qqs
.
delegate
.
addLast
(
bot
.
get
QQ
(
it
.
friendUin
).
also
{
bot
.
qqs
.
delegate
.
addLast
(
bot
.
get
Friend
(
it
.
friendUin
).
also
{
currentFriendCount
++
})
}
...
...
@@ -475,12 +476,12 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
/**
* 发送一个包, 并挂起直到接收到指定的返回包或超时(3000ms)
*/
suspend
fun
<
E
:
Packet
>
OutgoingPacket
.
sendAndExpect
(
timeoutMillis
:
Long
=
3000
,
retry
:
Int
=
1
):
E
{
suspend
fun
<
E
:
Packet
>
OutgoingPacket
.
sendAndExpect
(
timeoutMillis
:
Long
=
3000
,
retry
:
Int
=
0
):
E
{
require
(
timeoutMillis
>
0
)
{
"timeoutMillis must > 0"
}
require
(
retry
>=
0
)
{
"retry must >= 0"
}
var
lastException
:
Exception
?
=
null
repeat
(
retry
+
1
)
{
if
(
retry
==
0
)
{
val
handler
=
PacketListener
(
commandName
=
commandName
,
sequenceId
=
sequenceId
)
packetListeners
.
addLast
(
handler
)
try
{
...
...
@@ -495,13 +496,33 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
?:
net
.
mamoe
.
mirai
.
qqandroid
.
utils
.
inline
{
error
(
"timeout when receiving response of $commandName"
)
}
}
catch
(
e
:
Exception
)
{
lastException
=
e
}
finally
{
packetListeners
.
remove
(
handler
)
}
}
else
this
.
delegate
.
useBytes
{
data
,
length
->
repeat
(
retry
+
1
)
{
val
handler
=
PacketListener
(
commandName
=
commandName
,
sequenceId
=
sequenceId
)
packetListeners
.
addLast
(
handler
)
try
{
withContext
(
this
@QQAndroidBotNetworkHandler
.
coroutineContext
+
CoroutineName
(
"Packet sender"
))
{
channel
.
send
(
data
,
0
,
length
)
}
bot
.
logger
.
info
(
"Send: ${this.commandName}"
)
return
withTimeoutOrNull
(
timeoutMillis
)
{
@Suppress
(
"UNCHECKED_CAST"
)
handler
.
await
()
as
E
// 不要 `withTimeout`. timeout 的异常会不知道去哪了.
}
?:
net
.
mamoe
.
mirai
.
qqandroid
.
utils
.
inline
{
error
(
"timeout when receiving response of $commandName"
)
}
}
catch
(
e
:
Exception
)
{
lastException
=
e
}
finally
{
packetListeners
.
remove
(
handler
)
}
}
throw
lastException
!!
}
throw
lastException
!!
}
@PublishedApi
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
455f408e
...
...
@@ -123,14 +123,11 @@ internal class MessageSvc {
val
messages
=
resp
.
uinPairMsgs
.
asSequence
().
filterNot
{
it
.
msg
==
null
}.
flatMap
{
it
.
msg
!!
.
asSequence
()
}.
mapNotNull
{
when
(
it
.
msgHead
.
msgType
)
{
166
->
{
FriendMessage
(
bot
,
false
,
// TODO: 2020/1/29 PREVIOUS??
bot
.
getQQ
(
it
.
msgHead
.
fromUin
),
it
.
msgBody
.
richText
.
toMessageChain
()
)
}
166
->
FriendMessage
(
bot
,
bot
.
getFriend
(
it
.
msgHead
.
fromUin
),
it
.
msgBody
.
richText
.
toMessageChain
()
)
else
->
null
}
}.
toMutableList
()
...
...
@@ -176,7 +173,7 @@ internal class MessageSvc {
}
data class
Failed
(
val
errorCode
:
Int
,
val
errorMessage
:
String
)
:
Response
()
{
override
fun
toString
():
String
=
"MessageSvc.PbSendMsg.Response.F
AILED
(errorCode=$errorCode, errorMessage=$errorMessage"
override
fun
toString
():
String
=
"MessageSvc.PbSendMsg.Response.F
ailed
(errorCode=$errorCode, errorMessage=$errorMessage"
}
}
...
...
@@ -224,7 +221,7 @@ internal class MessageSvc {
///return@buildOutgoingUniPacket
writeProtoBuf
(
MsgSvc
.
PbSendMsgReq
.
serializer
(),
MsgSvc
.
PbSendMsgReq
(
routingHead
=
MsgSvc
.
RoutingHead
(
grp
=
MsgSvc
.
Grp
(
groupCode
=
groupCode
)),
// TODO: 2020/1/30 确认这里是 id 还是 internalId
routingHead
=
MsgSvc
.
RoutingHead
(
grp
=
MsgSvc
.
Grp
(
groupCode
=
groupCode
)),
contentHead
=
MsgComm
.
ContentHead
(
pkgNum
=
1
,
divSeq
=
seq
),
msgBody
=
ImMsgBody
.
MsgBody
(
richText
=
ImMsgBody
.
RichText
(
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
455f408e
...
...
@@ -58,9 +58,15 @@ abstract class Bot : CoroutineScope {
abstract
val
qqs
:
ContactList
<
QQ
>
/**
* 获取一个好友对象. 若没有这个好友, 则会抛出异常[NoSuchElementException]
* 获取一个好友对象. 若没有这个好友, 则会抛出异常
[NoSuchElementException]
*/
abstract
fun
getQQ
(
id
:
Long
):
QQ
@Deprecated
(
message
=
"这个函数有歧义. 它获取的是好友, 却名为 getQQ"
,
replaceWith
=
ReplaceWith
(
"getFriend(id)"
))
fun
getQQ
(
id
:
Long
):
QQ
=
getFriend
(
id
)
/**
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
*/
abstract
fun
getFriend
(
id
:
Long
):
QQ
/**
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
...
...
@@ -133,8 +139,8 @@ abstract class Bot : CoroutineScope {
// region extensions
fun
Int
.
qq
():
QQ
=
get
QQ
(
this
.
toLong
())
fun
Long
.
qq
():
QQ
=
get
QQ
(
this
)
fun
Int
.
qq
():
QQ
=
get
Friend
(
this
.
toLong
())
fun
Long
.
qq
():
QQ
=
get
Friend
(
this
)
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt
View file @
455f408e
...
...
@@ -11,7 +11,7 @@ import net.mamoe.mirai.data.Profile
/**
* QQ 对象.
* 注意: 一个 [QQ] 实例并不是独立的, 它属于一个 [Bot].
* 它不能被直接构造. 任何时候都应从 [Bot.get
QQ
] 或事件中获取.
* 它不能被直接构造. 任何时候都应从 [Bot.get
Friend
] 或事件中获取.
*
* 对于同一个 [Bot] 任何一个人的 [QQ] 实例都是单一的.
*
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/FriendMessage.kt
View file @
455f408e
...
...
@@ -8,20 +8,9 @@ import net.mamoe.mirai.utils.MiraiInternalAPI
class
FriendMessage
(
bot
:
Bot
,
/**
* 是否是在这次登录之前的消息, 即消息记录
*/
val
previous
:
Boolean
,
override
val
sender
:
QQ
,
override
val
message
:
MessageChain
)
:
MessagePacket
<
QQ
,
QQ
>(
bot
),
BroadcastControllable
{
/**
* 是否应被自动广播. 此为内部 API
*/
@MiraiInternalAPI
override
val
shouldBroadcast
:
Boolean
get
()
=
!
previous
override
val
subject
:
QQ
get
()
=
sender
override
fun
toString
():
String
=
"FriendMessage(sender=${sender.id}, message=$message)"
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
View file @
455f408e
...
...
@@ -4,7 +4,9 @@ package net.mamoe.mirai.message
import
kotlinx.io.core.ByteReadPacket
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.contact.*
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.data.EventPacket
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.message.data.*
...
...
@@ -71,12 +73,19 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact>(_bot: Bot) :
// region Image download
suspend
inline
fun
Image
.
downloadAsByteArray
():
ByteArray
=
bot
.
run
{
downloadAsByteArray
()
}
suspend
inline
fun
Image
.
download
():
ByteReadPacket
=
bot
.
run
{
download
()
}
// endregion
fun
At
.
qq
():
QQ
=
bot
.
getQQ
(
this
.
target
)
@Deprecated
(
message
=
"这个函数有歧义, 将在不久后删除"
,
replaceWith
=
ReplaceWith
(
"bot.getFriend(this.target)"
))
fun
At
.
qq
():
QQ
=
bot
.
getFriend
(
this
.
target
)
@Deprecated
(
message
=
"这个函数有歧义, 将在不久后删除"
,
replaceWith
=
ReplaceWith
(
"bot.getFriend(this.toLong())"
))
fun
Int
.
qq
():
QQ
=
bot
.
getFriend
(
this
.
coerceAtLeastOrFail
(
0
).
toLong
())
fun
Int
.
qq
():
QQ
=
bot
.
getQQ
(
this
.
coerceAtLeastOrFail
(
0
).
toLong
(
))
fun
Long
.
qq
():
QQ
=
bot
.
get
QQ
(
this
.
coerceAtLeastOrFail
(
0
))
@Deprecated
(
message
=
"这个函数有歧义, 将在不久后删除"
,
replaceWith
=
ReplaceWith
(
"bot.getFriend(this)"
))
fun
Long
.
qq
():
QQ
=
bot
.
get
Friend
(
this
.
coerceAtLeastOrFail
(
0
))
@Deprecated
(
message
=
"这个函数有歧义, 将在不久后删除"
,
replaceWith
=
ReplaceWith
(
"bot.getGroup(this)"
))
fun
Long
.
group
():
Group
=
bot
.
getGroup
(
this
)
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/InputUtils.kt
View file @
455f408e
...
...
@@ -34,7 +34,7 @@ fun ByteReadPacket.transferTo(outputStream: OutputStream) {
}
}
fun
<
R
>
ByteReadPacket
.
useBytes
(
inline
fun
<
R
>
ByteReadPacket
.
useBytes
(
n
:
Int
=
remaining
.
toInt
(),
//not that safe but adequate
block
:
(
data
:
ByteArray
,
length
:
Int
)
->
R
):
R
=
ByteArrayPool
.
useInstance
{
...
...
mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt
View file @
455f408e
...
...
@@ -23,7 +23,7 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
@UseExperimental
(
MiraiInternalAPI
::
class
)
override
fun
getQQs
():
List
<
BlockingQQ
>
=
bot
.
qqs
.
delegate
.
toList
().
map
{
it
.
blocking
()
}
override
fun
getQQ
(
id
:
Long
):
BlockingQQ
=
bot
.
get
QQ
(
id
).
blocking
()
override
fun
getQQ
(
id
:
Long
):
BlockingQQ
=
bot
.
get
Friend
(
id
).
blocking
()
@UseExperimental
(
MiraiInternalAPI
::
class
)
override
fun
getGroups
():
List
<
BlockingGroup
>
=
bot
.
groups
.
delegate
.
toList
().
map
{
it
.
blocking
()
}
...
...
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