From b775dc1a2f5a528e9cf4b0c811ee04dbc1dacc54 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 18 Jan 2023 18:51:38 +0000 Subject: [PATCH 1/4] Restyled by autopep8 --- EzTg/main.py | 7 ++++--- EzTg/user.py | 5 +++-- setup.py | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index cbc5e9f..9bd5efc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -377,7 +377,7 @@ async def get_chat_id(self, message): message: `dict` The message object.s""" return message["chat"]["id"] - + async def get_sender_object(self, message): """Get sender object from message. @@ -386,5 +386,6 @@ async def get_sender_object(self, message): message: `dict` The message object.""" sender = message["from"] - user = User(sender["id"], sender["id_bot"], sender["first_name"], sender["last_name"], sender["username"], sender["language_code"], sender["is_premium"], sender["added_to_attachment_menu"]) - return user \ No newline at end of file + user = User(sender["id"], sender["id_bot"], sender["first_name"], sender["last_name"], + sender["username"], sender["language_code"], sender["is_premium"], sender["added_to_attachment_menu"]) + return user diff --git a/EzTg/user.py b/EzTg/user.py index 4818c81..36900f1 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -1,6 +1,6 @@ class User: """Represents a Telegram user or bot. - + Attributes ---------- id: `int` @@ -25,6 +25,7 @@ class User: Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. supports_inline_queries: `bool` Optional. True, if the bot supports inline queries. Returned only in getMe.""" + def __init__(self, id, is_bot, first_name, last_name, username, language_code, is_premium, added_to_attachment_menu, can_join_groups=None, can_read_all_group_messages=None, supports_inline_queries=None): self.id = id self.is_bot = is_bot @@ -36,4 +37,4 @@ def __init__(self, id, is_bot, first_name, last_name, username, language_code, i self.added_to_attachment_menu = added_to_attachment_menu self.can_join_groups = can_join_groups self.can_read_all_group_messages = can_read_all_group_messages - self.supports_inline_queries = supports_inline_queries \ No newline at end of file + self.supports_inline_queries = supports_inline_queries diff --git a/setup.py b/setup.py index ca59ace..a3a373a 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,7 @@ version="0.3.2", author="Hexye", author_email="dragonsale22@gmail.com", - 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/", From 1cdf86a1f53807fee033120e2b39610f246a9b16 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 18 Jan 2023 18:51:40 +0000 Subject: [PATCH 2/4] Restyled by black --- EzTg/main.py | 61 +++++++++++++++++++++++++++++----------------------- EzTg/user.py | 15 ++++++++++++- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index 9bd5efc..fdbd29b 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -4,13 +4,18 @@ 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__ @@ -22,10 +27,11 @@ class TokenError(Exception): class TelegramClient: - def __init__(self, token): - if (requests.get("https://api.telegram.org/bot" + token + - "/getMe").json()["ok"] == False): + if ( + requests.get("https://api.telegram.org/bot" + token + "/getMe").json()["ok"] + == False + ): raise TokenError("The token you provided is wrong") else: self.token = token @@ -40,9 +46,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) @@ -128,9 +134,7 @@ async def deleteMessage(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 editMessageText( self, @@ -187,11 +191,9 @@ async def editMessageText( disable_web_page_preview=disable_web_page_preview, ) - async def forwardMessage(self, - chat_id, - from_chat_id, - message_id, - disable_notification=False): + async def forwardMessage( + self, chat_id, from_chat_id, message_id, disable_notification=False + ): """Foward a message. Parameters @@ -317,10 +319,7 @@ async def setChatPhoto(self, chat_id, photo): The photo you want to use.""" return await self.send("setChatPhoto", chat_id=chat_id, photo=photo) - async def pinChatMessage(self, - chat_id, - message_id, - disable_notification=False): + async def pinChatMessage(self, chat_id, message_id, disable_notification=False): """Pin a message. Parameters @@ -347,9 +346,9 @@ async def unpinChatMessage(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 leaveChat(self, chat_id): """Leave a chat. @@ -386,6 +385,14 @@ async def get_sender_object(self, message): message: `dict` The message object.""" sender = message["from"] - user = User(sender["id"], sender["id_bot"], sender["first_name"], sender["last_name"], - sender["username"], sender["language_code"], sender["is_premium"], sender["added_to_attachment_menu"]) + user = User( + sender["id"], + sender["id_bot"], + sender["first_name"], + sender["last_name"], + sender["username"], + sender["language_code"], + sender["is_premium"], + sender["added_to_attachment_menu"], + ) return user diff --git a/EzTg/user.py b/EzTg/user.py index 36900f1..ff3ec41 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -26,7 +26,20 @@ class User: supports_inline_queries: `bool` Optional. True, if the bot supports inline queries. Returned only in getMe.""" - def __init__(self, id, is_bot, first_name, last_name, username, language_code, is_premium, added_to_attachment_menu, can_join_groups=None, can_read_all_group_messages=None, supports_inline_queries=None): + def __init__( + self, + id, + is_bot, + first_name, + last_name, + username, + language_code, + is_premium, + added_to_attachment_menu, + can_join_groups=None, + can_read_all_group_messages=None, + supports_inline_queries=None, + ): self.id = id self.is_bot = is_bot self.first_name = first_name From fa97fd925e8c5708ac501ea222ce874e377f1e18 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 18 Jan 2023 18:51:42 +0000 Subject: [PATCH 3/4] Restyled by isort --- EzTg/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/EzTg/main.py b/EzTg/main.py index fdbd29b..727bd12 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -1,5 +1,6 @@ import aiohttp import requests + from .user import User From c2e574c12d42e388c69f8e8028299573c43077db Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 18 Jan 2023 18:51:50 +0000 Subject: [PATCH 4/4] Restyled by yapf --- EzTg/main.py | 49 +++++++++++++++++++++++++------------------------ setup.py | 3 ++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index 727bd12..4ac5e2b 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -5,18 +5,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__ @@ -28,11 +23,10 @@ class TokenError(Exception): class TelegramClient: + def __init__(self, token): - if ( - requests.get("https://api.telegram.org/bot" + token + "/getMe").json()["ok"] - == False - ): + if (requests.get("https://api.telegram.org/bot" + token + + "/getMe").json()["ok"] == False): raise TokenError("The token you provided is wrong") else: self.token = token @@ -47,9 +41,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) @@ -135,7 +129,9 @@ async def deleteMessage(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 editMessageText( self, @@ -192,9 +188,11 @@ async def editMessageText( disable_web_page_preview=disable_web_page_preview, ) - async def forwardMessage( - self, chat_id, from_chat_id, message_id, disable_notification=False - ): + async def forwardMessage(self, + chat_id, + from_chat_id, + message_id, + disable_notification=False): """Foward a message. Parameters @@ -320,7 +318,10 @@ async def setChatPhoto(self, chat_id, photo): The photo you want to use.""" return await self.send("setChatPhoto", chat_id=chat_id, photo=photo) - async def pinChatMessage(self, chat_id, message_id, disable_notification=False): + async def pinChatMessage(self, + chat_id, + message_id, + disable_notification=False): """Pin a message. Parameters @@ -347,9 +348,9 @@ async def unpinChatMessage(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 leaveChat(self, chat_id): """Leave a chat. diff --git a/setup.py b/setup.py index a3a373a..ca59ace 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,8 @@ version="0.3.2", author="Hexye", author_email="dragonsale22@gmail.com", - 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/",