Skip to content

Commit

Permalink
Allow passing reply_markup as list of 'list of tuples'
Browse files Browse the repository at this point in the history
  • Loading branch information
z44d committed Nov 18, 2024
1 parent 0aa71eb commit da21baf
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 39 deletions.
6 changes: 4 additions & 2 deletions tgram/methods/copy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tgram.types import ReplyParameters
from tgram.types import ParseMode

from tgram.utils import get_parse_mode
from tgram.utils import get_parse_mode, convert_to_inline_keyboard_markup


class CopyMessage:
Expand Down Expand Up @@ -106,7 +106,9 @@ async def copy_message(
if protect_content is not None
else self.protect_content,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return MessageId._parse(me=self, d=result["result"])
6 changes: 4 additions & 2 deletions tgram/methods/edit_message_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tgram.types import MessageEntity
from tgram.types import ParseMode

from tgram.utils import get_parse_mode
from tgram.utils import get_parse_mode, convert_to_inline_keyboard_markup


class EditMessageCaption:
Expand Down Expand Up @@ -38,7 +38,9 @@ async def edit_message_caption(
parse_mode=get_parse_mode(self, parse_mode),
caption_entities=caption_entities,
show_caption_above_media=show_caption_above_media,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
)
return (
Message._parse(me=self, d=result["result"])
Expand Down
6 changes: 5 additions & 1 deletion tgram/methods/edit_message_live_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from tgram.types import InlineKeyboardMarkup
from tgram.types import Message

from tgram.utils import convert_to_inline_keyboard_markup


class EditMessageLiveLocation:
async def edit_message_live_location(
Expand Down Expand Up @@ -36,7 +38,9 @@ async def edit_message_live_location(
horizontal_accuracy=horizontal_accuracy,
heading=heading,
proximity_alert_radius=proximity_alert_radius,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
)
return (
Message._parse(me=self, d=result["result"])
Expand Down
6 changes: 4 additions & 2 deletions tgram/methods/edit_message_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tgram.types import InputMedia
from tgram.types import Message

from tgram.utils import convert_input_media
from tgram.utils import convert_input_media, convert_to_inline_keyboard_markup


class EditMessageMedia:
Expand Down Expand Up @@ -33,7 +33,9 @@ async def edit_message_media(
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
**file,
)
return (
Expand Down
6 changes: 5 additions & 1 deletion tgram/methods/edit_message_reply_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from tgram.types import InlineKeyboardMarkup
from tgram.types import Message

from tgram.utils import convert_to_inline_keyboard_markup


class EditMessageReplyMarkup:
async def edit_message_reply_markup(
Expand All @@ -25,7 +27,9 @@ async def edit_message_reply_markup(
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
)
return (
Message._parse(me=self, d=result["result"])
Expand Down
6 changes: 4 additions & 2 deletions tgram/methods/edit_message_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tgram.types import Message
from tgram.types import MessageEntity, ParseMode

from tgram.utils import get_parse_mode
from tgram.utils import get_parse_mode, convert_to_inline_keyboard_markup


class EditMessageText:
Expand Down Expand Up @@ -38,7 +38,9 @@ async def edit_message_text(
parse_mode=get_parse_mode(self, parse_mode),
entities=entities,
link_preview_options=link_preview_options or self.link_preview_options,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
)
return (
Message._parse(me=self, d=result["result"])
Expand Down
6 changes: 4 additions & 2 deletions tgram/methods/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode
from pathlib import Path
from tgram.utils import get_file_path, get_parse_mode
from tgram.utils import get_file_path, get_parse_mode, convert_to_inline_keyboard_markup


class SendAnimation:
Expand Down Expand Up @@ -144,7 +144,9 @@ async def send_animation(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 4 additions & 2 deletions tgram/methods/send_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode
from pathlib import Path
from tgram.utils import get_file_path, get_parse_mode
from tgram.utils import get_file_path, get_parse_mode, convert_to_inline_keyboard_markup


class SendAudio:
Expand Down Expand Up @@ -137,7 +137,9 @@ async def send_audio(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters

from tgram.utils import convert_to_inline_keyboard_markup


class SendContact:
async def send_contact(
Expand Down Expand Up @@ -103,7 +105,9 @@ async def send_contact(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters

from tgram.utils import convert_to_inline_keyboard_markup


class SendDice:
async def send_dice(
Expand Down Expand Up @@ -88,7 +90,9 @@ async def send_dice(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 4 additions & 2 deletions tgram/methods/send_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode
from pathlib import Path
from tgram.utils import get_file_path, get_parse_mode
from tgram.utils import get_file_path, get_parse_mode, convert_to_inline_keyboard_markup


class SendDocument:
Expand Down Expand Up @@ -126,7 +126,9 @@ async def send_document(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from tgram.types import Message
from tgram.types import ReplyParameters

from tgram.utils import convert_to_inline_keyboard_markup


class SendGame:
async def send_game(
Expand Down Expand Up @@ -79,7 +81,9 @@ async def send_game(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from tgram.types import Message
from tgram.types import ReplyParameters

from tgram.utils import convert_to_inline_keyboard_markup


class SendInvoice:
async def send_invoice(
Expand Down Expand Up @@ -187,7 +189,9 @@ async def send_invoice(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters

from tgram.utils import convert_to_inline_keyboard_markup


class SendLocation:
async def send_location(
Expand Down Expand Up @@ -112,7 +114,9 @@ async def send_location(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
4 changes: 3 additions & 1 deletion tgram/methods/send_media_from_file_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ async def send_media_from_file_id(
else self.protect_content,
"message_effect_id": message_effect_id,
"reply_parameters": reply_parameters,
"reply_markup": reply_markup,
"reply_markup": utils.convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
"allow_paid_broadcast": allow_paid_broadcast,
},
)
Expand Down
6 changes: 4 additions & 2 deletions tgram/methods/send_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode

from tgram.utils import get_parse_mode
from tgram.utils import get_parse_mode, convert_to_inline_keyboard_markup


class SendMessage:
Expand Down Expand Up @@ -113,7 +113,9 @@ async def send_message(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
10 changes: 8 additions & 2 deletions tgram/methods/send_paid_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode

from tgram.utils import convert_input_media, get_parse_mode
from tgram.utils import (
convert_input_media,
get_parse_mode,
convert_to_inline_keyboard_markup,
)


class SendPaidMedia:
Expand Down Expand Up @@ -100,7 +104,9 @@ async def send_paid_media(
if protect_content is not None
else self.protect_content,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
business_connection_id=business_connection_id,
allow_paid_broadcast=allow_paid_broadcast,
**files,
Expand Down
6 changes: 4 additions & 2 deletions tgram/methods/send_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode
from pathlib import Path
from tgram.utils import get_file_path, get_parse_mode
from tgram.utils import get_file_path, get_parse_mode, convert_to_inline_keyboard_markup


class SendPhoto:
Expand Down Expand Up @@ -118,7 +118,9 @@ async def send_photo(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from tgram.types import ReplyKeyboardRemove
from tgram.types import ReplyParameters, ParseMode

from tgram.utils import convert_to_inline_keyboard_markup


class SendPoll:
async def send_poll(
Expand Down Expand Up @@ -158,7 +160,9 @@ async def send_poll(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
6 changes: 5 additions & 1 deletion tgram/methods/send_sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from tgram.types import ReplyParameters
from pathlib import Path

from tgram.utils import convert_to_inline_keyboard_markup


class SendSticker:
async def send_sticker(
Expand Down Expand Up @@ -98,7 +100,9 @@ async def send_sticker(
else self.protect_content,
message_effect_id=message_effect_id,
reply_parameters=reply_parameters,
reply_markup=reply_markup,
reply_markup=convert_to_inline_keyboard_markup(reply_markup)
if isinstance(reply_markup, list)
else reply_markup,
allow_paid_broadcast=allow_paid_broadcast,
)
return Message._parse(me=self, d=result["result"])
Loading

0 comments on commit da21baf

Please sign in to comment.