mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-02 23:22:25 +08:00
Http api ready for recall
This commit is contained in:
parent
06c69ad6cc
commit
241cf2d579
@ -1,9 +1,10 @@
|
|||||||
package net.mamoe.mirai.api.http.data
|
package net.mamoe.mirai.api.http.data
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import net.mamoe.mirai.api.http.data.common.DTO
|
||||||
|
|
||||||
@Serializable
|
@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 Success : StateCode(0, "success") // 成功
|
||||||
object NoBot : StateCode(2, "指定Bot不存在")
|
object NoBot : StateCode(2, "指定Bot不存在")
|
||||||
object IllegalSession : StateCode(3, "Session失效或不存在")
|
object IllegalSession : StateCode(3, "Session失效或不存在")
|
||||||
|
@ -11,9 +11,11 @@ package net.mamoe.mirai.api.http.route
|
|||||||
|
|
||||||
import io.ktor.application.Application
|
import io.ktor.application.Application
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.http.content.readAllParts
|
import io.ktor.http.content.readAllParts
|
||||||
import io.ktor.http.content.streamProvider
|
import io.ktor.http.content.streamProvider
|
||||||
import io.ktor.request.receiveMultipart
|
import io.ktor.request.receiveMultipart
|
||||||
|
import io.ktor.response.respond
|
||||||
import io.ktor.response.respondText
|
import io.ktor.response.respondText
|
||||||
import io.ktor.routing.post
|
import io.ktor.routing.post
|
||||||
import io.ktor.routing.routing
|
import io.ktor.routing.routing
|
||||||
@ -45,14 +47,12 @@ fun Application.messageModule() {
|
|||||||
it.session.bot.getFriend(it.target).apply {
|
it.session.bot.getFriend(it.target).apply {
|
||||||
sendMessage(it.messageChain.toMessageChain(this)) // this aka QQ
|
sendMessage(it.messageChain.toMessageChain(this)) // this aka QQ
|
||||||
}
|
}
|
||||||
call.respondStateCode(StateCode.Success)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
miraiVerify<SendDTO>("/sendGroupMessage") {
|
miraiVerify<SendDTO>("/sendGroupMessage") {
|
||||||
it.session.bot.getGroup(it.target).apply {
|
it.session.bot.getGroup(it.target).apply {
|
||||||
sendMessage(it.messageChain.toMessageChain(this)) // this aka Group
|
sendMessage(it.messageChain.toMessageChain(this)) // this aka Group
|
||||||
}
|
}
|
||||||
call.respondStateCode(StateCode.Success)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
miraiVerify<SendDTO>("/quoteMessage") {
|
miraiVerify<SendDTO>("/quoteMessage") {
|
||||||
@ -100,6 +100,11 @@ fun Application.messageModule() {
|
|||||||
} ?: throw IllegalAccessException("图片上传错误")
|
} ?: throw IllegalAccessException("图片上传错误")
|
||||||
} ?: throw IllegalAccessException("未知错误")
|
} ?: throw IllegalAccessException("未知错误")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
miraiVerify<RecallDTO>("recall") {
|
||||||
|
// TODO
|
||||||
|
call.respond(HttpStatusCode.NotFound, "未完成")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +126,13 @@ private data class SendImageDTO(
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
private class SendRetDTO(
|
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)
|
) : StateCode(stateCode.code, stateCode.msg)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
private data class RecallDTO(
|
||||||
|
override val sessionKey: String,
|
||||||
|
val target: Long,
|
||||||
|
val sender: Long
|
||||||
|
) : VerifyDTO()
|
||||||
|
Loading…
Reference in New Issue
Block a user