mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 19:40:24 +08:00
http api handle PermissionDeniedException
This commit is contained in:
parent
baa3e56d67
commit
830f73062e
@ -27,11 +27,6 @@ object NotVerifiedSessionException : IllegalAccessException("Session未激活")
|
|||||||
*/
|
*/
|
||||||
object NoSuchBotException: IllegalAccessException("指定Bot不存在")
|
object NoSuchBotException: IllegalAccessException("指定Bot不存在")
|
||||||
|
|
||||||
/**
|
|
||||||
* 指定Bot不存在
|
|
||||||
*/
|
|
||||||
object PermissionDeniedException: IllegalAccessException("无操作限权")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误参数
|
* 错误参数
|
||||||
*/
|
*/
|
||||||
|
@ -35,6 +35,7 @@ import net.mamoe.mirai.api.http.data.common.DTO
|
|||||||
import net.mamoe.mirai.api.http.data.common.VerifyDTO
|
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 org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.helpers.NOPLogger
|
import org.slf4j.helpers.NOPLogger
|
||||||
import org.slf4j.helpers.NOPLoggerFactory
|
import org.slf4j.helpers.NOPLoggerFactory
|
||||||
|
@ -4,7 +4,6 @@ import io.ktor.application.Application
|
|||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.routing.routing
|
import io.ktor.routing.routing
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import net.mamoe.mirai.api.http.data.PermissionDeniedException
|
|
||||||
import net.mamoe.mirai.api.http.data.StateCode
|
import net.mamoe.mirai.api.http.data.StateCode
|
||||||
import net.mamoe.mirai.api.http.data.common.DTO
|
import net.mamoe.mirai.api.http.data.common.DTO
|
||||||
import net.mamoe.mirai.api.http.data.common.VerifyDTO
|
import net.mamoe.mirai.api.http.data.common.VerifyDTO
|
||||||
@ -29,27 +28,21 @@ fun Application.groupManageModule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
miraiVerify<MuteDTO>("/mute") {
|
miraiVerify<MuteDTO>("/mute") {
|
||||||
when (it.session.bot.getGroup(it.target)[it.memberId].mute(it.time)) {
|
it.session.bot.getGroup(it.target)[it.memberId].mute(it.time)
|
||||||
true -> call.respondStateCode(StateCode.Success)
|
call.respondStateCode(StateCode.Success)
|
||||||
else -> throw PermissionDeniedException
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
miraiVerify<MuteDTO>("/unmute") {
|
miraiVerify<MuteDTO>("/unmute") {
|
||||||
when (it.session.bot.getGroup(it.target).members[it.memberId].unmute()) {
|
it.session.bot.getGroup(it.target).members[it.memberId].unmute()
|
||||||
true -> call.respondStateCode(StateCode.Success)
|
call.respondStateCode(StateCode.Success)
|
||||||
else -> throw PermissionDeniedException
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移出群聊(需要相关权限)
|
* 移出群聊(需要相关权限)
|
||||||
*/
|
*/
|
||||||
miraiVerify<KickDTO>("/kick") {
|
miraiVerify<KickDTO>("/kick") {
|
||||||
when (it.session.bot.getGroup(it.target)[it.memberId].kick(it.msg)) {
|
it.session.bot.getGroup(it.target)[it.memberId].kick(it.msg)
|
||||||
true -> call.respondStateCode(StateCode.Success)
|
call.respondStateCode(StateCode.Success)
|
||||||
else -> throw PermissionDeniedException
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user