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
8c69eefc
Commit
8c69eefc
authored
Feb 03, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use groupCode as primary key
parent
d9e58052
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
70 additions
and
111 deletions
+70
-111
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
...ommonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+5
-5
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+33
-40
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
+2
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt
...protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/list/FriendListPacket.kt
...qandroid/network/protocol/packet/list/FriendListPacket.kt
+2
-6
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+5
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
.../src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
...re/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
+5
-12
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
...nMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
+3
-1
mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/contact/GroupIdConversionsKtTest.kt
...otlin/net/mamoe/mirai/contact/GroupIdConversionsKtTest.kt
+0
-14
mirai-demos/mirai-demo-1/src/main/java/demo/subscribe/SubscribeSamples.kt
...i-demo-1/src/main/java/demo/subscribe/SubscribeSamples.kt
+3
-1
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
...rai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
+0
-4
mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingBot.java
...-japt/src/main/java/net/mamoe/mirai/japt/BlockingBot.java
+4
-8
mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt
...n/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt
+1
-3
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
View file @
8c69eefc
...
@@ -77,7 +77,7 @@ internal class MemberImpl(
...
@@ -77,7 +77,7 @@ internal class MemberImpl(
internal
class
GroupImpl
(
internal
class
GroupImpl
(
bot
:
QQAndroidBot
,
override
val
coroutineContext
:
CoroutineContext
,
bot
:
QQAndroidBot
,
override
val
coroutineContext
:
CoroutineContext
,
override
val
id
:
Long
,
override
val
id
:
Long
,
override
val
groupCode
:
Long
,
val
uin
:
Long
,
override
var
name
:
String
,
override
var
name
:
String
,
override
var
announcement
:
String
,
override
var
announcement
:
String
,
override
var
members
:
ContactList
<
Member
>
override
var
members
:
ContactList
<
Member
>
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
8c69eefc
...
@@ -51,13 +51,13 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -51,13 +51,13 @@ internal abstract class QQAndroidBotBase constructor(
override
val
groups
:
ContactList
<
Group
>
=
ContactList
(
LockFreeLinkedList
())
override
val
groups
:
ContactList
<
Group
>
=
ContactList
(
LockFreeLinkedList
())
override
fun
getGroupByID
(
id
:
Long
):
Group
{
fun
getGroupByUin
(
uin
:
Long
):
Group
{
return
groups
.
delegate
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"Can not found group with ID=${id
}"
)
return
groups
.
delegate
.
filteringGetOrNull
{
(
it
as
GroupImpl
).
uin
==
uin
}
?:
throw
NoSuchElementException
(
"Can not found group with ID=${uin
}"
)
}
}
override
fun
getGroup
ByGroupCode
(
groupCode
:
Long
):
Group
{
override
fun
getGroup
(
id
:
Long
):
Group
{
return
groups
.
delegate
.
filteringGetOrNull
{
it
.
groupCode
==
groupCode
}
return
groups
.
delegate
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"Can not found group with GroupCode=${
groupCode
}"
)
?:
throw
NoSuchElementException
(
"Can not found group with GroupCode=${
id
}"
)
}
}
override
suspend
fun
addFriend
(
id
:
Long
,
message
:
String
?,
remark
:
String
?):
AddFriendResult
{
override
suspend
fun
addFriend
(
id
:
Long
,
message
:
String
?,
remark
:
String
?):
AddFriendResult
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
8c69eefc
...
@@ -31,7 +31,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
...
@@ -31,7 +31,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.*
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.Volatile
import
kotlin.jvm.Volatile
@Suppress
(
"MemberVisibilityCanBePrivate"
)
@Suppress
(
"MemberVisibilityCanBePrivate"
)
...
@@ -103,13 +102,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -103,13 +102,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
}
}
}
// println("d2key=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
// println("d2key=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
StatSvc
.
Register
(
bot
.
client
).
sendAndExpect
<
StatSvc
.
Register
.
Response
>(
6000
)
StatSvc
.
Register
(
bot
.
client
).
sendAndExpect
<
StatSvc
.
Register
.
Response
>(
6000
)
// it's slow
}
}
override
suspend
fun
init
()
{
override
suspend
fun
init
()
{
MessageSvc
.
PbGetMsg
(
bot
.
client
,
MsgSvc
.
SyncFlag
.
START
,
currentTimeSeconds
).
sendWithoutExpect
()
this
@QQAndroidBotNetworkHandler
.
subscribeAlways
<
ForceOfflineEvent
>
{
this
@QQAndroidBotNetworkHandler
.
subscribeAlways
<
ForceOfflineEvent
>
{
if
(
this
@QQAndroidBotNetworkHandler
.
bot
==
this
.
bot
)
{
if
(
this
@QQAndroidBotNetworkHandler
.
bot
==
this
.
bot
)
{
close
()
close
()
...
@@ -159,26 +156,26 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -159,26 +156,26 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
val
troopData
=
FriendList
.
GetTroopListSimplify
(
val
troopData
=
FriendList
.
GetTroopListSimplify
(
bot
.
client
bot
.
client
).
sendAndExpect
<
FriendList
.
GetTroopListSimplify
.
Response
>(
timeoutMillis
=
1000
)
).
sendAndExpect
<
FriendList
.
GetTroopListSimplify
.
Response
>(
timeoutMillis
=
1000
)
println
(
"获取到群数量"
+
troopData
.
groups
.
size
)
//
println("获取到群数量" + troopData.groups.size)
val
toGet
:
MutableMap
<
GroupImpl
,
ContactList
<
Member
>>
=
mutableMapOf
()
val
toGet
:
MutableMap
<
GroupImpl
,
ContactList
<
Member
>>
=
mutableMapOf
()
troopData
.
groups
.
forEach
{
troopData
.
groups
.
forEach
{
val
contactList
=
ContactList
(
LockFreeLinkedList
<
Member
>())
val
contactList
=
ContactList
(
LockFreeLinkedList
<
Member
>())
val
group
=
val
group
=
GroupImpl
(
GroupImpl
(
bot
,
bot
=
bot
,
this
.
coroutineContext
,
coroutineContext
=
this
.
coroutineContext
,
i
t
.
groupUin
,
i
d
=
it
.
groupCode
,
it
.
groupCode
,
uin
=
it
.
groupUin
,
it
.
groupName
,
name
=
it
.
groupName
,
it
.
groupMemo
,
announcement
=
it
.
groupMemo
,
contactList
members
=
contactList
)
)
group
.
owner
=
group
.
owner
=
MemberImpl
(
MemberImpl
(
bot
.
QQ
(
it
.
dwGroupOwnerUin
)
as
QQImpl
,
qq
=
bot
.
QQ
(
it
.
dwGroupOwnerUin
)
as
QQImpl
,
group
,
group
=
group
,
group
.
coroutineContext
,
coroutineContext
=
group
.
coroutineContext
,
MemberPermission
.
OWNER
permission
=
MemberPermission
.
OWNER
)
)
toGet
[
group
]
=
contactList
toGet
[
group
]
=
contactList
bot
.
groups
.
delegate
.
addLast
(
group
)
bot
.
groups
.
delegate
.
addLast
(
group
)
...
@@ -186,10 +183,10 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -186,10 +183,10 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
toGet
.
forEach
{
toGet
.
forEach
{
try
{
try
{
getTroopMemberList
(
it
.
key
,
it
.
value
,
it
.
key
.
owner
.
id
)
getTroopMemberList
(
it
.
key
,
it
.
value
,
it
.
key
.
owner
.
id
)
groupInfo
[
it
.
key
.
groupCode
]
=
it
.
value
.
size
groupInfo
[
it
.
key
.
uin
]
=
it
.
value
.
size
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
groupInfo
[
it
.
key
.
groupCode
]
=
-
1
groupInfo
[
it
.
key
.
uin
]
=
-
1
bot
.
logger
.
info
(
"群${it.key.
groupCode
}的列表拉取失败, 将采用动态加入"
)
bot
.
logger
.
info
(
"群${it.key.
uin
}的列表拉取失败, 将采用动态加入"
)
}
}
//delay(200)
//delay(200)
}
}
...
@@ -221,36 +218,32 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -221,36 +218,32 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
}
}
}
bot
.
logger
.
info
(
"====================Mirai Bot List初始化完毕===================="
)
bot
.
logger
.
info
(
"====================Mirai Bot List初始化完毕===================="
)
MessageSvc
.
PbGetMsg
(
bot
.
client
,
MsgSvc
.
SyncFlag
.
START
,
currentTimeSeconds
).
sendWithoutExpect
()
}
}
suspend
fun
getTroopMemberList
(
group
:
GroupImpl
,
list
:
ContactList
<
Member
>,
owner
:
Long
):
ContactList
<
Member
>
{
suspend
fun
getTroopMemberList
(
group
:
GroupImpl
,
list
:
ContactList
<
Member
>,
owner
:
Long
):
ContactList
<
Member
>
{
bot
.
logger
.
info
(
"开始获取群[${group.
groupCode
}]成员列表"
)
bot
.
logger
.
info
(
"开始获取群[${group.
uin
}]成员列表"
)
var
size
=
0
var
size
=
0
var
nextUin
=
0L
var
nextUin
=
0L
while
(
true
)
{
while
(
true
)
{
val
data
=
FriendList
.
GetTroopMemberList
(
val
data
=
FriendList
.
GetTroopMemberList
(
bot
.
client
,
client
=
bot
.
client
,
group
.
id
,
targetGroupUin
=
group
.
uin
,
group
.
groupCode
,
targetGroupCode
=
group
.
id
,
nextUin
nextUin
=
nextUin
).
sendAndExpect
<
FriendList
.
GetTroopMemberList
.
Response
>(
timeoutMillis
=
3000
)
).
sendAndExpect
<
FriendList
.
GetTroopMemberList
.
Response
>(
timeoutMillis
=
3000
)
data
.
members
.
forEach
{
data
.
members
.
forEach
{
if
(
it
.
memberUin
!=
bot
.
uin
)
{
if
(
it
.
memberUin
!=
bot
.
uin
)
{
list
.
delegate
.
addLast
(
list
.
delegate
.
addLast
(
MemberImpl
(
MemberImpl
(
bot
.
QQ
(
it
.
memberUin
)
as
QQImpl
,
qq
=
bot
.
QQ
(
it
.
memberUin
)
as
QQImpl
,
group
,
group
=
group
,
EmptyCoroutineContext
,
coroutineContext
=
group
.
coroutineContext
,
when
{
permission
=
when
{
it
.
memberUin
==
owner
->
{
it
.
memberUin
==
owner
->
MemberPermission
.
OWNER
MemberPermission
.
OWNER
it
.
dwFlag
==
1L
->
MemberPermission
.
ADMINISTRATOR
}
else
->
MemberPermission
.
MEMBER
it
.
dwFlag
==
1L
->
{
MemberPermission
.
ADMINISTRATOR
}
else
->
{
MemberPermission
.
MEMBER
}
}
}
)
)
)
)
...
@@ -261,9 +254,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
...
@@ -261,9 +254,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
if
(
nextUin
==
0L
)
{
if
(
nextUin
==
0L
)
{
break
break
}
}
println
(
"已获取群[${group.groupCode
}]成员列表前"
+
size
+
"个成员"
)
//println("已获取群[${group.uin
}]成员列表前" + size + "个成员")
}
}
println
(
"群[${group.groupCode
}]成员全部获取完成, 共${list.size}个成员"
)
//println("群[${group.uin
}]成员全部获取完成, 共${list.size}个成员")
return
list
return
list
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
8c69eefc
...
@@ -214,7 +214,7 @@ internal class MessageSvc {
...
@@ -214,7 +214,7 @@ internal class MessageSvc {
*/
*/
fun
ToGroup
(
fun
ToGroup
(
client
:
QQAndroidClient
,
client
:
QQAndroidClient
,
group
Id
:
Long
,
group
Code
:
Long
,
message
:
MessageChain
message
:
MessageChain
):
OutgoingPacket
=
buildOutgoingUniPacket
(
client
)
{
):
OutgoingPacket
=
buildOutgoingUniPacket
(
client
)
{
...
@@ -224,7 +224,7 @@ internal class MessageSvc {
...
@@ -224,7 +224,7 @@ internal class MessageSvc {
///return@buildOutgoingUniPacket
///return@buildOutgoingUniPacket
writeProtoBuf
(
writeProtoBuf
(
MsgSvc
.
PbSendMsgReq
.
serializer
(),
MsgSvc
.
PbSendMsgReq
(
MsgSvc
.
PbSendMsgReq
.
serializer
(),
MsgSvc
.
PbSendMsgReq
(
routingHead
=
MsgSvc
.
RoutingHead
(
grp
=
MsgSvc
.
Grp
(
groupCode
=
group
Id
)),
// TODO: 2020/1/30 确认这里是 id 还是 internalId
routingHead
=
MsgSvc
.
RoutingHead
(
grp
=
MsgSvc
.
Grp
(
groupCode
=
group
Code
)),
// TODO: 2020/1/30 确认这里是 id 还是 internalId
contentHead
=
MsgComm
.
ContentHead
(
pkgNum
=
1
,
divSeq
=
seq
),
contentHead
=
MsgComm
.
ContentHead
(
pkgNum
=
1
,
divSeq
=
seq
),
msgBody
=
ImMsgBody
.
MsgBody
(
msgBody
=
ImMsgBody
.
MsgBody
(
richText
=
ImMsgBody
.
RichText
(
richText
=
ImMsgBody
.
RichText
(
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt
View file @
8c69eefc
...
@@ -38,7 +38,7 @@ internal class OnlinePush {
...
@@ -38,7 +38,7 @@ internal class OnlinePush {
return
GroupMessageOrNull
(
null
)
return
GroupMessageOrNull
(
null
)
}
}
val
group
=
bot
.
getGroup
ByGroupCode
(
pbPushMsg
.
msg
.
msgHead
.
groupInfo
!!
.
groupCode
)
val
group
=
bot
.
getGroup
(
pbPushMsg
.
msg
.
msgHead
.
groupInfo
!!
.
groupCode
)
val
flags
=
extraInfo
?.
flags
?:
0
val
flags
=
extraInfo
?.
flags
?:
0
return
GroupMessageOrNull
(
return
GroupMessageOrNull
(
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/list/FriendListPacket.kt
View file @
8c69eefc
...
@@ -14,11 +14,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
...
@@ -14,11 +14,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import
net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
import
net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
import
net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory
import
net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory
import
net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
import
net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
import
net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList.GetFriendGroupList.decode
import
net.mamoe.mirai.utils.io.debugIfFail
import
net.mamoe.mirai.utils.io.debugIfFail
import
net.mamoe.mirai.utils.io.debugPrintThis
import
net.mamoe.mirai.utils.io.debugPrintln
import
net.mamoe.mirai.utils.io.discardExact
internal
class
FriendList
{
internal
class
FriendList
{
...
@@ -35,7 +31,7 @@ internal class FriendList {
...
@@ -35,7 +31,7 @@ internal class FriendList {
operator
fun
invoke
(
operator
fun
invoke
(
client
:
QQAndroidClient
,
client
:
QQAndroidClient
,
targetGroup
Id
:
Long
,
targetGroup
Uin
:
Long
,
targetGroupCode
:
Long
,
targetGroupCode
:
Long
,
nextUin
:
Long
=
0
nextUin
:
Long
=
0
):
OutgoingPacket
{
):
OutgoingPacket
{
...
@@ -53,7 +49,7 @@ internal class FriendList {
...
@@ -53,7 +49,7 @@ internal class FriendList {
GetTroopMemberListReq
(
GetTroopMemberListReq
(
uin
=
client
.
uin
,
uin
=
client
.
uin
,
groupCode
=
targetGroupCode
,
groupCode
=
targetGroupCode
,
groupUin
=
targetGroup
Id
,
groupUin
=
targetGroup
Uin
,
nextUin
=
nextUin
,
nextUin
=
nextUin
,
reqType
=
0
,
reqType
=
0
,
version
=
2
version
=
2
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
8c69eefc
...
@@ -21,7 +21,7 @@ import net.mamoe.mirai.utils.WeakRef
...
@@ -21,7 +21,7 @@ import net.mamoe.mirai.utils.WeakRef
import
net.mamoe.mirai.utils.io.transferTo
import
net.mamoe.mirai.utils.io.transferTo
/**
/**
*
Mirai 的机器人
. 一个机器人实例登录一个 QQ 账号.
*
机器人对象
. 一个机器人实例登录一个 QQ 账号.
* Mirai 为多账号设计, 可同时维护多个机器人.
* Mirai 为多账号设计, 可同时维护多个机器人.
*
*
* @see Contact
* @see Contact
...
@@ -78,12 +78,7 @@ abstract class Bot : CoroutineScope {
...
@@ -78,12 +78,7 @@ abstract class Bot : CoroutineScope {
/**
/**
* 获取一个机器人加入的群. 若没有这个群, 则会抛出异常 [NoSuchElementException]
* 获取一个机器人加入的群. 若没有这个群, 则会抛出异常 [NoSuchElementException]
*/
*/
abstract
fun
getGroupByID
(
id
:
Long
):
Group
abstract
fun
getGroup
(
id
:
Long
):
Group
/**
* 获取一个机器人加入的群. 若没有这个群, 则会抛出异常 [NoSuchElementException]
*/
abstract
fun
getGroupByGroupCode
(
groupCode
:
Long
):
Group
// 目前还不能构造群对象. 这将在以后支持
// 目前还不能构造群对象. 这将在以后支持
...
@@ -131,8 +126,10 @@ abstract class Bot : CoroutineScope {
...
@@ -131,8 +126,10 @@ abstract class Bot : CoroutineScope {
/**
/**
* 关闭这个 [Bot], 停止一切相关活动. 不可重新登录.
* 关闭这个 [Bot], 停止一切相关活动. 不可重新登录.
*
* @param cause 原因. 为 null 时视为正常关闭, 非 null 时视为异常关闭
*/
*/
abstract
fun
dispose
(
throwable
:
Throwable
?
)
abstract
fun
close
(
cause
:
Throwable
?
=
null
)
// region extensions
// region extensions
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
View file @
8c69eefc
...
@@ -133,15 +133,15 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
...
@@ -133,15 +133,15 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
// endregion
// endregion
@UseExperimental
(
MiraiInternalAPI
::
class
)
@UseExperimental
(
MiraiInternalAPI
::
class
)
override
fun
dispose
(
throwabl
e
:
Throwable
?)
{
override
fun
close
(
caus
e
:
Throwable
?)
{
if
(
throwabl
e
==
null
)
{
if
(
caus
e
==
null
)
{
network
.
close
()
network
.
close
()
this
.
botJob
.
complete
()
this
.
botJob
.
complete
()
groups
.
delegate
.
clear
()
groups
.
delegate
.
clear
()
qqs
.
delegate
.
clear
()
qqs
.
delegate
.
clear
()
}
else
{
}
else
{
network
.
close
(
throwabl
e
)
network
.
close
(
caus
e
)
this
.
botJob
.
completeExceptionally
(
throwabl
e
)
this
.
botJob
.
completeExceptionally
(
caus
e
)
groups
.
delegate
.
clear
()
groups
.
delegate
.
clear
()
qqs
.
delegate
.
clear
()
qqs
.
delegate
.
clear
()
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
View file @
8c69eefc
...
@@ -25,7 +25,7 @@ interface Contact : CoroutineScope {
...
@@ -25,7 +25,7 @@ interface Contact : CoroutineScope {
val
bot
:
Bot
// weak ref
val
bot
:
Bot
// weak ref
/**
/**
* 可以是 QQ 号码或者群号码
[GroupId]
.
* 可以是 QQ 号码或者群号码.
*/
*/
val
id
:
Long
val
id
:
Long
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
View file @
8c69eefc
...
@@ -7,32 +7,25 @@ import kotlinx.coroutines.CoroutineScope
...
@@ -7,32 +7,25 @@ import kotlinx.coroutines.CoroutineScope
/**
/**
* 群. 在 QQ Android 中叫做 "Troop"
* 群. 在 QQ Android 中叫做 "Troop"
*
* Group UIN 与 Group Code 并不是同一个值.
* Group Code是在客户端显示的code
* Group Uin是QQ内部的群ID[在Mirai中则为 id]
* 但是有的时候 两个是相同的value
* 在网络调用层 Code与Uin会被混用
* 但在开发层 你应该只关注Group Code
*/
*/
interface
Group
:
Contact
,
CoroutineScope
{
interface
Group
:
Contact
,
CoroutineScope
{
/**
* 同为 groupCode, 用户看到的群号码.
*/
override
val
id
:
Long
val
groupCode
:
Long
/**
/**
* 群主 (同步事件更新)
* 群主 (同步事件更新)
* 进行 [updateGroupInfo] 时将会更新这个值.
*/
*/
val
owner
:
Member
val
owner
:
Member
/**
/**
* 群名称 (同步事件更新)
* 群名称 (同步事件更新)
* 进行 [updateGroupInfo] 时将会更新这个值.
*/
*/
val
name
:
String
val
name
:
String
/**
/**
* 入群公告, 没有时为空字符串. (同步事件更新)
* 入群公告, 没有时为空字符串. (同步事件更新)
* 进行 [updateGroupInfo] 时将会更新这个值.
*/
*/
val
announcement
:
String
val
announcement
:
String
...
@@ -45,7 +38,7 @@ interface Group : Contact, CoroutineScope {
...
@@ -45,7 +38,7 @@ interface Group : Contact, CoroutineScope {
/**
/**
* 获取群成员实例. 若此
ID
的成员不存在, 则会抛出 [kotlin.NoSuchElementException]
* 获取群成员实例. 若此
id
的成员不存在, 则会抛出 [kotlin.NoSuchElementException]
*/
*/
operator
fun
get
(
id
:
Long
):
Member
operator
fun
get
(
id
:
Long
):
Member
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt
View file @
8c69eefc
...
@@ -63,6 +63,8 @@ abstract class BotNetworkHandler : CoroutineScope {
...
@@ -63,6 +63,8 @@ abstract class BotNetworkHandler : CoroutineScope {
/**
/**
* 关闭网络接口, 停止所有有关协程和任务
* 关闭网络接口, 停止所有有关协程和任务
*
* @param cause 关闭的原因. null 时视为正常关闭, 非 null 时视为异常关闭.
*/
*/
open
fun
close
(
cause
:
Throwable
?
=
null
)
{
open
fun
close
(
cause
:
Throwable
?
=
null
)
{
if
(
supervisor
.
isActive
)
{
if
(
supervisor
.
isActive
)
{
...
@@ -75,7 +77,7 @@ abstract class BotNetworkHandler : CoroutineScope {
...
@@ -75,7 +77,7 @@ abstract class BotNetworkHandler : CoroutineScope {
}
}
}
}
suspend
fun
BotNetworkHandler
.
closeAndJoin
(
cause
:
Throwable
?
=
null
){
suspend
fun
BotNetworkHandler
.
closeAndJoin
(
cause
:
Throwable
?
=
null
)
{
this
.
close
(
cause
)
this
.
close
(
cause
)
this
.
supervisor
.
join
()
this
.
supervisor
.
join
()
}
}
\ No newline at end of file
mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/contact/GroupIdConversionsKtTest.kt
deleted
100644 → 0
View file @
d9e58052
package
net.mamoe.mirai.contact
import
net.mamoe.mirai.test.shouldBeEqualTo
import
org.junit.Test
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
internal
class
GroupIdConversionsKtTest
{
@Test
fun
checkToInternalId
()
{
GroupId
(
221056495
).
toInternalId
().
value
shouldBeEqualTo
4111056495
// 61 056495
//4111 056495
}
}
\ No newline at end of file
mirai-demos/mirai-demo-1/src/main/java/demo/subscribe/SubscribeSamples.kt
View file @
8c69eefc
...
@@ -217,7 +217,9 @@ suspend fun directlySubscribe(bot: Bot) {
...
@@ -217,7 +217,9 @@ suspend fun directlySubscribe(bot: Bot) {
"复读"
in
message
->
sender
.
sendMessage
(
message
)
"复读"
in
message
->
sender
.
sendMessage
(
message
)
"发群消息"
in
message
->
580266363
.
group
().
sendMessage
(
message
.
toString
().
substringAfter
(
"发群消息"
))
"发群消息"
in
message
->
{
bot
.
getGroup
(
580266363
).
sendMessage
(
message
.
toString
().
substringAfter
(
"发群消息"
))
}
}
}
}
}
}
}
\ No newline at end of file
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
View file @
8c69eefc
...
@@ -50,10 +50,6 @@ suspend fun main() {
...
@@ -50,10 +50,6 @@ suspend fun main() {
// 订阅来自这个 bot 的群消息事件
// 订阅来自这个 bot 的群消息事件
bot
.
subscribeGroupMessages
{
bot
.
subscribeGroupMessages
{
"群资料"
reply
{
group
.
updateGroupInfo
().
toString
().
reply
()
}
startsWith
(
"mute"
)
{
startsWith
(
"mute"
)
{
val
at
:
At
by
message
val
at
:
At
by
message
at
.
member
().
mute
(
30
)
at
.
member
().
mute
(
30
)
...
...
mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingBot.java
View file @
8c69eefc
...
@@ -5,7 +5,6 @@ import net.mamoe.mirai.BotAccount;
...
@@ -5,7 +5,6 @@ import net.mamoe.mirai.BotAccount;
import
net.mamoe.mirai.data.AddFriendResult
;
import
net.mamoe.mirai.data.AddFriendResult
;
import
net.mamoe.mirai.message.data.Image
;
import
net.mamoe.mirai.message.data.Image
;
import
net.mamoe.mirai.network.BotNetworkHandler
;
import
net.mamoe.mirai.network.BotNetworkHandler
;
import
net.mamoe.mirai.utils.GroupNotFoundException
;
import
net.mamoe.mirai.utils.MiraiInternalAPI
;
import
net.mamoe.mirai.utils.MiraiInternalAPI
;
import
net.mamoe.mirai.utils.MiraiLogger
;
import
net.mamoe.mirai.utils.MiraiLogger
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
...
@@ -15,6 +14,9 @@ import java.util.List;
...
@@ -15,6 +14,9 @@ import java.util.List;
@SuppressWarnings
(
"unused"
)
@SuppressWarnings
(
"unused"
)
public
interface
BlockingBot
{
public
interface
BlockingBot
{
// TODO: 2020/2/3 需要更新
/**
/**
* 账号信息
* 账号信息
*/
*/
...
@@ -55,17 +57,11 @@ public interface BlockingBot {
...
@@ -55,17 +57,11 @@ public interface BlockingBot {
/**
/**
* 获取缓存的群对象. 若没有对应的缓存, 则会线程安全地创建一个.
* 获取缓存的群对象. 若没有对应的缓存, 则会线程安全地创建一个.
* 若 {@code id} 无效, 将会抛出 {@link
GroupNotFound
Exception}
* 若 {@code id} 无效, 将会抛出 {@link
java.util.NoSuchElement
Exception}
*/
*/
@NotNull
@NotNull
BlockingGroup
getGroup
(
long
id
);
BlockingGroup
getGroup
(
long
id
);
/**
* 获取缓存的群对象. 若没有对应的缓存, 则会线程安全地创建一个.
* 若 {@code internalId} 无效, 将会抛出 {@link GroupNotFoundException}
*/
@NotNull
BlockingGroup
getGroupByInternalId
(
long
internalId
);
// endregion
// endregion
...
...
mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt
View file @
8c69eefc
...
@@ -4,7 +4,6 @@ import kotlinx.coroutines.runBlocking
...
@@ -4,7 +4,6 @@ import kotlinx.coroutines.runBlocking
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.ByteReadPacket
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.BotAccount
import
net.mamoe.mirai.BotAccount
import
net.mamoe.mirai.contact.GroupInternalId
import
net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.data.AddFriendResult
import
net.mamoe.mirai.japt.BlockingBot
import
net.mamoe.mirai.japt.BlockingBot
import
net.mamoe.mirai.japt.BlockingGroup
import
net.mamoe.mirai.japt.BlockingGroup
...
@@ -29,12 +28,11 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
...
@@ -29,12 +28,11 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
override
fun
getGroups
():
List
<
BlockingGroup
>
=
bot
.
groups
.
delegate
.
toList
().
map
{
it
.
blocking
()
}
override
fun
getGroups
():
List
<
BlockingGroup
>
=
bot
.
groups
.
delegate
.
toList
().
map
{
it
.
blocking
()
}
override
fun
getGroup
(
id
:
Long
):
BlockingGroup
=
runBlocking
{
bot
.
getGroup
(
id
).
blocking
()
}
override
fun
getGroup
(
id
:
Long
):
BlockingGroup
=
runBlocking
{
bot
.
getGroup
(
id
).
blocking
()
}
override
fun
getGroupByInternalId
(
internalId
:
Long
):
BlockingGroup
=
runBlocking
{
bot
.
getGroup
(
GroupInternalId
(
internalId
)).
blocking
()
}
override
fun
getNetwork
():
BotNetworkHandler
=
bot
.
network
override
fun
getNetwork
():
BotNetworkHandler
=
bot
.
network
override
fun
login
()
=
runBlocking
{
bot
.
login
()
}
override
fun
login
()
=
runBlocking
{
bot
.
login
()
}
override
fun
downloadAsByteArray
(
image
:
Image
):
ByteArray
=
bot
.
run
{
runBlocking
{
image
.
downloadAsByteArray
()
}
}
override
fun
downloadAsByteArray
(
image
:
Image
):
ByteArray
=
bot
.
run
{
runBlocking
{
image
.
downloadAsByteArray
()
}
}
override
fun
download
(
image
:
Image
):
ByteReadPacket
=
bot
.
run
{
runBlocking
{
image
.
download
()
}
}
override
fun
download
(
image
:
Image
):
ByteReadPacket
=
bot
.
run
{
runBlocking
{
image
.
download
()
}
}
override
fun
addFriend
(
id
:
Long
,
message
:
String
?,
remark
:
String
?):
AddFriendResult
=
runBlocking
{
bot
.
addFriend
(
id
,
message
,
remark
)
}
override
fun
addFriend
(
id
:
Long
,
message
:
String
?,
remark
:
String
?):
AddFriendResult
=
runBlocking
{
bot
.
addFriend
(
id
,
message
,
remark
)
}
override
fun
approveFriendAddRequest
(
id
:
Long
,
remark
:
String
?)
=
runBlocking
{
bot
.
approveFriendAddRequest
(
id
,
remark
)
}
override
fun
approveFriendAddRequest
(
id
:
Long
,
remark
:
String
?)
=
runBlocking
{
bot
.
approveFriendAddRequest
(
id
,
remark
)
}
override
fun
dispose
(
throwable
:
Throwable
?)
=
bot
.
disp
ose
(
throwable
)
override
fun
dispose
(
throwable
:
Throwable
?)
=
bot
.
cl
ose
(
throwable
)
}
}
\ 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