KurimuzonAkuma / pyrogram

Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots
https://pyrogram.org
GNU Lesser General Public License v3.0
358 stars 95 forks source link

InputBotInlineMessageID's dc_id being the same with Client's dc_id #74

Closed SIR-X closed 4 months ago

SIR-X commented 5 months ago

Checklist

Description

There is a bug in methods.messages.inline_session.

A condition should be added that checks so that if InputBotInlineMessageID's dc_id & Client's dc_id are equal, it doesn't create a new session and returns the client itself.

So, we should add this to it:

if dc_id == await client.storage.dc_id():
    return client

Steps to reproduce

The get_session won't work if dc_id is the same as bot's dc_id. And it's used in all edit_inline_message methods.

Code example

# NOTE That's what you have to do
async def get_session(client: "pyrogram.Client", dc_id: int):
    if dc_id == await client.storage.dc_id():
        return client

    async with client.media_sessions_lock:
        ...

Logs

Traceback (most recent call last):
  File "...\handlers\on_chosen_inline.py", line 51, in OnChosenInline
    await client.edit_inline_text(
  File "...\.venv\Lib\site-packages\pyrogram\methods\messages\edit_inline_text.py", line 78, in edit_inline_text
    session = await get_session(self, dc_id)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\pyrogram\methods\messages\inline_session.py", line 40, in get_session
    exported_auth = await client.invoke(
                    ^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\pyrogram\methods\advanced\invoke.py", line 94, in invoke
    r = await session.invoke(
        ^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\pyrogram\session\session.py", line 401, in invoke
    return await self.send(query, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\pyrogram\session\session.py", line 369, in send
    RPCError.raise_it(result, type(data))
  File "...\.venv\Lib\site-packages\pyrogram\errors\rpc_error.py", line 91, in raise_it
    raise getattr(
pyrogram.errors.exceptions.bad_request_400.DcIdInvalid: Telegram says: [400 DC_ID_INVALID] - The dc_id parameter is invalid (caused by "auth.ExportAuthorization")
MemoKing34 commented 4 months ago

Can you create a pull request?