Skip to content

Commit

Permalink
Fix bug in clicking UpdateBotCallbackQuery buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Mar 9, 2024
1 parent 5d21d22 commit f66e749
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/source/releases/changes-in-this-fork.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ it can take advantage of new goodies!
| Scheme layer used: 176 |
+------------------------+

- `Fix bug in clicking UpdateBotCallbackQuery buttons <https://t.me/pyrogramchat/610636>`_

+-------------+
| PmOItrOAe |
Expand Down
11 changes: 8 additions & 3 deletions pyrogram/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ def __init__(self, client: "pyrogram.Client"):

async def message_parser(update, users, chats):
return (
await pyrogram.types.Message._parse(self.client, update.message, users, chats,
isinstance(update, UpdateNewScheduledMessage)),
await pyrogram.types.Message._parse(
self.client,
update.message,
users,
chats,
isinstance(update, UpdateNewScheduledMessage)
),
MessageHandler
)

Expand All @@ -109,7 +114,7 @@ async def deleted_messages_parser(update, users, chats):

async def callback_query_parser(update, users, chats):
return (
await pyrogram.types.CallbackQuery._parse(self.client, update, users),
await pyrogram.types.CallbackQuery._parse(self.client, update, users, chats),
CallbackQueryHandler
)

Expand Down
4 changes: 1 addition & 3 deletions pyrogram/methods/messages/get_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
from typing import Union, List, Iterable

import pyrogram
from pyrogram import raw
from pyrogram import types
from pyrogram import utils
from pyrogram import raw, types, utils

log = logging.getLogger(__name__)

Expand Down
27 changes: 20 additions & 7 deletions pyrogram/types/bots_and_keyboards/callback_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from typing import Union, List, Match, Optional

import pyrogram
from pyrogram import raw, enums
from pyrogram import types
from pyrogram import raw, enums, types
from pyrogram.errors import ChannelPrivate
from ..object import Object
from ..update import Update
from ... import utils
Expand Down Expand Up @@ -87,21 +87,34 @@ def __init__(
self.matches = matches

@staticmethod
async def _parse(client: "pyrogram.Client", callback_query, users) -> "CallbackQuery":
async def _parse(client: "pyrogram.Client", callback_query, users, chats) -> "CallbackQuery":
message = None
inline_message_id = None

if isinstance(callback_query, raw.types.UpdateBotCallbackQuery):
chat_id = utils.get_peer_id(callback_query.peer)
peer_id = utils.get_raw_peer_id(callback_query.peer)
message_id = callback_query.msg_id

message = client.message_cache[(chat_id, message_id)]

if not message:
message = await client.get_messages(
chat_id=chat_id,
message_ids=message_id
)
try:
message = await client.get_messages(
chat_id=chat_id,
message_ids=message_id
)
except ChannelPrivate:
channel = chats.get(peer_id, None)
if channel:
message = types.Message(
id=message_id,
date=utils.timestamp_to_datetime(0),
chat=types.Chat._parse_channel_chat(
client,
channel
)
)
elif isinstance(callback_query, raw.types.UpdateInlineBotCallbackQuery):
inline_message_id = utils.pack_inline_message_id(callback_query.msg_id)

Expand Down

0 comments on commit f66e749

Please sign in to comment.