From 64980e066fb99815d740cd7b29e87e1d7f97e617 Mon Sep 17 00:00:00 2001 From: ryoii Date: Thu, 6 Feb 2020 17:01:22 +0800 Subject: [PATCH 1/4] http-api add botPermission property for group --- .../kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt index 5550ad079..ce87ea576 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt @@ -25,16 +25,17 @@ suspend fun QQDTO(qq: QQ): QQDTO = QQDTO(qq.id, "", "") data class MemberDTO( override val id: Long, val memberName: String = "", - val group: GroupDTO, - val permission: MemberPermission + val permission: MemberPermission, + val group: GroupDTO ) : ContactDTO() -fun MemberDTO(member: Member, name: String = ""): MemberDTO = MemberDTO(member.id, name, GroupDTO(member.group), member.permission) +fun MemberDTO(member: Member, name: String = ""): MemberDTO = MemberDTO(member.id, name, member.permission, GroupDTO(member.group)) @Serializable data class GroupDTO( override val id: Long, - val name: String + val name: String, + val permission: MemberPermission ) : ContactDTO() -fun GroupDTO(group: Group): GroupDTO = GroupDTO(group.id, group.name) \ No newline at end of file +fun GroupDTO(group: Group): GroupDTO = GroupDTO(group.id, group.name, group.botPermission) \ No newline at end of file From 5c30f187f7bdcc7d9fd7122cf56012b5b19160e2 Mon Sep 17 00:00:00 2001 From: ryoii Date: Thu, 6 Feb 2020 18:13:28 +0800 Subject: [PATCH 2/4] http-api group info --- .../net/mamoe/mirai/api/http/dto/VerifyDTO.kt | 23 +++++++++++++++ .../mirai/api/http/route/GroupManageModule.kt | 29 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt index 9fe909dc5..4437083f2 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt @@ -3,6 +3,7 @@ package net.mamoe.mirai.api.http.dto import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import net.mamoe.mirai.api.http.AuthedSession +import net.mamoe.mirai.contact.Group @Serializable abstract class VerifyDTO : DTO { @@ -37,6 +38,28 @@ data class MuteDTO( val time: Int = 0 ) : VerifyDTO() +@Serializable +data class GroupConfigDTO( + override val sessionKey: String, + val target: Long, + val config: GroupInfoDTO +) : VerifyDTO() + +@Serializable +data class GroupInfoDTO( + val name: String? = null, + val announcement: String? = null, + val confessTalk: Boolean? = null, + val allowMemberInvite: Boolean? = null, + val autoApprove: Boolean? = null, + val anonymousChat: Boolean? = null +) : DTO { + constructor(group: Group) : this( + group.name, group.announcement, group.confessTalk, group.allowMemberInvite, + group.autoApprove, group.anonymousChat + ) +} + @Serializable open class StateCode(val code: Int, var msg: String) { object Success : StateCode(0, "success") // 成功 diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt index 794f02fc3..d97c27ac7 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt @@ -3,6 +3,8 @@ 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 @@ -10,6 +12,9 @@ import net.mamoe.mirai.api.http.dto.StateCode fun Application.groupManageModule() { routing { + /** + * 禁言 + */ miraiVerify("/muteAll") { it.session.bot.getGroup(it.target).muteAll = true call.respondStateCode(StateCode.Success) @@ -21,7 +26,7 @@ fun Application.groupManageModule() { } miraiVerify("/mute") { - when(it.session.bot.getGroup(it.target).members[it.member].mute(it.time)) { + when(it.session.bot.getGroup(it.target)[it.member].mute(it.time)) { true -> call.respondStateCode(StateCode.Success) else -> throw PermissionDeniedException } @@ -34,5 +39,27 @@ fun Application.groupManageModule() { } } + /** + * 群设置(需要相关权限) + */ + miraiGet("/groupConfig") { + val group = it.bot.getGroup(paramOrNull("target")) + call.respondDTO(GroupInfoDTO(group)) + } + + miraiVerify("/groupConfig") { dto -> + val group = dto.session.bot.getGroup(dto.target) + with(dto.config) { + name?.let { group.name = it } + announcement?.let { group.announcement = it } + confessTalk?.let { group.confessTalk = it } + allowMemberInvite?.let{ group.allowMemberInvite = it } + // TODO: 待core接口实现设置可改 +// autoApprove?.let { group.autoApprove = it } +// anonymousChat?.let { group.anonymousChat = it } + } + call.respondStateCode(StateCode.Success) + } + } } \ No newline at end of file From 2c32a905b1ff61050737a46ff0e247bb8a1c2d4f Mon Sep 17 00:00:00 2001 From: ryoii Date: Thu, 6 Feb 2020 18:27:34 +0800 Subject: [PATCH 3/4] http-api update readme_cn.md --- mirai-api-http/README_CH.md | 119 ++++++++++++++++++++++++++++++------ 1 file changed, 100 insertions(+), 19 deletions(-) diff --git a/mirai-api-http/README_CH.md b/mirai-api-http/README_CH.md index 40d0a2f1d..31d1b69cc 100644 --- a/mirai-api-http/README_CH.md +++ b/mirai-api-http/README_CH.md @@ -248,7 +248,8 @@ fun main() { "permission": "MEMBER", // 发送者的群限权:OWNER、ADMINISTRATOR或MEMBER "group": { // 消息发送群的信息 "id": 1234567890, // 发送群的群号 - "name": "Miral Technology" // 发送群的群名称 + "name": "Miral Technology", // 发送群的群名称 + "permission": "MEMBER" // 发送群中,Bot的群限权 } } }, @@ -398,10 +399,12 @@ fun main() { ```json5 [{ "id":123456789, - "name":"群名1" + "name":"群名1", + "permission": "MEMBER" },{ "id":987654321, - "name":"群名2" + "name":"群名2", + "permission": "MEMBER" }] ``` @@ -428,19 +431,21 @@ fun main() { [{ "id":1234567890, "memberName":"", + "permission":"MEMBER", "group":{ "id":12345, - "name":"群名1" - }, - "permission":"MEMBER" + "name":"群名1", + "permission": "MEMBER" + } },{ "id":9876543210, "memberName":"", + "permission":"OWNER", "group":{ "id":54321, - "name":"群名2" - }, - "permission":"OWNER" + "name":"群名2", + "permission": "MEMBER" + } }] ``` @@ -458,8 +463,8 @@ fun main() { ```json5 { - "sessionKey": "YourSessionKey", - "target": 123456789, + "sessionKey": "YourSessionKey", + "target": 123456789, } ``` @@ -510,10 +515,10 @@ fun main() { ```json5 { - "sessionKey": "YourSessionKey", - "target": 123456789, - "member": 987654321, - "time": 1800 + "sessionKey": "YourSessionKey", + "target": 123456789, + "member": 987654321, + "time": 1800 } ``` @@ -545,11 +550,11 @@ fun main() { #### 请求: -```josn5 +```json5 { - "sessionKey": "YourSessionKey", - "target": 123456789, - "member": 987654321 + "sessionKey": "YourSessionKey", + "target": 123456789, + "member": 987654321 } ``` @@ -557,3 +562,79 @@ fun main() { 同群禁言群成员 + + +### 群设置 + +使用此方法修改群设置(需要又相关限权) + +``` +[POST] /groupConfig +``` + +#### 请求: + +```json5 +{ + "sessionKey": "YourSessionKey", + "target": 123456789, + "config": { + "name": "群名称", + "announcement": "群公告", + "confessTalk": true, + "allowMemberInvite": true, + "autoApprove": true, + "anonymousChat": true + } +} +``` + +| 名字 | 可选 | 类型 | 举例 | 说明 | +| ----------------- | ----- | ------- | ---------------- | -------------------- | +| sessionKey | false | String | "YourSessionKey" | 你的session key | +| target | false | Long | 123456789 | 指定群的群号 | +| config | false | Object | {} | 群设置 | +| name | true | String | "Name" | 群名 | +| announcement | true | Boolean | true | 群公告 | +| confessTalk | true | Boolean | true | 是否开启坦白说 | +| allowMemberInvite | true | Boolean | true | 是否运行群员邀请 | +| autoApprove | true | Boolean | true | 是否开启自动审批入群 | +| anonymousChat | true | Boolean | true | 是否允许匿名聊天 | + +#### 响应: 返回统一状态码 + +```json5 +{ + "code": 0, + "msg": "success" +} +``` + +### 获取群设置 + +使用此方法获取群设置 + +``` +[Get] /groupConfig?sessionKey=YourSessionKey&target=123456789 +``` + +#### 请求: + +| 名字 | 可选 | 类型 | 举例 | 说明 | +| ----------------- | ----- | ------- | ---------------- | -------------------- | +| sessionKey | false | String | YourSessionKey | 你的session key | +| target | false | Long | 123456789 | 指定群的群号 | + + +#### 响应 + +```json5 +{ + "name": "群名称", + "announcement": "群公告", + "confessTalk": true, + "allowMemberInvite": true, + "autoApprove": true, + "anonymousChat": true +} +``` From ce534bc77b2b7a986587a6d89e0d6cba1c17d2f6 Mon Sep 17 00:00:00 2001 From: ryoii Date: Thu, 6 Feb 2020 18:32:17 +0800 Subject: [PATCH 4/4] http-api make level-top function a constructor --- .../mamoe/mirai/api/http/dto/ContactDTO.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt index ce87ea576..812411c04 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/ContactDTO.kt @@ -16,10 +16,11 @@ data class QQDTO( override val id: Long, val nickName: String, val remark: String -) : ContactDTO() +) : ContactDTO() { + // TODO: queryProfile.nickname & queryRemark.value not support now + constructor(qq: QQ) : this(qq.id, "", "") +} -// TODO: queryProfile.nickname & queryRemark.value not support now -suspend fun QQDTO(qq: QQ): QQDTO = QQDTO(qq.id, "", "") @Serializable data class MemberDTO( @@ -27,15 +28,17 @@ data class MemberDTO( val memberName: String = "", val permission: MemberPermission, val group: GroupDTO -) : ContactDTO() - -fun MemberDTO(member: Member, name: String = ""): MemberDTO = MemberDTO(member.id, name, member.permission, GroupDTO(member.group)) +) : ContactDTO() { + constructor(member: Member, name: String = "") : this ( + member.id, name, member.permission, GroupDTO(member.group) + ) +} @Serializable data class GroupDTO( override val id: Long, val name: String, val permission: MemberPermission -) : ContactDTO() - -fun GroupDTO(group: Group): GroupDTO = GroupDTO(group.id, group.name, group.botPermission) \ No newline at end of file +) : ContactDTO() { + constructor(group: Group) : this(group.id, group.name, group.botPermission) +}