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
210a3586
Commit
210a3586
authored
Feb 05, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http-api mute
parent
5d7273d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
7 deletions
+70
-7
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
...src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
+23
-6
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
+9
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt
...otlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt
+38
-0
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
View file @
210a3586
...
...
@@ -14,6 +14,28 @@ abstract class VerifyDTO : DTO {
@Serializable
data class
BindDTO
(
override
val
sessionKey
:
String
,
val
qq
:
Long
)
:
VerifyDTO
()
@Serializable
data class
SendDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
messageChain
:
MessageChainDTO
)
:
VerifyDTO
()
typealias
GroupTargetDTO
=
FriendTargetDTO
@Serializable
data class
FriendTargetDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
)
:
VerifyDTO
()
@Serializable
data class
MuteDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
member
:
Long
=
0
,
val
time
:
Int
=
0
)
:
VerifyDTO
()
@Serializable
open
class
StateCode
(
val
code
:
Int
,
var
msg
:
String
)
{
...
...
@@ -22,6 +44,7 @@ open class StateCode(val code: Int, var msg: String) {
object
IllegalSession
:
StateCode
(
3
,
"Session失效或不存在"
)
object
NotVerifySession
:
StateCode
(
4
,
"Session未认证"
)
object
NoElement
:
StateCode
(
5
,
"指定对象不存在"
)
object
PermissionDenied
:
StateCode
(
10
,
"无操作权限"
)
// KS bug: 主构造器中不能有非字段参数 https://github.com/Kotlin/kotlinx.serialization/issues/575
@Serializable
...
...
@@ -32,9 +55,3 @@ open class StateCode(val code: Int, var msg: String) {
}
}
@Serializable
data class
SendDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
messageChain
:
MessageChainDTO
)
:
VerifyDTO
()
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
View file @
210a3586
...
...
@@ -28,6 +28,7 @@ fun Application.mirai() {
authModule
()
messageModule
()
infoModule
()
groupManageModule
()
}
/**
...
...
@@ -111,8 +112,10 @@ internal inline fun Route.intercept(crossinline blk: suspend PipelineContext<Uni
call
.
respondStateCode
(
StateCode
.
NotVerifySession
)
}
catch
(
e
:
NoSuchBotException
)
{
call
.
respondStateCode
(
StateCode
.
NoBot
)
}
catch
(
e
:
NoSuchElementException
)
{
}
catch
(
e
:
NoSuchElementException
)
{
call
.
respondStateCode
(
StateCode
.
NoElement
)
}
catch
(
e
:
PermissionDeniedException
)
{
call
.
respondStateCode
(
StateCode
.
PermissionDenied
)
}
catch
(
e
:
IllegalAccessException
)
{
call
.
respondStateCode
(
StateCode
(
400
,
e
.
message
),
HttpStatusCode
.
BadRequest
)
}
...
...
@@ -197,6 +200,11 @@ object NotVerifiedSessionException : IllegalAccessException("Session未激活")
*/
object
NoSuchBotException
:
IllegalAccessException
(
"指定Bot不存在"
)
/**
* 指定Bot不存在
*/
object
PermissionDeniedException
:
IllegalAccessException
(
"无操作限权"
)
/**
* 错误参数
*/
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt
0 → 100644
View file @
210a3586
package
net.mamoe.mirai.api.http.route
import
io.ktor.application.Application
import
io.ktor.application.call
import
io.ktor.routing.routing
import
net.mamoe.mirai.api.http.dto.MuteDTO
import
net.mamoe.mirai.api.http.dto.StateCode
fun
Application
.
groupManageModule
()
{
routing
{
miraiVerify
<
MuteDTO
>(
"/muteAll"
)
{
it
.
session
.
bot
.
getGroup
(
it
.
target
).
muteAll
=
true
call
.
respondStateCode
(
StateCode
.
Success
)
}
miraiVerify
<
MuteDTO
>(
"/unmuteAll"
)
{
it
.
session
.
bot
.
getGroup
(
it
.
target
).
muteAll
=
false
call
.
respondStateCode
(
StateCode
.
Success
)
}
miraiVerify
<
MuteDTO
>(
"/mute"
)
{
when
(
it
.
session
.
bot
.
getGroup
(
it
.
target
).
members
[
it
.
member
].
mute
(
it
.
time
))
{
true
->
call
.
respondStateCode
(
StateCode
.
Success
)
else
->
throw
PermissionDeniedException
}
}
miraiVerify
<
MuteDTO
>(
"/unmute"
)
{
when
(
it
.
session
.
bot
.
getGroup
(
it
.
target
).
members
[
it
.
member
].
unmute
())
{
true
->
call
.
respondStateCode
(
StateCode
.
Success
)
else
->
throw
PermissionDeniedException
}
}
}
}
\ No newline at end of file
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