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
27b44563
Commit
27b44563
authored
Feb 26, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
703f0cc0
48a2d9ca
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
96 additions
and
30 deletions
+96
-30
gradle.properties
gradle.properties
+1
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
...ain/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
+3
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt
...-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt
+8
-8
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/StateCode.kt
...rc/main/kotlin/net/mamoe/mirai/api/http/data/StateCode.kt
+9
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt
...otlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt
+9
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/DTO.kt
...c/main/kotlin/net/mamoe/mirai/api/http/data/common/DTO.kt
+10
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/exceptions.kt
...c/main/kotlin/net/mamoe/mirai/api/http/data/exceptions.kt
+9
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
...c/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
+5
-7
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/MiraiJson.kt
...rc/main/kotlin/net/mamoe/mirai/api/http/util/MiraiJson.kt
+0
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
.../mirai/qqandroid/network/protocol/packet/PacketFactory.kt
+0
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+0
-6
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/linear.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/event/linear.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
...monMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
+41
-0
No files found.
gradle.properties
View file @
27b44563
...
@@ -3,7 +3,7 @@ kotlin.code.style=official
...
@@ -3,7 +3,7 @@ kotlin.code.style=official
# config
# config
mirai_version
=
0.22.0
mirai_version
=
0.22.0
mirai_japt_version
=
1.1.0
mirai_japt_version
=
1.1.0
mirai_console_version
=
0.
1.1
mirai_console_version
=
0.
2.0
kotlin.incremental.multiplatform
=
true
kotlin.incremental.multiplatform
=
true
kotlin.parallel.tasks.in.project
=
true
kotlin.parallel.tasks.in.project
=
true
# kotlin
# kotlin
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
View file @
27b44563
...
@@ -20,12 +20,14 @@ import kotlinx.coroutines.CoroutineScope
...
@@ -20,12 +20,14 @@ import kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
net.mamoe.mirai.api.http.route.mirai
import
net.mamoe.mirai.api.http.route.mirai
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
org.slf4j.helpers.NOPLoggerFactory
import
org.slf4j.helpers.NOPLoggerFactory
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
object
MiraiHttpAPIServer
:
CoroutineScope
{
object
MiraiHttpAPIServer
:
CoroutineScope
{
var
logger
=
DefaultLogger
(
"Mirai HTTP API"
)
var
logger
:
MiraiLogger
=
DefaultLogger
(
"Mirai HTTP API"
)
override
val
coroutineContext
:
CoroutineContext
=
override
val
coroutineContext
:
CoroutineContext
=
CoroutineExceptionHandler
{
_
,
throwable
->
logger
.
error
(
throwable
)
}
CoroutineExceptionHandler
{
_
,
throwable
->
logger
.
error
(
throwable
)
}
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt
View file @
27b44563
...
@@ -74,17 +74,17 @@ internal object SessionManager {
...
@@ -74,17 +74,17 @@ internal object SessionManager {
/**
/**
* @author NaturalHG
* 管理不同 Client 与 Mirai HTTP 的会话
* 这个用于管理不同Client与Mirai HTTP的会话
*
*
* [Session]均为内部操作用类
* [Session] 均为内部操作用类
* 需使用[SessionManager]
* @see [SessionManager]
* @author NaturalHG
*/
*/
abstract
class
Session
internal
constructor
(
internal
abstract
class
Session
internal
constructor
(
coroutineContext
:
CoroutineContext
,
coroutineContext
:
CoroutineContext
,
val
key
:
String
=
generateSessionKey
()
val
key
:
String
=
generateSessionKey
()
)
:
CoroutineScope
{
)
:
CoroutineScope
{
val
supervisorJob
=
SupervisorJob
(
coroutineContext
[
Job
])
private
val
supervisorJob
=
SupervisorJob
(
coroutineContext
[
Job
])
final
override
val
coroutineContext
:
CoroutineContext
=
supervisorJob
+
coroutineContext
final
override
val
coroutineContext
:
CoroutineContext
=
supervisorJob
+
coroutineContext
internal
open
fun
close
()
{
internal
open
fun
close
()
{
...
@@ -98,13 +98,13 @@ abstract class Session internal constructor(
...
@@ -98,13 +98,13 @@ abstract class Session internal constructor(
*
*
* TempSession在建立180s内没有转变为[AuthedSession]应被清除
* TempSession在建立180s内没有转变为[AuthedSession]应被清除
*/
*/
class
TempSession
internal
constructor
(
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
)
internal
class
TempSession
internal
constructor
(
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
)
/**
/**
* 任何[TempSession]认证后转化为一个[AuthedSession]
* 任何[TempSession]认证后转化为一个[AuthedSession]
* 在这一步[AuthedSession]应该已经有assigned的bot
* 在这一步[AuthedSession]应该已经有assigned的bot
*/
*/
class
AuthedSession
internal
constructor
(
val
bot
:
Bot
,
originKey
:
String
,
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
,
originKey
)
{
internal
class
AuthedSession
internal
constructor
(
val
bot
:
Bot
,
originKey
:
String
,
coroutineContext
:
CoroutineContext
)
:
Session
(
coroutineContext
,
originKey
)
{
companion
object
{
companion
object
{
const
val
CHECK_TIME
=
1800L
// 1800s aka 30min
const
val
CHECK_TIME
=
1800L
// 1800s aka 30min
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/StateCode.kt
View file @
27b44563
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.api.http.data
package
net.mamoe.mirai.api.http.data
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Serializable
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt
View file @
27b44563
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.api.http.data.common
package
net.mamoe.mirai.api.http.data.common
import
kotlinx.serialization.SerialName
import
kotlinx.serialization.SerialName
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Serializable
import
net.mamoe.mirai.contact.MemberPermission
import
net.mamoe.mirai.contact.MemberPermission
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.event.events.*
import
net.mamoe.mirai.event.events.*
import
net.mamoe.mirai.message.MessagePacket
import
net.mamoe.mirai.message.MessagePacket
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/DTO.kt
View file @
27b44563
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.api.http.data.common
package
net.mamoe.mirai.api.http.data.common
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Serializable
...
@@ -13,7 +22,7 @@ data class AuthDTO(val authKey: String) : DTO
...
@@ -13,7 +22,7 @@ data class AuthDTO(val authKey: String) : DTO
abstract
class
VerifyDTO
:
DTO
{
abstract
class
VerifyDTO
:
DTO
{
abstract
val
sessionKey
:
String
abstract
val
sessionKey
:
String
@Transient
@Transient
lateinit
var
session
:
AuthedSession
// 反序列化验证成功后传入
internal
lateinit
var
session
:
AuthedSession
// 反序列化验证成功后传入
}
}
@Serializable
@Serializable
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/
Exception
.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/
exceptions
.kt
View file @
27b44563
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.api.http.data
package
net.mamoe.mirai.api.http.data
/**
/**
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
View file @
27b44563
...
@@ -37,11 +37,7 @@ import net.mamoe.mirai.api.http.data.common.VerifyDTO
...
@@ -37,11 +37,7 @@ import net.mamoe.mirai.api.http.data.common.VerifyDTO
import
net.mamoe.mirai.api.http.util.jsonParseOrNull
import
net.mamoe.mirai.api.http.util.jsonParseOrNull
import
net.mamoe.mirai.api.http.util.toJson
import
net.mamoe.mirai.api.http.util.toJson
import
net.mamoe.mirai.contact.PermissionDeniedException
import
net.mamoe.mirai.contact.PermissionDeniedException
import
org.slf4j.Logger
import
org.slf4j.helpers.NOPLogger
import
org.slf4j.helpers.NOPLoggerFactory
import
org.slf4j.helpers.NOPLoggerFactory
import
org.slf4j.impl.SimpleLogger
import
org.slf4j.impl.SimpleLoggerFactory
fun
Application
.
mirai
()
{
fun
Application
.
mirai
()
{
install
(
DefaultHeaders
)
install
(
DefaultHeaders
)
...
@@ -86,7 +82,7 @@ internal fun Route.miraiGet(
...
@@ -86,7 +82,7 @@ internal fun Route.miraiGet(
val
sessionKey
=
call
.
parameters
[
"sessionKey"
]
?:
throw
IllegalParamException
(
"参数格式错误"
)
val
sessionKey
=
call
.
parameters
[
"sessionKey"
]
?:
throw
IllegalParamException
(
"参数格式错误"
)
if
(!
SessionManager
.
containSession
(
sessionKey
))
throw
IllegalSessionException
if
(!
SessionManager
.
containSession
(
sessionKey
))
throw
IllegalSessionException
when
(
val
session
=
SessionManager
[
sessionKey
])
{
when
(
val
session
=
SessionManager
[
sessionKey
])
{
is
TempSession
->
throw
NotVerifiedSessionException
is
TempSession
->
throw
NotVerifiedSessionException
is
AuthedSession
->
this
.
body
(
session
)
is
AuthedSession
->
this
.
body
(
session
)
}
}
...
@@ -153,9 +149,11 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
...
@@ -153,9 +149,11 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
/*
/*
extend function
extend function
*/
*/
internal
suspend
inline
fun
<
reified
T
:
StateCode
>
ApplicationCall
.
respondStateCode
(
code
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondJson
(
code
.
toJson
(
StateCode
.
serializer
()),
status
)
internal
suspend
inline
fun
<
reified
T
:
StateCode
>
ApplicationCall
.
respondStateCode
(
code
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondJson
(
code
.
toJson
(
StateCode
.
serializer
()),
status
)
internal
suspend
inline
fun
<
reified
T
:
DTO
>
ApplicationCall
.
respondDTO
(
dto
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondJson
(
dto
.
toJson
(),
status
)
internal
suspend
inline
fun
<
reified
T
:
DTO
>
ApplicationCall
.
respondDTO
(
dto
:
T
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondJson
(
dto
.
toJson
(),
status
)
internal
suspend
fun
ApplicationCall
.
respondJson
(
json
:
String
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
internal
suspend
fun
ApplicationCall
.
respondJson
(
json
:
String
,
status
:
HttpStatusCode
=
HttpStatusCode
.
OK
)
=
respondText
(
json
,
defaultTextContentType
(
ContentType
(
"application"
,
"json"
)),
status
)
respondText
(
json
,
defaultTextContentType
(
ContentType
(
"application"
,
"json"
)),
status
)
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/Json.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/
Mirai
Json.kt
View file @
27b44563
File moved
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt
View file @
27b44563
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
27b44563
...
@@ -102,12 +102,6 @@ abstract class Bot : CoroutineScope {
...
@@ -102,12 +102,6 @@ abstract class Bot : CoroutineScope {
*/
*/
abstract
val
qqs
:
ContactList
<
QQ
>
abstract
val
qqs
:
ContactList
<
QQ
>
/**
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
*/
@Deprecated
(
message
=
"这个函数有歧义. 它获取的是好友, 却名为 getQQ"
,
replaceWith
=
ReplaceWith
(
"getFriend(id)"
))
fun
getQQ
(
id
:
Long
):
QQ
=
getFriend
(
id
)
/**
/**
* 获取一个好友或一个群.
* 获取一个好友或一个群.
* 在一些情况下这可能会造成歧义. 请考虑后使用.
* 在一些情况下这可能会造成歧义. 请考虑后使用.
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/linear.kt
View file @
27b44563
...
@@ -96,7 +96,7 @@ suspend inline fun <reified E : Event, R : Any> subscribingGetOrNull(
...
@@ -96,7 +96,7 @@ suspend inline fun <reified E : Event, R : Any> subscribingGetOrNull(
/**
/**
* 异步监听这个事件, 并尝试从这个事件中获取一个值.
* 异步监听这个事件, 并尝试从这个事件中获取一个值.
*
*
* 若 [filter] 抛出
了一个异常, [Deferred.await] 会抛出这个异常或
.
* 若 [filter] 抛出
的异常将会被传递给 [Deferred.await] 抛出
.
*
*
* @param timeoutMillis 超时. 单位为毫秒. `-1` 为不限制
* @param timeoutMillis 超时. 单位为毫秒. `-1` 为不限制
* @param coroutineContext 额外的 [CoroutineContext]
* @param coroutineContext 额外的 [CoroutineContext]
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
View file @
27b44563
...
@@ -249,6 +249,36 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
...
@@ -249,6 +249,36 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
operator
fun
invoke
(
onEvent
:
MessageListener
<
T
>):
Listener
<
T
>
{
operator
fun
invoke
(
onEvent
:
MessageListener
<
T
>):
Listener
<
T
>
{
return
content
(
filter
,
onEvent
)
return
content
(
filter
,
onEvent
)
}
}
infix
fun
reply
(
toReply
:
String
):
Listener
<
T
>
{
return
content
(
filter
)
{
reply
(
toReply
)
}
}
infix
fun
reply
(
message
:
Message
):
Listener
<
T
>
{
return
content
(
filter
)
{
reply
(
message
)
}
}
infix
fun
reply
(
replier
:
(
@MessageDsl
suspend
T
.(
String
)
->
Any
?)):
Listener
<
T
>
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
executeAndReply
(
replier
)
}
}
infix
fun
quoteReply
(
toReply
:
String
):
Listener
<
T
>
{
return
content
(
filter
)
{
quoteReply
(
toReply
)
}
}
infix
fun
quoteReply
(
message
:
Message
):
Listener
<
T
>
{
return
content
(
filter
)
{
quoteReply
(
message
)
}
}
infix
fun
quoteReply
(
replier
:
(
@MessageDsl
suspend
T
.(
String
)
->
Any
?)):
Listener
<
T
>
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
executeAndQuoteReply
(
replier
)
}
}
}
}
/**
/**
...
@@ -698,6 +728,17 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
...
@@ -698,6 +728,17 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
}
}
}
}
@PublishedApi
@Suppress
(
"REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE"
)
// false positive
internal
suspend
inline
fun
T
.
executeAndQuoteReply
(
replier
:
suspend
T
.(
String
)
->
Any
?)
{
when
(
val
message
=
replier
(
this
,
this
.
message
.
toString
()))
{
is
Message
->
this
.
quoteReply
(
message
)
is
Unit
->
{
}
else
->
this
.
quoteReply
(
message
.
toString
())
}
}
/* 易产生迷惑感
/* 易产生迷惑感
fun replyCase(equals: String, trim: Boolean = true, replier: MessageReplier<T>) = case(equals, trim) { reply(replier(this)) }
fun replyCase(equals: String, trim: Boolean = true, replier: MessageReplier<T>) = case(equals, trim) { reply(replier(this)) }
fun replyContains(value: String, replier: MessageReplier<T>) = content({ value in it }) { replier(this) }
fun replyContains(value: String, replier: MessageReplier<T>) = content({ value in it }) { replier(this) }
...
...
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