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
cadbd7ff
Commit
cadbd7ff
authored
Mar 03, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deprecate `Bot.qq`, `Bot.get`, `Bot.contains`
parent
28c05302
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
15 deletions
+74
-15
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+8
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+9
-2
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/Bot.kt
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/Bot.kt
+18
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+20
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
+1
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Bot.kt
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Bot.kt
+18
-4
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
cadbd7ff
...
...
@@ -57,7 +57,14 @@ internal abstract class QQAndroidBotBase constructor(
)
internal
var
firstLoginSucceed
:
Boolean
=
false
override
val
uin
:
Long
get
()
=
client
.
uin
override
val
qqs
:
ContactList
<
QQ
>
=
ContactList
(
LockFreeLinkedList
())
@Deprecated
(
"use friends instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.friends"
)
)
override
val
qqs
:
ContactList
<
QQ
>
get
()
=
friends
override
val
friends
:
ContactList
<
QQ
>
=
ContactList
(
LockFreeLinkedList
())
override
val
selfQQ
:
QQ
by
lazy
{
QQ
(
object
:
FriendInfo
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
cadbd7ff
...
...
@@ -183,7 +183,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
check
(
bot
.
isActive
)
{
"bot is dead therefore network can't init"
}
check
(
this
@QQAndroidBotNetworkHandler
.
isActive
)
{
"network is dead therefore can't init"
}
bot
.
qq
s
.
delegate
.
clear
()
bot
.
friend
s
.
delegate
.
clear
()
bot
.
groups
.
delegate
.
clear
()
val
friendListJob
=
launch
{
...
...
@@ -211,7 +211,14 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
totalFriendCount
=
data
.
totalFriendCount
data
.
friendList
.
forEach
{
// atomic add
bot
.
qqs
.
delegate
.
addLast
(
QQImpl
(
bot
,
bot
.
coroutineContext
,
it
.
friendUin
,
FriendInfoImpl
(
it
))).
also
{
bot
.
friends
.
delegate
.
addLast
(
QQImpl
(
bot
,
bot
.
coroutineContext
,
it
.
friendUin
,
FriendInfoImpl
(
it
)
)
).
also
{
currentFriendCount
++
}
}
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/Bot.kt
View file @
cadbd7ff
...
...
@@ -86,14 +86,28 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
/**
* 机器人的好友列表. 它将与服务器同步更新
*/
@Deprecated
(
"use friends instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.friends"
)
)
actual
abstract
val
qqs
:
ContactList
<
QQ
>
/**
* 机器人的好友列表. 它将与服务器同步更新
*/
actual
abstract
val
friends
:
ContactList
<
QQ
>
/**
* 获取一个好友或一个群.
* 在一些情况下这可能会造成歧义. 请考虑后使用.
*/
@Deprecated
(
"use getFriend or getGroup instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.qqs.getOrNull(id) ?: this.groups.getOrNull(id) ?: throw NoSuchElementException(\"contact id \$id\")"
)
)
actual
operator
fun
get
(
id
:
Long
):
Contact
{
return
this
.
qq
s
.
getOrNull
(
id
)
?:
this
.
groups
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"contact id $id"
)
return
this
.
friend
s
.
getOrNull
(
id
)
?:
this
.
groups
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"contact id $id"
)
}
/**
...
...
@@ -101,7 +115,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
* 在一些情况下这可能会造成歧义. 请考虑后使用.
*/
actual
operator
fun
contains
(
id
:
Long
):
Boolean
{
return
this
.
qq
s
.
contains
(
id
)
||
this
.
groups
.
contains
(
id
)
return
this
.
friend
s
.
contains
(
id
)
||
this
.
groups
.
contains
(
id
)
}
/**
...
...
@@ -109,7 +123,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/
actual
fun
getFriend
(
id
:
Long
):
QQ
{
if
(
id
==
uin
)
return
selfQQ
return
qq
s
.
delegate
.
getOrNull
(
id
)
return
friend
s
.
delegate
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"No such friend $id for bot ${this.uin}"
)
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
cadbd7ff
...
...
@@ -95,22 +95,39 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
// region contacts
/**
* [QQ.id] 与 [Bot.uin] 相同的 [QQ] 实例
*/
abstract
val
selfQQ
:
QQ
/**
* 机器人的好友列表. 它将与服务器同步更新
*/
@Deprecated
(
"use friends instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.friends"
)
)
abstract
val
qqs
:
ContactList
<
QQ
>
/**
* 机器人的好友列表. 它将与服务器同步更新
*/
abstract
val
friends
:
ContactList
<
QQ
>
/**
* 获取一个好友或一个群.
* 在一些情况下这可能会造成歧义. 请考虑后使用.
*/
@Deprecated
(
"use getFriend or getGroup instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.qqs.getOrNull(id) ?: this.groups.getOrNull(id) ?: throw NoSuchElementException(\"contact id \$id\")"
)
)
operator
fun
get
(
id
:
Long
):
Contact
/**
* 判断是否有这个 id 的好友或群.
* 在一些情况下这可能会造成歧义. 请考虑后使用.
*/
operator
fun
contains
(
id
:
Long
):
Boolean
...
...
@@ -294,10 +311,10 @@ suspend inline fun Bot.closeAndJoin(cause: Throwable? = null) {
coroutineContext
[
Job
]
?.
join
()
}
inline
fun
Bot
.
containsFriend
(
id
:
Long
):
Boolean
=
this
.
qq
s
.
contains
(
id
)
inline
fun
Bot
.
containsFriend
(
id
:
Long
):
Boolean
=
this
.
friend
s
.
contains
(
id
)
inline
fun
Bot
.
containsGroup
(
id
:
Long
):
Boolean
=
this
.
groups
.
contains
(
id
)
inline
fun
Bot
.
getFriendOrNull
(
id
:
Long
):
QQ
?
=
this
.
qq
s
.
getOrNull
(
id
)
inline
fun
Bot
.
getFriendOrNull
(
id
:
Long
):
QQ
?
=
this
.
friend
s
.
getOrNull
(
id
)
inline
fun
Bot
.
getGroupOrNull
(
id
:
Long
):
Group
?
=
this
.
groups
.
getOrNull
(
id
)
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
View file @
cadbd7ff
...
...
@@ -189,7 +189,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
}
}
groups
.
delegate
.
clear
()
qq
s
.
delegate
.
clear
()
friend
s
.
delegate
.
clear
()
instances
.
removeIf
{
it
.
get
()
?.
uin
==
this
.
uin
}
}
}
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Bot.kt
View file @
cadbd7ff
...
...
@@ -96,14 +96,28 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
/**
* 机器人的好友列表. 它将与服务器同步更新
*/
@Deprecated
(
"use friends instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.friends"
)
)
actual
abstract
val
qqs
:
ContactList
<
QQ
>
/**
* 机器人的好友列表. 它将与服务器同步更新
*/
actual
abstract
val
friends
:
ContactList
<
QQ
>
/**
* 获取一个好友或一个群.
* 在一些情况下这可能会造成歧义. 请考虑后使用.
*/
@Deprecated
(
"use getFriend or getGroup instead"
,
level
=
DeprecationLevel
.
ERROR
,
replaceWith
=
ReplaceWith
(
"this.qqs.getOrNull(id) ?: this.groups.getOrNull(id) ?: throw NoSuchElementException(\"contact id \$id\")"
)
)
actual
operator
fun
get
(
id
:
Long
):
Contact
{
return
this
.
qq
s
.
getOrNull
(
id
)
?:
this
.
groups
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"contact id $id"
)
return
this
.
friend
s
.
getOrNull
(
id
)
?:
this
.
groups
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"contact id $id"
)
}
/**
...
...
@@ -111,7 +125,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
* 在一些情况下这可能会造成歧义. 请考虑后使用.
*/
actual
operator
fun
contains
(
id
:
Long
):
Boolean
{
return
this
.
qq
s
.
contains
(
id
)
||
this
.
groups
.
contains
(
id
)
return
this
.
friend
s
.
contains
(
id
)
||
this
.
groups
.
contains
(
id
)
}
/**
...
...
@@ -119,7 +133,7 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/
actual
fun
getFriend
(
id
:
Long
):
QQ
{
if
(
id
==
uin
)
return
selfQQ
return
qq
s
.
delegate
.
getOrNull
(
id
)
return
friend
s
.
delegate
.
getOrNull
(
id
)
?:
throw
NoSuchElementException
(
"No such friend $id for bot ${this.uin}"
)
}
...
...
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