Skip to content

Commit

Permalink
remove unused import, update to BotAPI 7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
z44d committed Jun 25, 2024
1 parent fac04a1 commit c7df277
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
69 changes: 62 additions & 7 deletions tgram/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import List, Union
from .types import (
StarTransactions,
Update,
InputFile,
WebhookInfo,
Expand Down Expand Up @@ -44,6 +45,7 @@
SentWebAppMessage,
LabeledPrice,
ShippingOption,
Telegram,
PassportElementError,
GameHighScore,
)
Expand Down Expand Up @@ -1501,6 +1503,7 @@ async def get_my_default_administrator_rights(
async def edit_message_text(
self,
text: str,
business_connection_id: str = None,
chat_id: Union[int, str] = None,
message_id: int = None,
inline_message_id: str = None,
Expand All @@ -1513,6 +1516,7 @@ async def edit_message_text(
result = await self._request(
"editMessageText",
text=text,
business_connection_id=business_connection_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
Expand All @@ -1521,10 +1525,15 @@ async def edit_message_text(
link_preview_options=link_preview_options,
reply_markup=reply_markup,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def edit_message_caption(
self,
business_connection_id: str = None,
chat_id: Union[int, str] = None,
message_id: int = None,
inline_message_id: str = None,
Expand All @@ -1537,6 +1546,7 @@ async def edit_message_caption(
"""https://core.telegram.org/bots/api/#editmessagecaption"""
result = await self._request(
"editMessageCaption",
business_connection_id=business_connection_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
Expand All @@ -1546,11 +1556,16 @@ async def edit_message_caption(
show_caption_above_media=show_caption_above_media,
reply_markup=reply_markup,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def edit_message_media(
self,
media: InputMedia,
business_connection_id: str = None,
chat_id: Union[int, str] = None,
message_id: int = None,
inline_message_id: str = None,
Expand All @@ -1560,17 +1575,23 @@ async def edit_message_media(
result = await self._request(
"editMessageMedia",
media=media,
business_connection_id=business_connection_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def edit_message_live_location(
self,
latitude: float,
longitude: float,
business_connection_id: str = None,
chat_id: Union[int, str] = None,
message_id: int = None,
inline_message_id: str = None,
Expand All @@ -1585,6 +1606,7 @@ async def edit_message_live_location(
"editMessageLiveLocation",
latitude=latitude,
longitude=longitude,
business_connection_id=business_connection_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
Expand All @@ -1594,10 +1616,15 @@ async def edit_message_live_location(
proximity_alert_radius=proximity_alert_radius,
reply_markup=reply_markup,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def stop_message_live_location(
self,
business_connection_id: str = None,
chat_id: Union[int, str] = None,
message_id: int = None,
inline_message_id: str = None,
Expand All @@ -1606,15 +1633,21 @@ async def stop_message_live_location(
"""https://core.telegram.org/bots/api/#stopmessagelivelocation"""
result = await self._request(
"stopMessageLiveLocation",
business_connection_id=business_connection_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def edit_message_reply_markup(
self,
business_connection_id: str = None,
chat_id: Union[int, str] = None,
message_id: int = None,
inline_message_id: str = None,
Expand All @@ -1623,24 +1656,31 @@ async def edit_message_reply_markup(
"""https://core.telegram.org/bots/api/#editmessagereplymarkup"""
result = await self._request(
"editMessageReplyMarkup",
business_connection_id=business_connection_id,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def stop_poll(
self,
chat_id: Union[int, str],
message_id: int,
business_connection_id: str = None,
reply_markup: InlineKeyboardMarkup = None,
) -> Poll:
"""https://core.telegram.org/bots/api/#stoppoll"""
result = await self._request(
"stopPoll",
chat_id=chat_id,
message_id=message_id,
business_connection_id=business_connection_id,
reply_markup=reply_markup,
)
return Poll._parse(client=self, d=result["result"])
Expand Down Expand Up @@ -2040,6 +2080,17 @@ async def answer_pre_checkout_query(
)
return result["result"]

async def get_star_transactions(
self, offset: int = None, limit: int = None
) -> StarTransactions:
"""https://core.telegram.org/bots/api/#getstartransactions"""
result = await self._request(
"getStarTransactions",
offset=offset,
limit=limit,
)
return StarTransactions._parse(client=self, d=result["result"])

async def refund_star_payment(
self, user_id: int, telegram_payment_charge_id: str
) -> bool:
Expand Down Expand Up @@ -2110,7 +2161,11 @@ async def set_game_score(
message_id=message_id,
inline_message_id=inline_message_id,
)
return Union[Message, bool]._parse(client=self, d=result["result"])
return (
Message._parse(client=self, d=result["result"])
if isinstance(result["result"], dict)
else result["result"]
)

async def get_game_high_scores(
self,
Expand Down
2 changes: 1 addition & 1 deletion tgram/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tgram
from typing import List, Optional, Union
from typing import List, Union


class Type_:
Expand Down

0 comments on commit c7df277

Please sign in to comment.