TWT233 / khl.py

Python SDK for kaiheila.cn API
MIT License
243 stars 40 forks source link

PublicVoiceChannel 类中的 fetch_user_list 函数实现有误 #197

Closed Mythologyli closed 1 year ago

Mythologyli commented 1 year ago

Describe the bug 使用 fetch_user_list 报错

To Reproduce

if not isinstance(public_channel, PublicVoiceChannel):
    return

users = await public_channel.fetch_user_list()

Expected behavior 正常获取到语音频道用户列表

Logs/Screenshots 报错如下:

Traceback (most recent call last):
  File "\venv\lib\site-packages\khl\client.py", line 112, in safe_handler
    await handler(msg)
  File "\venv\lib\site-packages\khl\bot\bot.py", line 142, in handler
    await event_handler(self, event)
  File "\plugins\kook\__init__.py", line 49, in handle_kook_join_channel
    users = await public_channel.fetch_user_list()
  File "\venv\lib\site-packages\khl\channel.py", line 183, in fetch_user_list
    users = await self.gate.exec_paged_req(api.Channel.userList(channel_id=self.id))
  File "\venv\lib\site-packages\khl\gateway.py", line 34, in exec_paged_req
    return await self.requester.exec_paged_req(r, **kwargs)
  File "\venv\lib\site-packages\khl\requester.py", line 81, in exec_paged_req
    ret.extend(p['items'])
TypeError: list indices must be integers or slices, not str

Environment

Additional context /api/v3/channel/user-list 接口返回格式为:

{
    "code": 0,
    "message": "操作成功",
    "data": [
        {
            "id": "999999999",
            "username": "XXX",
            "identify_num": "9999",
            "online": true,
            "os": "Websocket",
            "status": 1,
            "avatar": "XXX",
            "vip_avatar": "XXX",
            "banner": "",
            "nickname": "XXX",
            "roles": [
                4131873
            ],
            "is_vip": false,
            "is_ai_reduce_noise": true,
            "is_personal_card_bg": false,
            "bot": false,
            "mobile_verified": true,
            "joined_at": 1639808384000,
            "active_time": 1639808384000,
            "live_info": {
                "in_live": false,
                "audience_count": 0,
                "live_thumb": "",
                "live_start_time": 0
            }
        }
    ]
}

而 khl 中调用 requester.py 中的 exec_paged_req 函数,data 部分实际上为 list,exec_paged_req 按照 dict 处理,取 p['items'],因此报错 TypeError: list indices must be integers or slices, not str

TWT233 commented 1 year ago

resolved in #198