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
848cc1b5
Commit
848cc1b5
authored
Dec 06, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add java-accessible functions in ContactSystem; Expose network as a `val`
parent
492918ff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
8 deletions
+31
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+30
-7
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt
...i-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt
+1
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
848cc1b5
...
...
@@ -17,6 +17,8 @@ import net.mamoe.mirai.utils.BotConfiguration
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.internal.PositiveNumbers
import
net.mamoe.mirai.utils.internal.coerceAtLeastOrFail
import
net.mamoe.mirai.utils.io.logStacktrace
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.coroutineContext
...
...
@@ -86,7 +88,9 @@ class Bot(val account: BotAccount, val logger: MiraiLogger, context: CoroutineCo
val
contacts
=
ContactSystem
()
lateinit
var
network
:
BotNetworkHandler
<
*
>
val
network
:
BotNetworkHandler
<
*
>
get
()
=
_network
private
lateinit
var
_network
:
BotNetworkHandler
<
*
>
init
{
launch
{
...
...
@@ -127,15 +131,15 @@ class Bot(val account: BotAccount, val logger: MiraiLogger, context: CoroutineCo
logger
.
info
(
"BotAccount: ${qqAccount.toLong()}"
)
logger
.
info
(
"Initializing BotNetworkHandler"
)
try
{
if
(
::
network
.
isInitialized
)
{
network
.
close
(
cause
)
if
(
::
_
network
.
isInitialized
)
{
_
network
.
close
(
cause
)
}
}
catch
(
e
:
Exception
)
{
logger
.
error
(
"Cannot close network handler"
,
e
)
}
network
=
TIMBotNetworkHandler
(
this
@Bot
.
coroutineContext
+
configuration
,
this
@Bot
)
_
network
=
TIMBotNetworkHandler
(
this
@Bot
.
coroutineContext
+
configuration
,
this
@Bot
)
return
network
.
login
()
return
_
network
.
login
()
}
/**
...
...
@@ -178,12 +182,22 @@ class Bot(val account: BotAccount, val logger: MiraiLogger, context: CoroutineCo
* 注: 这个方法是线程安全的
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
@JvmSynthetic
suspend
fun
getQQ
(
id
:
UInt
):
QQ
=
if
(
_qqs
.
containsKey
(
id
))
_qqs
[
id
]
!!
else
qqsLock
.
withLock
{
_qqs
.
getOrPut
(
id
)
{
QQImpl
(
bot
,
id
,
coroutineContext
)
}
}
// NO INLINE!! to help Java
@UseExperimental
(
MiraiInternalAPI
::
class
)
suspend
fun
getQQ
(
id
:
Long
):
QQ
=
id
.
coerceAtLeastOrFail
(
0
).
toUInt
().
let
{
if
(
_qqs
.
containsKey
(
it
))
_qqs
[
it
]
!!
else
qqsLock
.
withLock
{
_qqs
.
getOrPut
(
it
)
{
QQImpl
(
bot
,
it
,
coroutineContext
)
}
}
}
/**
* 获取缓存的群对象. 若没有对应的缓存, 则会创建一个.
*
...
...
@@ -203,11 +217,20 @@ class Bot(val account: BotAccount, val logger: MiraiLogger, context: CoroutineCo
_groups
.
getOrPut
(
it
)
{
Group
(
bot
,
id
,
coroutineContext
)
}
}
}
// NO INLINE!! to help Java
@UseExperimental
(
MiraiInternalAPI
::
class
)
suspend
fun
getGroup
(
@PositiveNumbers
id
:
Long
):
Group
=
id
.
coerceAtLeastOrFail
(
0
).
toUInt
().
let
{
if
(
_groups
.
containsKey
(
it
))
_groups
[
it
]
!!
else
groupsLock
.
withLock
{
_groups
.
getOrPut
(
it
)
{
Group
(
bot
,
GroupId
(
it
),
coroutineContext
)
}
}
}
}
@UseExperimental
(
MiraiInternalAPI
::
class
)
suspend
fun
close
()
{
network
.
close
()
fun
close
()
{
_
network
.
close
()
this
.
coroutineContext
.
cancelChildren
()
contacts
.
_groups
.
clear
()
contacts
.
_qqs
.
clear
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt
View file @
848cc1b5
...
...
@@ -25,7 +25,7 @@ import kotlin.jvm.JvmOverloads
*/
//Contacts
suspend
inline
fun
Bot
.
getQQ
(
@PositiveNumbers
number
:
Long
):
QQ
=
this
.
contacts
.
getQQ
(
number
.
coerceAtLeastOrFail
(
0
).
toUInt
()
)
suspend
inline
fun
Bot
.
getQQ
(
@PositiveNumbers
number
:
Long
):
QQ
=
this
.
contacts
.
getQQ
(
number
)
suspend
inline
fun
Bot
.
getQQ
(
number
:
UInt
):
QQ
=
this
.
contacts
.
getQQ
(
number
)
...
...
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