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
6e22272a
Commit
6e22272a
authored
Jan 30, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use delegate
parent
cc853ce0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
28 deletions
+34
-28
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
...ommonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
+12
-24
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+18
-4
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt
...nMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt
+3
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
...e/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
+1
-0
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
View file @
6e22272a
...
...
@@ -26,6 +26,9 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
TODO
(
"not implemented"
)
}
override
val
isOnline
:
Boolean
get
()
=
true
override
suspend
fun
queryProfile
():
Profile
{
TODO
(
"not implemented"
)
}
...
...
@@ -40,11 +43,16 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
}
internal
class
MemberImpl
(
bot
:
QQAndroidBot
,
group
:
Group
,
override
val
coroutineContext
:
CoroutineContext
,
override
val
id
:
Long
)
:
ContactImpl
(),
Member
{
override
val
group
:
Group
by
group
.
unsafeWeakRef
()
internal
class
MemberImpl
(
qq
:
QQImpl
,
group
:
GroupImpl
,
override
val
coroutineContext
:
CoroutineContext
)
:
ContactImpl
(),
Member
,
QQ
by
qq
{
override
val
group
:
GroupImpl
by
group
.
unsafeWeakRef
()
val
qq
:
QQImpl
by
qq
.
unsafeWeakRef
()
override
val
permission
:
MemberPermission
get
()
=
TODO
(
"not implemented"
)
override
val
bot
:
QQAndroidBot
by
bot
.
unsafeWeakRef
()
override
suspend
fun
mute
(
durationSeconds
:
Int
):
Boolean
{
TODO
(
"not implemented"
)
...
...
@@ -54,26 +62,6 @@ internal class MemberImpl(bot: QQAndroidBot, group: Group, override val coroutin
TODO
(
"not implemented"
)
}
override
suspend
fun
queryProfile
():
Profile
{
TODO
(
"not implemented"
)
}
override
suspend
fun
queryPreviousNameList
():
PreviousNameList
{
TODO
(
"not implemented"
)
}
override
suspend
fun
queryRemark
():
FriendNameRemark
{
TODO
(
"not implemented"
)
}
override
suspend
fun
sendMessage
(
message
:
MessageChain
)
{
TODO
(
"not implemented"
)
}
override
suspend
fun
uploadImage
(
image
:
ExternalImage
):
ImageId
{
TODO
(
"not implemented"
)
}
}
...
...
@@ -89,7 +77,7 @@ internal class GroupImpl(bot: QQAndroidBot, override val coroutineContext: Corou
override
val
members
:
ContactList
<
Member
>
=
ContactList
(
LockFreeLinkedList
())
override
fun
getMember
(
id
:
Long
):
Member
=
members
.
delegate
.
filteringGetOrAdd
({
it
.
id
==
id
},
{
MemberImpl
(
bot
as
QQAndroidBot
,
this
,
coroutineContext
,
id
)
})
members
.
delegate
.
filteringGetOrAdd
({
it
.
id
==
id
},
{
MemberImpl
(
bot
.
getQQ
(
id
)
as
QQImpl
,
this
,
coroutineContext
)
})
override
suspend
fun
updateGroupInfo
():
GroupInfo
{
TODO
(
"not implemented"
)
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
6e22272a
...
...
@@ -310,19 +310,33 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
/**
* 发送一个包, 并挂起直到接收到指定的返回包或超时(3000ms)
*/
suspend
fun
<
E
:
Packet
>
OutgoingPacket
.
sendAndExpect
(
timoutMillis
:
Long
=
3000
):
E
{
suspend
fun
<
E
:
Packet
>
OutgoingPacket
.
sendAndExpect
(
timeoutMillis
:
Long
=
3000
,
retry
:
Int
=
1
):
E
{
require
(
timeoutMillis
>
0
)
{
"timeoutMillis must > 0"
}
require
(
retry
>=
0
)
{
"retry must >= 0"
}
val
handler
=
PacketListener
(
commandName
=
commandName
,
sequenceId
=
sequenceId
)
packetListeners
.
addLast
(
handler
)
bot
.
logger
.
info
(
"Send: ${this.commandName}"
)
var
lastException
:
Exception
?
=
null
repeat
(
retry
+
1
)
{
try
{
return
doSendAndReceive
(
timeoutMillis
,
handler
)
}
catch
(
e
:
Exception
)
{
lastException
=
e
}
}
throw
lastException
!!
}
private
suspend
inline
fun
<
E
:
Packet
>
OutgoingPacket
.
doSendAndReceive
(
timeoutMillis
:
Long
=
3000
,
handler
:
PacketListener
):
E
{
channel
.
send
(
delegate
)
return
withTimeoutOrNull
(
timoutMillis
)
{
return
withTimeoutOrNull
(
tim
e
outMillis
)
{
@Suppress
(
"UNCHECKED_CAST"
)
handler
.
await
()
as
E
// 不要 `withTimeout`. timeout 的异常会不知道去哪了.
}
?:
net
.
mamoe
.
mirai
.
qqandroid
.
utils
.
inline
{
packetListeners
.
remove
(
handler
)
error
(
"timeout when sending $
{commandName}
"
)
error
(
"timeout when sending $
commandName
"
)
}
}
...
...
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/ContactImpl.kt
View file @
6e22272a
...
...
@@ -139,6 +139,9 @@ internal class QQImpl @PublishedApi internal constructor(bot: TIMPCBot, override
}
}
override
val
isOnline
:
Boolean
get
()
=
true
override
suspend
fun
queryProfile
():
Profile
=
withTIMPCBot
{
RequestProfileDetailsPacket
(
bot
.
uin
,
id
,
sessionKey
).
sendAndExpect
<
RequestProfileDetailsResponse
>().
profile
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
View file @
6e22272a
...
...
@@ -13,6 +13,7 @@ interface Member : QQ, Contact {
/**
* 所在的群
*/
@WeakRefProperty
val
group
:
Group
/**
...
...
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