mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-01 12:49:48 +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不存在")
|
||||
|
||||
/**
|
||||
* 指定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.util.jsonParseOrNull
|
||||
import net.mamoe.mirai.api.http.util.toJson
|
||||
import net.mamoe.mirai.contact.PermissionDeniedException
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.helpers.NOPLogger
|
||||
import org.slf4j.helpers.NOPLoggerFactory
|
||||
|
@ -4,7 +4,6 @@ import io.ktor.application.Application
|
||||
import io.ktor.application.call
|
||||
import io.ktor.routing.routing
|
||||
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.common.DTO
|
||||
import net.mamoe.mirai.api.http.data.common.VerifyDTO
|
||||
@ -29,27 +28,21 @@ fun Application.groupManageModule() {
|
||||
}
|
||||
|
||||
miraiVerify<MuteDTO>("/mute") {
|
||||
when (it.session.bot.getGroup(it.target)[it.memberId].mute(it.time)) {
|
||||
true -> call.respondStateCode(StateCode.Success)
|
||||
else -> throw PermissionDeniedException
|
||||
}
|
||||
it.session.bot.getGroup(it.target)[it.memberId].mute(it.time)
|
||||
call.respondStateCode(StateCode.Success)
|
||||
}
|
||||
|
||||
miraiVerify<MuteDTO>("/unmute") {
|
||||
when (it.session.bot.getGroup(it.target).members[it.memberId].unmute()) {
|
||||
true -> call.respondStateCode(StateCode.Success)
|
||||
else -> throw PermissionDeniedException
|
||||
}
|
||||
it.session.bot.getGroup(it.target).members[it.memberId].unmute()
|
||||
call.respondStateCode(StateCode.Success)
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出群聊(需要相关权限)
|
||||
*/
|
||||
miraiVerify<KickDTO>("/kick") {
|
||||
when (it.session.bot.getGroup(it.target)[it.memberId].kick(it.msg)) {
|
||||
true -> call.respondStateCode(StateCode.Success)
|
||||
else -> throw PermissionDeniedException
|
||||
}
|
||||
it.session.bot.getGroup(it.target)[it.memberId].kick(it.msg)
|
||||
call.respondStateCode(StateCode.Success)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user