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
c15651b9
Commit
c15651b9
authored
Nov 13, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust property name and visibility
parent
a42fbe47
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
18 deletions
+49
-18
mirai-core/build.gradle.kts
mirai-core/build.gradle.kts
+3
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+22
-7
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotSession.kt
...c/commonMain/kotlin/net.mamoe.mirai/network/BotSession.kt
+12
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/ActionPacketHandler.kt
...mirai/network/protocol/tim/handler/ActionPacketHandler.kt
+3
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/PacketHandler.kt
...mamoe.mirai/network/protocol/tim/handler/PacketHandler.kt
+8
-2
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
...o-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
+1
-1
No files found.
mirai-core/build.gradle.kts
View file @
c15651b9
...
...
@@ -93,8 +93,11 @@ kotlin {
}
sourceSets
[
"jvmTest"
].
apply
{
dependencies
{
}
kotlin
.
outputDir
=
file
(
"build/classes/kotlin/jvm/test"
)
kotlin
.
setSrcDirs
(
listOf
(
"src/$name/kotlin"
))
}
sourceSets
.
all
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
c15651b9
...
...
@@ -2,7 +2,7 @@
package
net.mamoe.mirai
import
kotlinx.coroutines.
Job
import
kotlinx.coroutines.
*
import
kotlinx.coroutines.sync.Mutex
import
kotlinx.coroutines.sync.withLock
import
net.mamoe.mirai.Bot.ContactSystem
...
...
@@ -19,6 +19,7 @@ import net.mamoe.mirai.utils.BotConfiguration
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.internal.coerceAtLeastOrFail
import
kotlin.coroutines.CoroutineContext
import
kotlin.jvm.JvmOverloads
data class
BotAccount
(
...
...
@@ -56,7 +57,9 @@ data class BotAccount(
* @author NaturalHG
* @see Contact
*/
class
Bot
(
val
account
:
BotAccount
,
val
logger
:
MiraiLogger
)
{
class
Bot
(
val
account
:
BotAccount
,
val
logger
:
MiraiLogger
)
:
CoroutineScope
{
override
val
coroutineContext
:
CoroutineContext
=
SupervisorJob
()
constructor
(
qq
:
UInt
,
password
:
String
)
:
this
(
BotAccount
(
qq
,
password
))
constructor
(
account
:
BotAccount
)
:
this
(
account
,
DefaultLogger
(
"Bot("
+
account
.
id
+
")"
))
...
...
@@ -65,7 +68,9 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) {
var
network
:
BotNetworkHandler
<
*
>
=
TIMBotNetworkHandler
(
this
)
init
{
instances
.
add
(
this
)
launch
{
addInstance
(
this
@Bot
)
}
}
override
fun
toString
():
String
=
"Bot(${account.id})"
...
...
@@ -150,13 +155,23 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) {
suspend
inline
fun
GroupInternalId
.
group
():
Group
=
getGroup
(
this
)
suspend
fun
close
()
{
this
.
network
.
close
()
this
.
contacts
.
groups
.
clear
()
this
.
contacts
.
qqs
.
clear
()
network
.
close
()
this
.
coroutineContext
.
cancelChildren
()
contacts
.
groups
.
clear
()
contacts
.
qqs
.
clear
()
}
companion
object
{
val
instances
:
MutableList
<
Bot
>
=
mutableListOf
()
@Suppress
(
"ObjectPropertyName"
)
private
val
_instances
:
MutableList
<
Bot
>
=
mutableListOf
()
private
val
instanceLock
:
Mutex
=
Mutex
()
val
instances
:
List
<
Bot
>
get
()
=
_instances
internal
suspend
fun
addInstance
(
bot
:
Bot
)
=
instanceLock
.
withLock
{
_instances
+=
bot
}
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotSession.kt
View file @
c15651b9
...
...
@@ -25,6 +25,7 @@ import net.mamoe.mirai.utils.getGTK
import
net.mamoe.mirai.utils.internal.PositiveNumbers
import
net.mamoe.mirai.utils.internal.coerceAtLeastOrFail
import
kotlin.coroutines.coroutineContext
import
kotlin.jvm.JvmField
/**
* 构造 [BotSession] 的捷径
...
...
@@ -57,17 +58,23 @@ class BotSession(
/**
* Web api 使用
*/
var
sKey
:
String
=
""
internal
set
(
value
)
{
val
sKey
:
String
get
()
=
_sKey
@JvmField
@Suppress
(
"PropertyName"
)
internal
var
_sKey
:
String
=
""
set
(
value
)
{
field
=
value
gtk
=
getGTK
(
value
)
_
gtk
=
getGTK
(
value
)
}
/**
* Web api 使用
*/
var
gtk
:
Int
=
0
private
set
val
gtk
:
Int
get
()
=
_gtk
@JvmField
private
var
_gtk
:
Int
=
0
/**
* 发送一个数据包, 并期待接受一个特定的 [ServerPacket][P].
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/ActionPacketHandler.kt
View file @
c15651b9
...
...
@@ -30,7 +30,7 @@ class ActionPacketHandler(session: BotSession) : PacketHandler(session) {
override
suspend
fun
onPacketReceived
(
packet
:
Packet
):
Unit
=
with
(
session
)
{
when
(
packet
)
{
is
SKey
->
{
sKey
=
packet
.
delegate
_
sKey
=
packet
.
delegate
cookies
=
"uin=o$qqAccount;skey=$sKey;"
...
...
@@ -55,14 +55,14 @@ class ActionPacketHandler(session: BotSession) : PacketHandler(session) {
private
suspend
fun
requestSKey
()
=
with
(
session
)
{
withContext
(
NetworkScope
.
coroutineContext
)
{
socket
.
sendPacket
(
RequestSKeyPacket
()
)
RequestSKeyPacket
().
send
(
)
}
}
suspend
fun
requestAccountInfo
()
=
with
(
session
)
{
withContext
(
NetworkScope
.
coroutineContext
)
{
socket
.
sendPacket
(
RequestAccountInfoPacket
(
qqAccount
,
sessionKey
)
)
RequestAccountInfoPacket
(
qqAccount
,
sessionKey
).
send
(
)
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/PacketHandler.kt
View file @
c15651b9
package
net.mamoe.mirai.network.protocol.tim.handler
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.network.BotSession
import
net.mamoe.mirai.network.protocol.tim.packet.Packet
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
/**
* 数据包(接受/发送)处理器
*/
abstract
class
PacketHandler
(
val
session
:
BotSession
)
{
val
session
:
BotSession
)
:
CoroutineScope
{
override
val
coroutineContext
:
CoroutineContext
get
()
=
EmptyCoroutineContext
abstract
suspend
fun
onPacketReceived
(
packet
:
Packet
)
interface
Key
<
T
:
PacketHandler
>
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
View file @
c15651b9
...
...
@@ -35,7 +35,7 @@ class GentleImage {
lateinit
var
contact
:
Contact
//
Deferred<Image?> 将导致 kotlin 内部错误
//
`Deferred<Image?>` causes a runtime ClassCastException
val
image
:
Deferred
<
Image
>
by
lazy
{
GlobalScope
.
async
{
//delay((Math.random() * 5000L).toLong())
...
...
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