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
14a2df03
Commit
14a2df03
authored
Feb 05, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle NoSuchBot Exception
parent
66a015af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
12 deletions
+27
-12
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
.../kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
+19
-11
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
+8
-1
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
View file @
14a2df03
...
@@ -21,22 +21,30 @@ fun Application.authModule() {
...
@@ -21,22 +21,30 @@ fun Application.authModule() {
}
}
miraiVerify
<
BindDTO
>(
"/verify"
,
verifiedSessionKey
=
false
)
{
miraiVerify
<
BindDTO
>(
"/verify"
,
verifiedSessionKey
=
false
)
{
try
{
val
bot
=
getBotOrThrow
(
it
.
qq
)
val
bot
=
Bot
.
instanceWhose
(
it
.
qq
)
with
(
SessionManager
)
{
with
(
SessionManager
)
{
closeSession
(
it
.
sessionKey
)
closeSession
(
it
.
sessionKey
)
allSession
[
it
.
sessionKey
]
=
AuthedSession
(
bot
,
EmptyCoroutineContext
)
allSession
[
it
.
sessionKey
]
=
AuthedSession
(
bot
,
EmptyCoroutineContext
)
}
call
.
respondStateCode
(
StateCode
.
Success
)
}
catch
(
e
:
NoSuchElementException
)
{
call
.
respondStateCode
(
StateCode
.
NoBot
)
}
}
call
.
respondStateCode
(
StateCode
.
Success
)
}
}
miraiVerify
<
BindDTO
>(
"/release"
)
{
miraiVerify
<
BindDTO
>(
"/release"
)
{
SessionManager
.
closeSession
(
it
.
sessionKey
)
val
bot
=
getBotOrThrow
(
it
.
qq
)
call
.
respondStateCode
(
StateCode
.
Success
)
val
session
=
SessionManager
[
it
.
sessionKey
]
as
AuthedSession
if
(
bot
.
uin
==
session
.
bot
.
uin
)
{
SessionManager
.
closeSession
(
it
.
sessionKey
)
call
.
respondStateCode
(
StateCode
.
Success
)
}
else
{
throw
NoSuchElementException
()
}
}
}
}
}
}
}
private
fun
getBotOrThrow
(
qq
:
Long
)
=
try
{
Bot
.
instanceWhose
(
qq
)
}
catch
(
e
:
NoSuchElementException
)
{
throw
NoSuchBotException
}
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
View file @
14a2df03
...
@@ -108,7 +108,9 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
...
@@ -108,7 +108,9 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
call
.
respondStateCode
(
StateCode
.
IllegalSession
)
call
.
respondStateCode
(
StateCode
.
IllegalSession
)
}
catch
(
e
:
NotVerifiedSessionException
)
{
}
catch
(
e
:
NotVerifiedSessionException
)
{
call
.
respondStateCode
(
StateCode
.
NotVerifySession
)
call
.
respondStateCode
(
StateCode
.
NotVerifySession
)
}
catch
(
e
:
NoSuchElementException
)
{
}
catch
(
e
:
NoSuchBotException
)
{
call
.
respondStateCode
(
StateCode
.
NoBot
)
}
catch
(
e
:
NoSuchElementException
)
{
call
.
respondStateCode
(
StateCode
.
NoElement
)
call
.
respondStateCode
(
StateCode
.
NoElement
)
}
catch
(
e
:
IllegalAccessException
)
{
}
catch
(
e
:
IllegalAccessException
)
{
call
.
respondStateCode
(
StateCode
(
400
,
e
.
message
),
HttpStatusCode
.
BadRequest
)
call
.
respondStateCode
(
StateCode
(
400
,
e
.
message
),
HttpStatusCode
.
BadRequest
)
...
@@ -189,6 +191,11 @@ object IllegalSessionException : IllegalAccessException("Session失效或不存
...
@@ -189,6 +191,11 @@ object IllegalSessionException : IllegalAccessException("Session失效或不存
*/
*/
object
NotVerifiedSessionException
:
IllegalAccessException
(
"Session未激活"
)
object
NotVerifiedSessionException
:
IllegalAccessException
(
"Session未激活"
)
/**
* 指定Bot不存在
*/
object
NoSuchBotException
:
IllegalAccessException
(
"指定Bot不存在"
)
/**
/**
* 错误参数
* 错误参数
*/
*/
...
...
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