http api handle PermissionDeniedException

This commit is contained in:
ryoii 2020-02-15 17:45:18 +08:00
parent baa3e56d67
commit 830f73062e
3 changed files with 7 additions and 18 deletions

View File

@ -27,11 +27,6 @@ object NotVerifiedSessionException : IllegalAccessException("Session未激活")
*/
object NoSuchBotException: IllegalAccessException("指定Bot不存在")
/**
* 指定Bot不存在
*/
object PermissionDeniedException: IllegalAccessException("无操作限权")
/**
* 错误参数
*/

View File

@ -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

View File

@ -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)
}
/**