Web

身份组相关查询

更新时间: 2024/03/14 19:21:13

服务器身份组相关查询

查询指定服务器下身份组列表

调用getServerRoles方法可分页方式查询服务器身份组列表,查询结果按照priority数值的升序排列。

该方法的参数limit表示查询结果数量上限。由于查询结果首页必定包含默认身份组(类型为everyone的身份组),因此返回的结果可能会突破 limit 上限。

  • API 原型

    jsgetServerRoles(options: GetServerRolesOptions): Promise<GetServerRolesResult>
    
  • 示例代码

    jsconst roles = await qchat.qchatRole.getServerRoles({
      "serverId": "1001190",
      "timetag": 0
    })
    
    console.log(roles)
    // {
    //     "roles": [
    //         {
    //             "serverId": "1001190",
    //             "roleId": "706315",
    //             "name": "@everyOne",
    //             "icon": "",
    //             "auths": {
    //                 "manageServer": "allow",
    //                 "manageChannel": "deny",
    //                 "manageRole": "deny",
    //                 "sendMsg": "allow",
    //                 "accountInfoSelf": "allow",
    //                 "inviteServer": "allow",
    //                 "kickServer": "deny",
    //                 "accountInfoOther": "deny",
    //                 "recallMsg": "deny",
    //                 "deleteMsg": "deny",
    //                 "remindOther": "allow",
    //                 "remindEveryone": "allow",
    //                 "manageBlackWhiteList": "deny"
    //             },
    //             "type": "everyone",
    //             "priority": 0,
    //             "createTime": 1645090303618,
    //             "updateTime": 1645608234657
    //         },
    //         {
    //             "serverId": "1001190",
    //             "roleId": "1246291",
    //             "name": "计算机1111",
    //             "auths": {
    //                 "manageServer": "allow",
    //                 "manageChannel": "allow",
    //                 "manageRole": "allow",
    //                 "sendMsg": "allow",
    //                 "accountInfoSelf": "allow",
    //                 "inviteServer": "allow",
    //                 "kickServer": "allow",
    //                 "accountInfoOther": "allow",
    //                 "recallMsg": "allow",
    //                 "deleteMsg": "allow",
    //                 "remindOther": "allow",
    //                 "remindEveryone": "allow",
    //                 "manageBlackWhiteList": "allow"
    //             },
    //             "type": "custom",
    //             "memberCount": 0,
    //             "priority": 9,
    //             "createTime": 1646190551938,
    //             "updateTime": 1646190551938
    //         },
    //         {
    //             "serverId": "1001190",
    //             "roleId": "1246297",
    //             "name": "计1212算机1111",
    //             "auths": {
    //                 "manageServer": "allow",
    //                 "manageChannel": "allow",
    //                 "manageRole": "allow",
    //                 "sendMsg": "allow",
    //                 "accountInfoSelf": "allow",
    //                 "inviteServer": "allow",
    //                 "kickServer": "allow",
    //                 "accountInfoOther": "allow",
    //                 "recallMsg": "allow",
    //                 "deleteMsg": "allow",
    //                 "remindOther": "allow",
    //                 "remindEveryone": "allow",
    //                 "manageBlackWhiteList": "allow"
    //             },
    //             "type": "custom",
    //             "memberCount": 0,
    //             "priority": 10,
    //             "createTime": 1646190793107,
    //             "updateTime": 1646190793107
    //         }
    //     ],
    //     "isMemberRoles": [
    //         "1246291",
    //         "1246297"
    //     ]
    // }
    

查询服务器身份组的成员列表

调用getMembersFromServerRole方法可查询某个服务器身份组的成员列表。

仅自定义身份组(即 ERoleTypeCUSTOM 的身份组)支持调该方法查询其成员列表。创建身份组时默认创建的 @everyone 身份组(即 ERoleTypeEVERYONE 的身份组)不支持调用该方法查询成员列表。如调用该方法查询 @everyone 身份组的成员信息, 将报错(错误码 403)。

  • API 原型

    jsgetMembersFromServerRole(options: GetMembersFromServerRoleOptions): Promise<QChatServerRoleMember[]>
    

    其中GetMembersFromServerRoleOptions需要传入serverIdserverRoleroleId、查询锚点时间戳和查询数量限制。此外,如需查询下一页,需要传入查询锚点accid

  • 示例代码

    以下为查询两页的示例代码

    jsconst page1 = await qchat.qchatRole.getMembersFromServerRole({
      "serverId": "{{YOUR_SERVER_ID}}",
      "roleId": "{{YOUR_CHANNEL_ID}}",
    })
    
    const lastMember = page1[page1.length - 1]
    
    const page2 = await qchat.qchatRole.getMembersFromServerRole({
      "serverId": "{{YOUR_SERVER_ID}}",
      "roleId": "{{YOUR_CHANNEL_ID}}",
      "timetag": lastMember.createTime,
      "accid": lastMember.accid
    })
    

通过 accid 查询服务器身份组列表

调用getServerRolesByAccid可通过accid查询该accid所属的服务器身份组,结果会分页。查询结果只会返回自定义身份组,不包含类型为everyone的身份组。

  • API 原型

    jsgetServerRolesByAccid(options: GetServerRolesByAccidOptions): Promise<QChatServerRole[]>
    
  • 示例代码

    jsawait qchat.qchatRole.getServerRolesByAccid({
      "serverId": "{{YOUR_SERVER_ID}}",
      "accid": "{{YOUR_ACCOUNT_ID}}",
    })
    

通过一批 accid 查询服务器身份组列表

调用getExistingServerRolesByAccids 可以通过一组 accid 查询这些 accid 所属的服务器身份组列表。查询结果只会返回自定义身份组(类型为custom),不包含类型为everyone的身份组。

  • 查询结果不分页。
  • 单次调用该方法最多可传入 100 个 accid
  • API 原型

    jsgetExistingServerRolesByAccids(options: GetExistingServerRolesByAccidsOptions): Promise<GetExistingServerRolesByAccidsResult>
    
  • 示例代码

    jsawait qchat.qchatRole.getExistingServerRolesByAccids({
      "serverId": "{{YOUR_SERVER_ID}}",
      "accids": ["{{YOUR_ACCOUNT_ID}}"],
    })
    

查询一批 accid 在某服务器身份组下的成员列表

调用getExistingAccidsInServerRole方法可通过一批accid查询某个服务器身份组下的成员信息。

查询结果不分页。

  • API 原型
    jsgetExistingAccidsInServerRole(options: GetExistingAccidsInServerRoleOptions): Promise<string[]>
    

示例代码

jsconst accids = await qchat.qchatRole.getExistingAccidsInServerRole({
  "serverId": "{{YOUR_SERVER_ID}}",
  "roleId": "{{YOUR_ROLE_ID}}",
  "accids": ["{{YOUR_ACCOUNT_ID}}"],
})

频道身份组相关查询

查询某频道下的身份组信息列表

调用getChannelRoles方法可以分页查询某个频道下的身份组列表。

  • API 原型

    jsgetChannelRoles(options: GetChannelRolesOptions): Promise<QChatChannelRole[]>
    
  • 示例代码

    jsconst channelRoles = await qchat.qchatRole.getChannelRoles({
      "serverId": "1001190",
      "channelId": "935550",
      "limit": 10
    })
    
    console.log(channelRoles)
    
    // [
    //   {
    //     "serverId": "1001190",
    //     "roleId": "689754",
    //     "parentRoleId": "706315",
    //     "channelId": "935550",
    //     "name": "@everyOne",
    //     "icon": "",
    //     "auths": {
    //       "manageChannel": "ignore",
    //       "manageRole": "ignore",
    //       "sendMsg": "ignore",
    //       "recallMsg": "ignore",
    //       "deleteMsg": "ignore",
    //       "remindOther": "ignore",
    //       "remindEveryone": "ignore",
    //       "manageBlackWhiteList": "ignore"
    //     },
    //     "type": "everyone",
    //     "createTime": 1645090353549,
    //     "updateTime": 1645090353549
    //   },
    //   {
    //     "serverId": "1001190",
    //     "roleId": "771147",
    //     "parentRoleId": "788313",
    //     "channelId": "935550",
    //     "auths": {
    //       "manageChannel": "ignore",
    //       "manageRole": "ignore",
    //       "sendMsg": "ignore",
    //       "recallMsg": "ignore",
    //       "deleteMsg": "ignore",
    //       "remindOther": "ignore",
    //       "remindEveryone": "ignore",
    //       "manageBlackWhiteList": "ignore"
    //     },
    //     "type": "custom",
    //     "createTime": 1645178916951,
    //     "updateTime": 1645178916951
    //   },
    // ]
    

根据一批服务器身份组查询相应的频道身份组

调用getExistingChannelRolesByServerRoleIds方法,可通过传入一组服务器身份组 ID 查询继承这些服务器身份组的频道身份组列表。

查询结果不分页。

  • API 原型

    jsgetExistingChannelRolesByServerRoleIds(options: GetExistingChannelRolesByServerRoleIdsOptions): Promise<QChatChannelRole[]>
    

    GetExistingChannelRolesByServerRoleIdsOptions需要传入需要查询的serverIdchannelIdroleIds

  • 示例代码

    jsconst channelRoles = await qchat.qchatRole.getExistingChannelRolesByServerRoleIds({
      "serverId": "{{YOUR_SERVER_ID}}",
      "channelId": "{{YOUR_CHANNEL_ID}}",
      "accids": ["{{YOUR_ACCOUNT_ID}}"],
    })
    

用户定制权限相关查询

批量查询用户是否拥有定制权限

调用getExistingAccidsOfMemberRoles,可通过传入accid列表查询这些accid对应的用户是否拥有该频道下的成员定制权限。

查询结果不分页。

  • API 原型

    jsgetExistingAccidsOfMemberRoles(options: GetExistingAccidsOfMemberRolesOptions): Promise<string[]>
    

    GetExistingAccidsOfMemberRolesOptions中需要传入需要查询的serverIdchannelIdaccid列表。

  • 示例代码

    jsconst accids = await qchat.qchatRole.getExistingAccidsOfMemberRoles({
      "serverId": "{{YOUR_SERVER_ID}}",
      "channelId": "{{YOUR_CHANNEL_ID}}",
      "accids": ["{{YOUR_ACCOUNT_ID}}"],
    })
    

查询频道成员定制权限

调用getMemberRoles方法可分页查询某Channel下的成员定制权限列表。

  • API 原型

    jsgetMemberRoles(options: GetMemberRolesOptions): Promise<QChatMemberRole[]>
    

    其中GetMemberRolesOptions需要传入serverIdchannelId、查询锚点时间戳和查询数量限制。

  • 示例代码

    jsawait qchat.qchatRole.addMemberRole({
      "serverId": "{{YOUR_SERVER_ID}}",
      "channelId": "{{YOUR_CHANNEL_ID}}",
      "accid": "{{YOUR_ACCOUNT_ID}}"
    })
    
    const memberRoles = await qchat.qchatRole.getMemberRoles({
      "serverId": "{{YOUR_SERVER_ID}}",
      "channelId": "{{YOUR_CHANNEL_ID}}",
      "timetag": 0,
    })
    
    console.log(memberRoles)
    // [{
    //     "serverId": "{{YOUR_SERVER_ID}}",
    //     "id": "{{THE_ID}}",
    //     "accid": "{{YOUR_ACCOUNT_ID}}",
    //     "channelId": "{{YOUR_CHANNEL_ID}}",
    //     "auths": {
    //         "manageChannel": "ignore",
    //         "manageRole": "ignore",
    //         "sendMsg": "ignore",
    //         "recallMsg": "ignore",
    //         "deleteMsg": "ignore",
    //         "remindOther": "ignore",
    //         "remindEveryone": "ignore",
    //         "manageBlackWhiteList": "ignore"
    //     },
    //     "createTime": 1646200705882,
    //     "updateTime": 1646200705882,
    //     "nick": "",
    //     "memberType": "normal",
    //     "joinTime": 1645431196871,
    //     "inviter": "test"
    // }]
    

查询自己拥有的权限

查询自己是否拥有某个权限

调用checkPermission方法,可通过传入服务器ID,频道ID和需要查询的权限,查询自己有无该权限,返回truefalse

身份组权限资源项QChatRoleAuth中的权限分为服务器专有的权限与非服务器专有权限(即服务器和频道下均可配置的权限)。如果查询服务器专有的权限,则调用不需要传channelId,其他情况则channelId必须要传。

  • API 原型

    jscheckPermission(options: CheckPermissionOptions): Promise<boolean>
    
  • 示例代码

    jsconst accids = await qchat.qchatRole.checkPermission({
      "serverId": "{{YOUR_SERVER_ID}}",
      "channelId": "{{YOUR_CHANNEL_ID}}",
      "auth": "{{YOUR_AUTH}}",
    })
    

查询自己是否拥有某些权限

调用checkPermissions方法查询自己是否拥有某些权限(单次最多可查 10 个权限)。

  • API 原型

    checkPermissions(options: CheckPermissionsOptions): Promise<checkPermissionsResult>
    
  • 示例代码

      // 初始化SDK
      const qchat = new QChatSDK({
        ... 
      })
      // 等待登录完成
      await qchat.login()
      // 消息搜索
      qchat.qchatRole.checkPermissions({
        "serverId": "{{YOUR_SERVER_ID}}",
        "channelId": "{{YOUR_CHANNEL_ID}}",
        "auths": "{{YOUR_AUTH}}",
      })
    
此文档是否对你有帮助?
有帮助
去反馈
  • 服务器身份组相关查询
  • 查询指定服务器下身份组列表
  • 查询服务器身份组的成员列表
  • 通过 accid 查询服务器身份组列表
  • 通过一批 accid 查询服务器身份组列表
  • 查询一批 accid 在某服务器身份组下的成员列表
  • 频道身份组相关查询
  • 查询某频道下的身份组信息列表
  • 根据一批服务器身份组查询相应的频道身份组
  • 用户定制权限相关查询
  • 批量查询用户是否拥有定制权限
  • 查询频道成员定制权限
  • 查询自己拥有的权限
  • 查询自己是否拥有某个权限
  • 查询自己是否拥有某些权限