Skip to content

Commit

Permalink
Restyled by yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Jun 29, 2023
1 parent 3e21c81 commit 3873298
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 54 deletions.
45 changes: 24 additions & 21 deletions EzTg/EzTg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@


class Parse(dict):

def __getattr__(*args):
args = dict.get(*args)

return (
Parse(args)
if isinstance(args, dict)
else [
[Parse(y) for y in x] if isinstance(x, list) else Parse(x) for x in args
]
if isinstance(args, list)
else args
)
return (Parse(args) if isinstance(args, dict) else
[[Parse(y) for y in x] if isinstance(x, list) else Parse(x)
for x in args] if isinstance(args, list) else args)

__setattr__ = dict.__setitem__

Expand Down Expand Up @@ -52,9 +47,9 @@ async def send(self, method, **kwargs):
The method you want to use.
\*\*kwargs: `dict`
The parameters you want to send to the method."""
async with aiohttp.request(
"POST", self.api.format(self.token, method), json=kwargs
) as response:
async with aiohttp.request("POST",
self.api.format(self.token, method),
json=kwargs) as response:
r = await response.json()
return Parse(r)

Expand Down Expand Up @@ -85,7 +80,8 @@ async def start_polling(self, callback, callback_query=None):
offset = update[-1].update_id + 1
elif "callback_query" in x.keys() and callback_query:
try:
asyncio.get_event_loop().create_task(callback_query(x))
asyncio.get_event_loop().create_task(
callback_query(x))
except Exception as e:
raise e
finally:
Expand Down Expand Up @@ -151,7 +147,9 @@ async def delete_message(self, chat_id, message_id):
The chat id you want to delete the message from.
message_id: `int`
The message id you want to delete."""
return await self.send("deleteMessage", chat_id=chat_id, message_id=message_id)
return await self.send("deleteMessage",
chat_id=chat_id,
message_id=message_id)

async def edit_message_text(
self,
Expand Down Expand Up @@ -209,9 +207,11 @@ async def edit_message_text(
disable_web_page_preview=disable_web_page_preview,
)

async def forward_message(
self, chat_id, from_chat_id, message_id, disable_notification=False
):
async def forward_message(self,
chat_id,
from_chat_id,
message_id,
disable_notification=False):
"""Foward a message.
Parameters
Expand Down Expand Up @@ -353,7 +353,10 @@ async def set_chat_photo(self, chat_id, photo):
The photo you want to use."""
return await self.send("setChatPhoto", chat_id=chat_id, photo=photo)

async def pin_chat_message(self, chat_id, message_id, disable_notification=False):
async def pin_chat_message(self,
chat_id,
message_id,
disable_notification=False):
"""Pin a message.
Parameters
Expand Down Expand Up @@ -381,9 +384,9 @@ async def unpin_chat_message(self, chat_id, message_id):
The chat id you want to unpin the message.
message_id: `int`
The message id you want to unpin."""
return await self.send(
"unpinChatMessage", chat_id=chat_id, message_id=message_id
)
return await self.send("unpinChatMessage",
chat_id=chat_id,
message_id=message_id)

async def leave_chat(self, chat_id):
"""Leave a chat.
Expand Down
9 changes: 4 additions & 5 deletions EzTg/types/chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def __init__(self, data: dict):
if self.photo:
self.photo = ChatPhoto(self.photo)
self.active_usernames = data.get("active_usernames")
self.emoji_status_custom_emoji_id = data.get("emoji_status_custom_emoji_id")
self.emoji_status_custom_emoji_id = data.get(
"emoji_status_custom_emoji_id")
self.bio = data.get("bio")
self.has_private_forwards = data.get("has_private_forwards")
self.has_restricted_voice_and_video_messages = data.get(
"has_restricted_voice_and_video_messages"
)
"has_restricted_voice_and_video_messages")
self.join_to_send_messages = data.get("join_to_send_messages")
self.join_by_request = data.get("join_by_request")
self.description = data.get("description")
Expand All @@ -95,8 +95,7 @@ def __init__(self, data: dict):
self.slow_mode_delay = data.get("slow_mode_delay")
self.message_auto_delete_time = data.get("message_auto_delete_time")
self.has_aggressive_anti_spam_enabled = data.get(
"has_aggressive_anti_spam_enabled"
)
"has_aggressive_anti_spam_enabled")
self.has_hidden_members = data.get("has_hidden_members")
self.has_protected_content = data.get("has_protected_content")
self.sticket_set_name = data.get("sticket_set_name")
Expand Down
11 changes: 9 additions & 2 deletions EzTg/types/inlinekeyboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class InlineKeyboard:

def __init__(self, data=None):
"""Create a new inline keyboard or Represents an inline keyboard that appears right next to the message it belongs to."""
if data:
Expand Down Expand Up @@ -37,7 +38,10 @@ def callback(self, text, callback_data):
The text of the button
callback_data : str
The callback data of the button"""
self.keyboard[-1].append({"text": text, "callback_data": callback_data})
self.keyboard[-1].append({
"text": text,
"callback_data": callback_data
})

def callback_new_row(self, text, callback_data):
"""Add a new callback button to the keyboard in a new row.
Expand All @@ -49,7 +53,10 @@ def callback_new_row(self, text, callback_data):
callback_data : str
The callback data of the button"""
self.keyboard.append([])
self.keyboard[-1].append({"text": text, "callback_data": callback_data})
self.keyboard[-1].append({
"text": text,
"callback_data": callback_data
})

def send(self):
"""Return the keyboard."""
Expand Down
4 changes: 3 additions & 1 deletion EzTg/types/message/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def __init__(self, data):
self.caption = data.get("caption")
self.caption_entities = data.get("caption_entities")
if self.caption_entities:
self.caption_entities = [MessageEntity(e) for e in self.caption_entities]
self.caption_entities = [
MessageEntity(e) for e in self.caption_entities
]
self.has_media_spoiler = data.get("has_media_spoiler")
self.contact = data.get("contact")
if self.contact:
Expand Down
3 changes: 2 additions & 1 deletion EzTg/types/message/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __init__(self, data):
self.correct_option_id = data.get("correct_option_id")
self.explanation = data.get("explanation")
self.explanation_entities = [
MessageEntity(entity) for entity in data.get("explanation_entities", [])
MessageEntity(entity)
for entity in data.get("explanation_entities", [])
]
self.open_period = data.get("open_period")
self.close_date = data.get("close_date")
41 changes: 19 additions & 22 deletions EzTg/types/replykeyboardmarkup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ReplyKeyboardMarkup:

def __init__(
self,
is_persistent=False,
Expand Down Expand Up @@ -56,17 +57,15 @@ def add(
Optional. The request poll of the button, by default False
web_app : str
Optional. The web app of the button, by default None"""
self.keyboard[-1].append(
{
"text": text,
"request_user": request_user,
"request_chat": request_chat,
"request_contact": request_contact,
"request_location": request_location,
"request_poll": request_poll,
"web_app": web_app,
}
)
self.keyboard[-1].append({
"text": text,
"request_user": request_user,
"request_chat": request_chat,
"request_contact": request_contact,
"request_location": request_location,
"request_poll": request_poll,
"web_app": web_app,
})

def add_new_row(
self,
Expand Down Expand Up @@ -97,17 +96,15 @@ def add_new_row(
web_app : str
Optional. The web app of the button, by default None"""
self.keyboard.append([])
self.keyboard[-1].append(
{
"text": text,
"request_user": request_user,
"request_chat": request_chat,
"request_contact": request_contact,
"request_location": request_location,
"request_poll": request_poll,
"web_app": web_app,
}
)
self.keyboard[-1].append({
"text": text,
"request_user": request_user,
"request_chat": request_chat,
"request_contact": request_contact,
"request_location": request_location,
"request_poll": request_poll,
"web_app": web_app,
})

def send(self):
"""Return the keyboard."""
Expand Down
3 changes: 2 additions & 1 deletion EzTg/types/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def __init__(self, data):
self.is_premium = data.get("is_premium")
self.added_to_attachment_menu = data.get("added_to_attachment_menu")
self.can_join_groups = data.get("can_join_groups")
self.can_read_all_group_messages = data.get("can_read_all_group_messages")
self.can_read_all_group_messages = data.get(
"can_read_all_group_messages")
self.supports_inline_queries = data.get("supports_inline_queries")
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
version="0.3.2",
author="Hexye",
author_email="[email protected]",
description="An api wrapper for telegram easy to use. Coerent according to telegram core.",
description=
"An api wrapper for telegram easy to use. Coerent according to telegram core.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/HexyeDEV/EzTg/",
Expand Down

0 comments on commit 3873298

Please sign in to comment.