http-api manage member info

This commit is contained in:
ryoii 2020-02-07 15:35:34 +08:00
parent 75d82457ea
commit 685e552d5c
2 changed files with 36 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.mamoe.mirai.api.http.AuthedSession
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member
@Serializable
abstract class VerifyDTO : DTO {
@ -60,6 +61,22 @@ data class GroupInfoDTO(
)
}
@Serializable
data class MemberConfigDTO(
override val sessionKey: String,
val target: Long,
val memberID: Long,
val config: MemberInfoDTO
) : VerifyDTO()
@Serializable
data class MemberInfoDTO(
val name: String? = null,
val specialTitle: String? = null
) : DTO {
constructor(member: Member) : this(member.groupCard, member.specialTitle)
}
@Serializable
open class StateCode(val code: Int, var msg: String) {
object Success : StateCode(0, "success") // 成功

View File

@ -3,17 +3,14 @@ package net.mamoe.mirai.api.http.route
import io.ktor.application.Application
import io.ktor.application.call
import io.ktor.routing.routing
import net.mamoe.mirai.api.http.dto.GroupConfigDTO
import net.mamoe.mirai.api.http.dto.GroupInfoDTO
import net.mamoe.mirai.api.http.dto.MuteDTO
import net.mamoe.mirai.api.http.dto.StateCode
import net.mamoe.mirai.api.http.dto.*
fun Application.groupManageModule() {
routing {
/**
* 禁言
* 禁言需要相关权限
*/
miraiVerify<MuteDTO>("/muteAll") {
it.session.bot.getGroup(it.target).muteAll = true
@ -61,5 +58,22 @@ fun Application.groupManageModule() {
call.respondStateCode(StateCode.Success)
}
/**
* 群员信息管理需要相关权限
*/
miraiGet("/memberInfo") {
val member = it.bot.getGroup(paramOrNull("target"))[paramOrNull("memberID")]
call.respondDTO(MemberInfoDTO(member))
}
miraiVerify<MemberConfigDTO>("/memberInfo") { dto ->
val member = dto.session.bot.getGroup(dto.target)[dto.memberID]
with(dto.config) {
name?.let { member.groupCard = it }
specialTitle?.let { member.specialTitle = it }
}
call.respondStateCode(StateCode.Success)
}
}
}