Http api ready for recall

This commit is contained in:
ryoii 2020-02-22 19:18:48 +08:00
parent 06c69ad6cc
commit 241cf2d579
2 changed files with 18 additions and 5 deletions

View File

@ -1,9 +1,10 @@
package net.mamoe.mirai.api.http.data
import kotlinx.serialization.Serializable
import net.mamoe.mirai.api.http.data.common.DTO
@Serializable
open class StateCode(val code: Int, var msg: String) {
open class StateCode(val code: Int, var msg: String) : DTO {
object Success : StateCode(0, "success") // 成功
object NoBot : StateCode(2, "指定Bot不存在")
object IllegalSession : StateCode(3, "Session失效或不存在")

View File

@ -11,9 +11,11 @@ package net.mamoe.mirai.api.http.route
import io.ktor.application.Application
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.http.content.readAllParts
import io.ktor.http.content.streamProvider
import io.ktor.request.receiveMultipart
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.post
import io.ktor.routing.routing
@ -45,14 +47,12 @@ fun Application.messageModule() {
it.session.bot.getFriend(it.target).apply {
sendMessage(it.messageChain.toMessageChain(this)) // this aka QQ
}
call.respondStateCode(StateCode.Success)
}
miraiVerify<SendDTO>("/sendGroupMessage") {
it.session.bot.getGroup(it.target).apply {
sendMessage(it.messageChain.toMessageChain(this)) // this aka Group
}
call.respondStateCode(StateCode.Success)
}
miraiVerify<SendDTO>("/quoteMessage") {
@ -100,6 +100,11 @@ fun Application.messageModule() {
} ?: throw IllegalAccessException("图片上传错误")
} ?: throw IllegalAccessException("未知错误")
}
miraiVerify<RecallDTO>("recall") {
// TODO
call.respond(HttpStatusCode.NotFound, "未完成")
}
}
}
@ -121,6 +126,13 @@ private data class SendImageDTO(
@Serializable
private class SendRetDTO(
@Transient val stateCode: StateCode = StateCode.Success,
val messageId: Long
val messageId: Long,
@Transient val stateCode: StateCode = Success
) : StateCode(stateCode.code, stateCode.msg)
@Serializable
private data class RecallDTO(
override val sessionKey: String,
val target: Long,
val sender: Long
) : VerifyDTO()