From c7f1528cfc21acc28f3faf95e9f2d8dd3ab828bf Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Wed, 18 Jan 2023 19:48:02 +0100 Subject: [PATCH 001/113] add User class --- EzTg/main.py | 12 ++++++++++++ EzTg/user.py | 39 +++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 EzTg/user.py diff --git a/EzTg/main.py b/EzTg/main.py index ce678c3..cbc5e9f 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -1,5 +1,6 @@ import aiohttp import requests +from .user import User class Parse(dict): @@ -376,3 +377,14 @@ 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. + + Parameters + ---------- + 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 diff --git a/EzTg/user.py b/EzTg/user.py new file mode 100644 index 0000000..4818c81 --- /dev/null +++ b/EzTg/user.py @@ -0,0 +1,39 @@ +class User: + """Represents a Telegram user or bot. + + Attributes + ---------- + id: `int` + The unique identifier for this user or bot. + is_bot: `bool` + True, if this user is a bot. + first_name: `str` + User's or bot's first name. + last_name: `str` + User's or bot's last name. + username: `str` + User's or bot's username. + language_code: `str` + IETF language tag of the user's language. + is_premium: `bool` + True, if this user is a Telegram Premium user + added_to_attachment_menu: `bool` + True, if this user added the bot to the attachment menu + can_join_groups: `bool` + Optional. True, if the bot can be invited to groups. Returned only in getMe. + can_read_all_group_messages: `bool` + 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 + self.first_name = first_name + self.last_name = last_name + self.username = username + self.language_code = language_code + self.is_premium = is_premium + 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 diff --git a/setup.py b/setup.py index 8afe22e..ca59ace 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setuptools.setup( name="EzTg", - version="0.2.2", + version="0.3.2", author="Hexye", author_email="dragonsale22@gmail.com", description= From b775dc1a2f5a528e9cf4b0c811ee04dbc1dacc54 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 18 Jan 2023 18:51:38 +0000 Subject: [PATCH 002/113] 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 003/113] 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 004/113] 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 005/113] 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/", From 4c42eafda3c67f109c18391e3799398b27ab472f Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sat, 4 Feb 2023 01:32:44 +0100 Subject: [PATCH 006/113] add ReplyMarkupKeyboard --- EzTg/replykeyboardmarkup.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 EzTg/replykeyboardmarkup.py diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py new file mode 100644 index 0000000..38bc448 --- /dev/null +++ b/EzTg/replykeyboardmarkup.py @@ -0,0 +1,17 @@ +class ReplyKeyboardMarkup: + def __init__(self, is_persistent=False, resize_keyboard=False, one_time_keyboard=False, selective=False, input_field_placeholder=None): + self.keyboard = [[]] + self.is_persistent = is_persistent + self.resize_keyboard = resize_keyboard + self.one_time_keyboard = one_time_keyboard + self.selective = selective + + def add(self, text, request_user=None, request_chat=None, request_contact=False, request_location=False, request_poll=False, web_app=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}) + + def add_new_row(self, text, request_user=None, request_chat=None, request_contact=False, request_location=False, request_poll=False, web_app=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}) + + def send(self): + return {"reply_markup_keyboard": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective} \ No newline at end of file From efdc88aab3c5189f888225cf1fc1e937618e1db1 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 17 Feb 2023 19:19:43 +0100 Subject: [PATCH 007/113] update getMe according to user class --- EzTg/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EzTg/main.py b/EzTg/main.py index 4ac5e2b..9d0a752 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -215,7 +215,9 @@ async def forwardMessage(self, async def getMe(self): """Get information about the bot.""" - return await self.send("getMe") + r = await self.send("getMe") + user = User(r["id"], r["is_bot"], r["first_name"], r["last_name"], r["username"], r["language_code"], r["is_premium"], r["added_to_attachment_menu"], r["can_join_groups"], r["can_read_all_group_messages"], r["supports_inline_queries"]) + return user async def copyMessage( self, From 14f868dfcadecaa6fcfbf56e82c677ab14b5cf97 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 17 Feb 2023 18:19:58 +0000 Subject: [PATCH 008/113] Restyled by autopep8 --- EzTg/main.py | 3 ++- EzTg/replykeyboardmarkup.py | 14 ++++++++------ setup.py | 3 +-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index 9d0a752..e255663 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -216,7 +216,8 @@ async def forwardMessage(self, async def getMe(self): """Get information about the bot.""" r = await self.send("getMe") - user = User(r["id"], r["is_bot"], r["first_name"], r["last_name"], r["username"], r["language_code"], r["is_premium"], r["added_to_attachment_menu"], r["can_join_groups"], r["can_read_all_group_messages"], r["supports_inline_queries"]) + user = User(r["id"], r["is_bot"], r["first_name"], r["last_name"], r["username"], r["language_code"], r["is_premium"], + r["added_to_attachment_menu"], r["can_join_groups"], r["can_read_all_group_messages"], r["supports_inline_queries"]) return user async def copyMessage( diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 38bc448..ecd09dd 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -5,13 +5,15 @@ def __init__(self, is_persistent=False, resize_keyboard=False, one_time_keyboard self.resize_keyboard = resize_keyboard self.one_time_keyboard = one_time_keyboard self.selective = selective - + def add(self, text, request_user=None, request_chat=None, request_contact=False, request_location=False, request_poll=False, web_app=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, text, request_user=None, request_chat=None, request_contact=False, request_location=False, request_poll=False, web_app=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 {"reply_markup_keyboard": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective} \ No newline at end of file + return {"reply_markup_keyboard": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective} 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 02778671f01a65ce63433219367722d00c8ca6ce Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 17 Feb 2023 18:20:00 +0000 Subject: [PATCH 009/113] Restyled by black --- EzTg/main.py | 64 +++++++++++++++++++++--------------- EzTg/replykeyboardmarkup.py | 65 ++++++++++++++++++++++++++++++++----- 2 files changed, 94 insertions(+), 35 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index e255663..1fc5085 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -5,13 +5,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__ @@ -23,10 +28,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 @@ -41,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) @@ -129,9 +135,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, @@ -188,11 +192,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 @@ -216,8 +218,19 @@ async def forwardMessage(self, async def getMe(self): """Get information about the bot.""" r = await self.send("getMe") - user = User(r["id"], r["is_bot"], r["first_name"], r["last_name"], r["username"], r["language_code"], r["is_premium"], - r["added_to_attachment_menu"], r["can_join_groups"], r["can_read_all_group_messages"], r["supports_inline_queries"]) + user = User( + r["id"], + r["is_bot"], + r["first_name"], + r["last_name"], + r["username"], + r["language_code"], + r["is_premium"], + r["added_to_attachment_menu"], + r["can_join_groups"], + r["can_read_all_group_messages"], + r["supports_inline_queries"], + ) return user async def copyMessage( @@ -321,10 +334,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 @@ -351,9 +361,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ecd09dd..d5fe781 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,19 +1,68 @@ class ReplyKeyboardMarkup: - def __init__(self, is_persistent=False, resize_keyboard=False, one_time_keyboard=False, selective=False, input_field_placeholder=None): + def __init__( + self, + is_persistent=False, + resize_keyboard=False, + one_time_keyboard=False, + selective=False, + input_field_placeholder=None, + ): self.keyboard = [[]] self.is_persistent = is_persistent self.resize_keyboard = resize_keyboard self.one_time_keyboard = one_time_keyboard self.selective = selective - def add(self, text, request_user=None, request_chat=None, request_contact=False, request_location=False, request_poll=False, web_app=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}) + def add( + self, + text, + request_user=None, + request_chat=None, + request_contact=False, + request_location=False, + request_poll=False, + web_app=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, + } + ) - def add_new_row(self, text, request_user=None, request_chat=None, request_contact=False, request_location=False, request_poll=False, web_app=None): + def add_new_row( + self, + text, + request_user=None, + request_chat=None, + request_contact=False, + request_location=False, + request_poll=False, + web_app=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 {"reply_markup_keyboard": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective} + return { + "reply_markup_keyboard": self.keyboard, + "is_persistent": self.is_persistent, + "resize_keyboard": self.resize_keyboard, + "one_time_keyboard": self.one_time_keyboard, + "selective": self.selective, + } From 4221b6f85496d83c76136bc9b4e0db89ccfa0654 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 17 Feb 2023 18:20:13 +0000 Subject: [PATCH 010/113] Restyled by yapf --- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- setup.py | 3 ++- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index 1fc5085..4204a79 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 @@ -334,7 +332,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 @@ -361,9 +362,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index d5fe781..fc6680e 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { 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/", From b269981de7b22baa4a965f94e7256381a8e79123 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Wed, 1 Mar 2023 22:22:27 +0100 Subject: [PATCH 011/113] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..01b37ec --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Hexye + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 6e4d5e6535caa8d5ce0f3a8227f0f2cd38e40bbf Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 1 Mar 2023 21:22:37 +0000 Subject: [PATCH 012/113] Restyled by autopep8 --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 3c441d44dd64b71b6a11eb356e2457444d1d2fed Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 1 Mar 2023 21:22:39 +0000 Subject: [PATCH 013/113] Restyled by black --- EzTg/main.py | 64 ++++++++++++++++++++----------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++----------- 2 files changed, 56 insertions(+), 49 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index 4204a79..33e0484 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -5,13 +5,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__ @@ -23,10 +28,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 @@ -41,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) @@ -97,7 +103,8 @@ async def sendMessage( reply_to_message_id: `int` If the message is a reply, ID of the original message. reply_markup: `dict` - Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.""" + Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + """ if reply_markup: return await self.send( "sendMessage", @@ -129,9 +136,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, @@ -163,7 +168,8 @@ async def editMessageText( disable_web_page_preview: `bool` Disable link previews for links in this message. reply_markup: `InlineKeyboard.send` - Additional interface options. Use the InlineKeyboard class to create a keyboard and use the send method to send it.""" + Additional interface options. Use the InlineKeyboard class to create a keyboard and use the send method to send it. + """ if reply_markup: return await self.send( "editMessageText", @@ -188,11 +194,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 @@ -204,7 +208,8 @@ async def forwardMessage(self, message_id: `int` The message id you want to forward. disable_notification: `bool` - Sends the message silently. Users will receive a notification with no sound.""" + Sends the message silently. Users will receive a notification with no sound. + """ return await self.send( "forwardMessage", chat_id=chat_id, @@ -258,7 +263,8 @@ async def copyMessage( allow_sending_without_reply: `bool` Pass True, if the message should be sent even if the specified replied-to message is not found. reply_markup: `InlineKeyboard.send` - Additional interface options. Use the InlineKeyboard class to create a keyboard and use the send method to send it.""" + Additional interface options. Use the InlineKeyboard class to create a keyboard and use the send method to send it. + """ if reply_markup: return await self.send( "copyMessage", @@ -332,10 +338,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 @@ -345,7 +348,8 @@ async def pinChatMessage(self, message_id: `int` The message id you want to pin. disable_notification: `bool` - Sends the message silently. Users will receive a notification with no sound.""" + Sends the message silently. Users will receive a notification with no sound. + """ return await self.send( "pinChatMessage", chat_id=chat_id, @@ -362,9 +366,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index fc6680e..d5fe781 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { From 13648bbbae05326d465fceaa834bdd240c580fa2 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 1 Mar 2023 21:22:50 +0000 Subject: [PATCH 014/113] Restyled by yapf --- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- setup.py | 3 ++- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/EzTg/main.py b/EzTg/main.py index 33e0484..cf720ee 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) @@ -136,7 +130,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, @@ -194,9 +190,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 @@ -338,7 +336,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 @@ -366,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index d5fe781..fc6680e 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { 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/", From 7b40f05c81005cd3ee7d3fa0eecf13c0f37d6e95 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 11:45:26 +0100 Subject: [PATCH 015/113] fix ReplyKeyboardMarkup --- EzTg/replykeyboardmarkup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 38bc448..087d3f3 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -14,4 +14,4 @@ def add_new_row(self, text, request_user=None, request_chat=None, request_contac 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 {"reply_markup_keyboard": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective} \ No newline at end of file + return {"reply_markup": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective} \ No newline at end of file From 74d0773572fcea3aeb54cc48f67722e04d21823d Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 11:46:55 +0100 Subject: [PATCH 016/113] fix ReplyKeyboardMarkup (again) --- EzTg/replykeyboardmarkup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index c5d9178..15280b4 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -57,7 +57,7 @@ def add_new_row( def send(self): return { - "reply_markup_keyboard": self.keyboard, + "reply_markup": self.keyboard, "is_persistent": self.is_persistent, "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, From 4cd1a27a5931762c6740003d800fafad6c12abc8 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 12:26:11 +0100 Subject: [PATCH 017/113] Add Chat class and related methods --- EzTg/chat.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ EzTg/main.py | 42 +++++++++++++++++++++++- 2 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 EzTg/chat.py diff --git a/EzTg/chat.py b/EzTg/chat.py new file mode 100644 index 0000000..fe7a473 --- /dev/null +++ b/EzTg/chat.py @@ -0,0 +1,91 @@ +class Chat: + """Represents a telegram chat. + + Attributes + ---------- + id: `int` + Unique identifier for this chat. + type: `str` + Type of chat, can be either `private`, `group`, `supergroup` or `channel`. + title: `str` + Optional. Title, for supergroups, channels and group chats. + username: `str` + Optional. Username, for private chats, supergroups and channels if available. + first_name: `str` + Optional. First name of the other party in a private chat. + last_name: `str` + Optional. Last name of the other party in a private chat. + is_forum: `bool` + Optional. True, if the supergroup chat is a forum. + photo: `ChatPhoto` + Optional. Chat photo. Returned only in getChat. + active_usernames: `list` + Optional. Active usernames in the chat. Returned only in getChat. + emoji_status_custom_emoji_id: `str` + Optional. Emoji status custom emoji id. Returned only in getChat. + bio: `str` + Optional. Bio of the chat. Returned only in getChat. + has_private_forwards: `bool` + Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id= links only in chats with the user. Returned only in getChat. + has_restricted_voice_and_video_messages: `bool` + Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat. + join_to_send_messages: `bool` + Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. + join_by_request: `bool` + Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. + description: `str` + Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. + invite_link: `str` + Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. + pinned_message: `Message` + Optional. The most recent pinned message (by sending date). Returned only in getChat. + permissions: `ChatPermissions` + Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. + slow_mode_delay: `int` + Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds. Returned only in getChat. + message_auto_delete_time: `int` + Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat. + has_aggressive_anti_spam_enabled: `bool` + Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only available to chat administrators. Returned only in getChat. + has_hidden_members: `bool` + Optional. True, if non-administrators can only get the list of bots and administrators in the chat. Returned only in getChat. + has_protected_content: `bool` + Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. + sticket_set_name: `str` + Optional. For supergroups, name of group sticker set. Returned only in getChat. + can_set_sticker_set: `bool` + Optional. True, if the bot can change the group sticker set. Returned only in getChat. + linked_chat_id: `int` + Optional. Unique identifier for the linked chat. Returned only in getChat. + location: `ChatLocation` + Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.""" + + def __init__(self, data: dict): + self.id = data["id"] + self.type = data["type"] + self.title = data.get("title") + self.username = data.get("username") + self.first_name = data.get("first_name") + self.last_name = data.get("last_name") + self.is_forum = data.get("is_forum") + self.photo = data.get("photo") + self.active_usernames = data.get("active_usernames") + 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") + 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") + self.invite_link = data.get("invite_link") + self.pinned_message = data.get("pinned_message") + self.permissions = data.get("permissions") + 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") + 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") + self.can_set_sticker_set = data.get("can_set_sticker_set") + self.linked_chat_id = data.get("linked_chat_id") + self.location = data.get("location") \ No newline at end of file diff --git a/EzTg/main.py b/EzTg/main.py index cf720ee..395b2cf 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -2,6 +2,7 @@ import requests from .user import User +from .chat import Chat class Parse(dict): @@ -398,13 +399,14 @@ async def get_chat_id(self, message): The message object.s""" return message["chat"]["id"] - async def get_sender_object(self, message): + async def get_sender_object(self, message) -> User: """Get sender object from message. Parameters ---------- message: `dict` The message object.""" + sender = message["from"] user = User( sender["id"], @@ -417,3 +419,41 @@ async def get_sender_object(self, message): sender["added_to_attachment_menu"], ) return user + + async def get_user_object(self, user) -> User: + """Get user object from user dict. + + Parameters + ---------- + user: `dict` + The user dict.""" + user = User( + user["id"], + user["id_bot"], + user["first_name"], + user["last_name"], + user["username"], + user["language_code"], + user["is_premium"], + user["added_to_attachment_menu"], + ) + return user + + async def get_entity_object(self, entity) -> Chat: + """Get entity object from entity dict. + + Parameters + ---------- + entity: `dict` + The entity dict.""" + return Chat(entity) + + async def get_entity(self, entity_id) -> Chat: + """Get entity from id. + + Parameters + ---------- + entity_id: `int` or `str` + The entity id or username of the target supergroup or channel (in the format @channelusername)""" + raw = await self.send("getChat", chat_id=entity_id) + return await self.get_entity_object(raw) \ No newline at end of file From 761b008b262f06a998d82b92cad833cd5ad3869d Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 12:26:19 +0100 Subject: [PATCH 018/113] . --- EzTg/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EzTg/main.py b/EzTg/main.py index 395b2cf..063fafa 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -456,4 +456,5 @@ async def get_entity(self, entity_id) -> Chat: entity_id: `int` or `str` The entity id or username of the target supergroup or channel (in the format @channelusername)""" raw = await self.send("getChat", chat_id=entity_id) - return await self.get_entity_object(raw) \ No newline at end of file + return await self.get_entity_object(raw) + \ No newline at end of file From a9ebd20f413132004fd2cb951182fc263dd76354 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 11:26:36 +0000 Subject: [PATCH 019/113] Restyled by autopep8 --- EzTg/chat.py | 15 +++++++++------ EzTg/main.py | 5 ++--- EzTg/replykeyboardmarkup.py | 2 +- setup.py | 3 +-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index fe7a473..fe151d6 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,6 +1,6 @@ class Chat: """Represents a telegram chat. - + Attributes ---------- id: `int` @@ -59,7 +59,7 @@ class Chat: Optional. Unique identifier for the linked chat. Returned only in getChat. location: `ChatLocation` Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.""" - + def __init__(self, data: dict): self.id = data["id"] self.type = data["type"] @@ -70,10 +70,12 @@ def __init__(self, data: dict): self.is_forum = data.get("is_forum") self.photo = data.get("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") + self.has_restricted_voice_and_video_messages = data.get( + "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") @@ -82,10 +84,11 @@ def __init__(self, data: dict): self.permissions = data.get("permissions") 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") + self.has_aggressive_anti_spam_enabled = data.get( + "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") self.can_set_sticker_set = data.get("can_set_sticker_set") self.linked_chat_id = data.get("linked_chat_id") - self.location = data.get("location") \ No newline at end of file + self.location = data.get("location") diff --git a/EzTg/main.py b/EzTg/main.py index 063fafa..f6149b9 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -406,7 +406,7 @@ async def get_sender_object(self, message) -> User: ---------- message: `dict` The message object.""" - + sender = message["from"] user = User( sender["id"], @@ -422,7 +422,7 @@ async def get_sender_object(self, message) -> User: async def get_user_object(self, user) -> User: """Get user object from user dict. - + Parameters ---------- user: `dict` @@ -457,4 +457,3 @@ async def get_entity(self, entity_id) -> Chat: The entity id or username of the target supergroup or channel (in the format @channelusername)""" raw = await self.send("getChat", chat_id=entity_id) return await self.get_entity_object(raw) - \ No newline at end of file diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 15280b4..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -62,4 +62,4 @@ def send(self): "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective, - } \ No newline at end of file + } 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 02323034521954b636ed39e8f89997b4e69a0c07 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 11:26:37 +0000 Subject: [PATCH 020/113] Restyled by black --- EzTg/chat.py | 12 +++++---- EzTg/main.py | 52 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++-------------- 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index fe151d6..e3c9b74 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -58,7 +58,8 @@ class Chat: linked_chat_id: `int` Optional. Unique identifier for the linked chat. Returned only in getChat. location: `ChatLocation` - Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.""" + Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. + """ def __init__(self, data: dict): self.id = data["id"] @@ -70,12 +71,12 @@ def __init__(self, data: dict): self.is_forum = data.get("is_forum") self.photo = data.get("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") @@ -85,7 +86,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index f6149b9..5929677 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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. @@ -454,6 +453,7 @@ async def get_entity(self, entity_id) -> Chat: Parameters ---------- entity_id: `int` or `str` - The entity id or username of the target supergroup or channel (in the format @channelusername)""" + The entity id or username of the target supergroup or channel (in the format @channelusername) + """ raw = await self.send("getChat", chat_id=entity_id) return await self.get_entity_object(raw) diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { From c5c44992790aebe2d961fea20ecf8533031dcd75 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 11:26:38 +0000 Subject: [PATCH 021/113] Restyled by isort --- EzTg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/main.py b/EzTg/main.py index 5929677..63d8d94 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -1,8 +1,8 @@ import aiohttp import requests -from .user import User from .chat import Chat +from .user import User class Parse(dict): From 8a1d5838a1f64fa118b35be8229b0e3b674faa95 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 11:26:40 +0000 Subject: [PATCH 022/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- setup.py | 3 ++- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e3c9b74..cf2cfd0 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -71,12 +71,12 @@ def __init__(self, data: dict): self.is_forum = data.get("is_forum") self.photo = data.get("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") @@ -86,8 +86,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") diff --git a/EzTg/main.py b/EzTg/main.py index 63d8d94..b581623 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { 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/", From 931da9a1e45c2ff54e4e013aec6cece60d2d9549 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 15:23:41 +0100 Subject: [PATCH 023/113] Add ChatPhoto class #20 and User class refactor --- EzTg/chat.py | 4 ++++ EzTg/chatphoto.py | 19 +++++++++++++++++++ EzTg/main.py | 18 ++---------------- EzTg/user.py | 34 ++++++++++++---------------------- 4 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 EzTg/chatphoto.py diff --git a/EzTg/chat.py b/EzTg/chat.py index fe7a473..d9772ff 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,3 +1,5 @@ +from .chatphoto import ChatPhoto + class Chat: """Represents a telegram chat. @@ -69,6 +71,8 @@ def __init__(self, data: dict): self.last_name = data.get("last_name") self.is_forum = data.get("is_forum") self.photo = data.get("photo") + 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.bio = data.get("bio") diff --git a/EzTg/chatphoto.py b/EzTg/chatphoto.py new file mode 100644 index 0000000..dec0460 --- /dev/null +++ b/EzTg/chatphoto.py @@ -0,0 +1,19 @@ +class ChatPhoto: + """Represents a chat photo. + + Attributes + ---------- + small_file_id: `str` + File identifier of small (160x160) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. + small_file_unique_id: `str` + Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + big_file_id: `str` + File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. + big_file_unique_id: `str` + Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.""" + + def __init__(self, data): + self.small_file_id = data['small_file_id'] + self.small_file_unique_id = data['small_file_unique_id'] + self.big_file_id = data['big_file_id'] + self.big_file_unique_id = data['big_file_unique_id'] \ No newline at end of file diff --git a/EzTg/main.py b/EzTg/main.py index 063fafa..228b73b 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -409,14 +409,7 @@ async def get_sender_object(self, message) -> User: 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"], + sender ) return user @@ -428,14 +421,7 @@ async def get_user_object(self, user) -> User: user: `dict` The user dict.""" user = User( - user["id"], - user["id_bot"], - user["first_name"], - user["last_name"], - user["username"], - user["language_code"], - user["is_premium"], - user["added_to_attachment_menu"], + user ) return user diff --git a/EzTg/user.py b/EzTg/user.py index ff3ec41..782ea5d 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -28,26 +28,16 @@ class User: 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, + data ): - self.id = id - self.is_bot = is_bot - self.first_name = first_name - self.last_name = last_name - self.username = username - self.language_code = language_code - self.is_premium = is_premium - 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 + self.id = data["id"] + self.is_bot = data["is_bot"] + self.first_name = data["first_name"] + self.last_name = data.get("last_name") + self.username = data.get("username") + self.language_code = data.get("language_code") + 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.supports_inline_queries = data.get("supports_inline_queries") From a384d6b96498e213172178fb217991ff82876fda Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:23:50 +0000 Subject: [PATCH 024/113] Restyled by autopep8 --- EzTg/chat.py | 1 + EzTg/chatphoto.py | 6 +++--- EzTg/user.py | 3 ++- setup.py | 3 +-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 9233627..bf7045f 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,5 +1,6 @@ from .chatphoto import ChatPhoto + class Chat: """Represents a telegram chat. diff --git a/EzTg/chatphoto.py b/EzTg/chatphoto.py index dec0460..9e839a4 100644 --- a/EzTg/chatphoto.py +++ b/EzTg/chatphoto.py @@ -1,6 +1,6 @@ class ChatPhoto: """Represents a chat photo. - + Attributes ---------- small_file_id: `str` @@ -11,9 +11,9 @@ class ChatPhoto: File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. big_file_unique_id: `str` Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.""" - + def __init__(self, data): self.small_file_id = data['small_file_id'] self.small_file_unique_id = data['small_file_unique_id'] self.big_file_id = data['big_file_id'] - self.big_file_unique_id = data['big_file_unique_id'] \ No newline at end of file + self.big_file_unique_id = data['big_file_unique_id'] diff --git a/EzTg/user.py b/EzTg/user.py index 782ea5d..7f95e5b 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -39,5 +39,6 @@ def __init__( 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") 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 5ba44ddd08de7c07d674f9eae54edcbad94a2a85 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:23:52 +0000 Subject: [PATCH 025/113] Restyled by black --- EzTg/chat.py | 9 +++--- EzTg/chatphoto.py | 11 +++---- EzTg/main.py | 57 +++++++++++++++++-------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++------------- EzTg/user.py | 8 ++---- 5 files changed, 61 insertions(+), 65 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index bf7045f..7d124dd 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -76,12 +76,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") @@ -91,7 +91,8 @@ 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") diff --git a/EzTg/chatphoto.py b/EzTg/chatphoto.py index 9e839a4..fa4d108 100644 --- a/EzTg/chatphoto.py +++ b/EzTg/chatphoto.py @@ -10,10 +10,11 @@ class ChatPhoto: big_file_id: `str` File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. big_file_unique_id: `str` - Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.""" + Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + """ def __init__(self, data): - self.small_file_id = data['small_file_id'] - self.small_file_unique_id = data['small_file_unique_id'] - self.big_file_id = data['big_file_id'] - self.big_file_unique_id = data['big_file_unique_id'] + self.small_file_id = data["small_file_id"] + self.small_file_unique_id = data["small_file_unique_id"] + self.big_file_id = data["big_file_id"] + self.big_file_unique_id = data["big_file_unique_id"] diff --git a/EzTg/main.py b/EzTg/main.py index 2783930..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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. @@ -408,9 +407,7 @@ async def get_sender_object(self, message) -> User: The message object.""" sender = message["from"] - user = User( - sender - ) + user = User(sender) return user async def get_user_object(self, user) -> User: @@ -420,9 +417,7 @@ async def get_user_object(self, user) -> User: ---------- user: `dict` The user dict.""" - user = User( - user - ) + user = User(user) return user async def get_entity_object(self, entity) -> Chat: diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7f95e5b..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -26,10 +26,7 @@ class User: supports_inline_queries: `bool` Optional. True, if the bot supports inline queries. Returned only in getMe.""" - def __init__( - self, - data - ): + def __init__(self, data): self.id = data["id"] self.is_bot = data["is_bot"] self.first_name = data["first_name"] @@ -39,6 +36,5 @@ def __init__( 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") From 5fede700e904b19c3041d03ddcedcc722a2ad66a Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:23:55 +0000 Subject: [PATCH 026/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 7d124dd..bf7045f 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -76,12 +76,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") @@ -91,8 +91,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From c762b084a819becad102fc05a90104c9fd4cefb9 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 15:37:13 +0100 Subject: [PATCH 027/113] add Message class #20 --- EzTg/chat.py | 3 + EzTg/message.py | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 EzTg/message.py diff --git a/EzTg/chat.py b/EzTg/chat.py index 9233627..ec3737f 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,4 +1,5 @@ from .chatphoto import ChatPhoto +from .message import Message class Chat: """Represents a telegram chat. @@ -86,6 +87,8 @@ def __init__(self, data: dict): self.description = data.get("description") self.invite_link = data.get("invite_link") self.pinned_message = data.get("pinned_message") + if self.pinned_message: + self.pinned_message = Message(self.pinned_message) self.permissions = data.get("permissions") self.slow_mode_delay = data.get("slow_mode_delay") self.message_auto_delete_time = data.get("message_auto_delete_time") diff --git a/EzTg/message.py b/EzTg/message.py new file mode 100644 index 0000000..0be2a90 --- /dev/null +++ b/EzTg/message.py @@ -0,0 +1,146 @@ +from .user import User +from .chat import Chat + +class Message: + """Represents a message. + + Attributes + ---------- + message_id: `int` + Unique message identifier inside this chat. + message_thread_id: `int` + Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + from_user: `User` + Optional. Sender, empty for messages sent to channels. + sender_chat: `Chat` + Optional. Sender of the message, sent on behalf of a chat. The channel itself for channel messages. The supergroup itself for messages from anonymous group administrators. The linked channel for messages automatically forwarded to the discussion group. + date: `int` + Date the message was sent in Unix time. + chat: `Chat` + Conversation the message belongs to. + forward_from: `User` + Optional. For forwarded messages, sender of the original message. + forward_from_chat: `Chat` + Optional. For messages forwarded from channels, information about the original channel. + forward_from_message_id: `int` + Optional. For messages forwarded from channels, identifier of the original message in the channel. + forward_signature: `str` + Optional. For messages forwarded from channels, signature of the post author if present. + forward_sender_name: `str` + Optional. For messages forwarded from channels, sender's name for messages forwarded to the discussion group. + forward_date: `int` + Optional. For forwarded messages, date the original message was sent in Unix time. + is_topic_message: `bool` + Optional. True, if the message is sent to a forum topic + is_automatic_forward: `bool` + Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group + reply_to_message: `Message` + Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. + via_bot: `User` + Optional. Bot through which the message was sent. + edit_date: `int` + Optional. Date the message was last edited in Unix time. + has_protected_content: `bool` + Optional. True, if the message can't be forwarded. + media_group_id: `str` + Optional. The unique identifier of a media message group this message belongs to. + author_signature: `str` + Optional. Signature of the post author for messages in channels. + text: `str` + Optional. For text messages, the actual UTF-8 text of the message. + animation: `Animation` + Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set. + audio: `Audio` + Optional. Message is an audio file, information about the file. + document: `Document` + Optional. Message is a general file, information about the file. + photo: `list[PhotoSize]` + Optional. Message is a photo, available sizes of the photo. + sticker: `Sticker` + Optional. Message is a sticker, information about the sticker. + video: `Video` + Optional. Message is a video, information about the video. + video_note: `VideoNote` + Optional. Message is a video note, information about the video message. + voice: `Voice` + Optional. Message is a voice message, information about the file. + caption: `str` + Optional. Caption for the animation, audio, document, photo, video or voice, 0-1024 characters. + caption_entities: `list[MessageEntity]` + Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption. + has_media_spoiler: `bool` + Optional. True, if the message media is covered by a spoiler animation + contact: `Contact` + Optional. Message is a shared contact, information about the contact. + dice: `Dice` + Optional. Message is a dice with random value from 1 to 6. + game: `Game` + Optional. Message is a game, information about the game. + poll: `Poll` + Optional. Message is a native poll, information about the poll. + venue: `Venue` + Optional. Message is a venue, information about the venue. + location: `Location` + Optional. Message is a shared location, information about the location. + new_chat_members: `list[User]` + Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members). + left_chat_member: `User` + Optional. A member was removed from the group, information about them (this member may be the bot itself). + new_chat_title: `str` + Optional. A chat title was changed to this value. + new_chat_photo: `list[PhotoSize]` + Optional. A chat photo was change to this value. + delete_chat_photo: `bool` + Optional. Service message: the chat photo was deleted. + group_chat_created: `bool` + Optional. Service message: the group has been created. + supergroup_chat_created: `bool` + Optional. Service message: the supergroup has been created. + """ + + def __init__(self, data): + self.message_id = data['message_id'] + self.message_thread_id = data.get('message_thread_id') + self.from_user = User(data.get('from')) + self.sender_chat = Chat(data.get('sender_chat')) + self.date = data['date'] + self.chat = Chat(data['chat']) + self.forward_from = User(data.get('forward_from')) + self.forward_from_chat = Chat(data.get('forward_from_chat')) + self.forward_from_message_id = data.get('forward_from_message_id') + self.forward_signature = data.get('forward_signature') + self.forward_sender_name = data.get('forward_sender_name') + self.forward_date = data.get('forward_date') + self.is_topic_message = data.get('is_topic_message') + self.is_automatic_forward = data.get('is_automatic_forward') + self.reply_to_message = Message(data.get('reply_to_message')) + self.via_bot = User(data.get('via_bot')) + self.edit_date = data.get('edit_date') + self.has_protected_content = data.get('has_protected_content') + self.media_group_id = data.get('media_group_id') + self.author_signature = data.get('author_signature') + self.text = data.get('text') + self.animation = data.get('animation') + self.audio = data.get('audio') + self.document = data.get('document') + self.photo = data.get('photo') + self.sticker = data.get('sticker') + self.video = data.get('video') + self.video_note = data.get('video_note') + self.voice = data.get('voice') + self.caption = data.get('caption') + self.caption_entities = data.get('caption_entities') + self.has_media_spoiler = data.get('has_media_spoiler') + self.contact = data.get('contact') + self.dice = data.get('dice') + self.game = data.get('game') + self.poll = data.get('poll') + self.venue = data.get('venue') + self.location = data.get('location') + self.new_chat_members = data.get('new_chat_members') + if self.new_chat_members: + self.new_chat_members = [User(x) for x in self.new_chat_members] + self.left_chat_member = data.get('left_chat_member') + if self.left_chat_member: + self.left_chat_member = User(self.left_chat_member) + self.new_chat_title = data.get('new_chat_title') \ No newline at end of file From 541ee648686d20ac81ad30f6886693601890bc72 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:37:23 +0000 Subject: [PATCH 028/113] Restyled by autopep8 --- EzTg/message.py | 5 +++-- setup.py | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/EzTg/message.py b/EzTg/message.py index 0be2a90..fdc32c3 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -1,9 +1,10 @@ from .user import User from .chat import Chat + class Message: """Represents a message. - + Attributes ---------- message_id: `int` @@ -143,4 +144,4 @@ def __init__(self, data): self.left_chat_member = data.get('left_chat_member') if self.left_chat_member: self.left_chat_member = User(self.left_chat_member) - self.new_chat_title = data.get('new_chat_title') \ No newline at end of file + self.new_chat_title = data.get('new_chat_title') 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 13de86f339ded2806693a82ab5569cad53e6b447 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:37:25 +0000 Subject: [PATCH 029/113] Restyled by black --- EzTg/chat.py | 9 ++-- EzTg/main.py | 49 +++++++++++----------- EzTg/message.py | 82 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 ++++++++++--------- EzTg/user.py | 3 +- 5 files changed, 93 insertions(+), 91 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 6e1c955..9828785 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -77,12 +77,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") @@ -94,7 +94,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/message.py b/EzTg/message.py index fdc32c3..8b38e2e 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -100,48 +100,48 @@ class Message: """ def __init__(self, data): - self.message_id = data['message_id'] - self.message_thread_id = data.get('message_thread_id') - self.from_user = User(data.get('from')) - self.sender_chat = Chat(data.get('sender_chat')) - self.date = data['date'] - self.chat = Chat(data['chat']) - self.forward_from = User(data.get('forward_from')) - self.forward_from_chat = Chat(data.get('forward_from_chat')) - self.forward_from_message_id = data.get('forward_from_message_id') - self.forward_signature = data.get('forward_signature') - self.forward_sender_name = data.get('forward_sender_name') - self.forward_date = data.get('forward_date') - self.is_topic_message = data.get('is_topic_message') - self.is_automatic_forward = data.get('is_automatic_forward') - self.reply_to_message = Message(data.get('reply_to_message')) - self.via_bot = User(data.get('via_bot')) - self.edit_date = data.get('edit_date') - self.has_protected_content = data.get('has_protected_content') - self.media_group_id = data.get('media_group_id') - self.author_signature = data.get('author_signature') - self.text = data.get('text') - self.animation = data.get('animation') - self.audio = data.get('audio') - self.document = data.get('document') - self.photo = data.get('photo') - self.sticker = data.get('sticker') - self.video = data.get('video') - self.video_note = data.get('video_note') - self.voice = data.get('voice') - self.caption = data.get('caption') - self.caption_entities = data.get('caption_entities') - self.has_media_spoiler = data.get('has_media_spoiler') - self.contact = data.get('contact') - self.dice = data.get('dice') - self.game = data.get('game') - self.poll = data.get('poll') - self.venue = data.get('venue') - self.location = data.get('location') - self.new_chat_members = data.get('new_chat_members') + self.message_id = data["message_id"] + self.message_thread_id = data.get("message_thread_id") + self.from_user = User(data.get("from")) + self.sender_chat = Chat(data.get("sender_chat")) + self.date = data["date"] + self.chat = Chat(data["chat"]) + self.forward_from = User(data.get("forward_from")) + self.forward_from_chat = Chat(data.get("forward_from_chat")) + self.forward_from_message_id = data.get("forward_from_message_id") + self.forward_signature = data.get("forward_signature") + self.forward_sender_name = data.get("forward_sender_name") + self.forward_date = data.get("forward_date") + self.is_topic_message = data.get("is_topic_message") + self.is_automatic_forward = data.get("is_automatic_forward") + self.reply_to_message = Message(data.get("reply_to_message")) + self.via_bot = User(data.get("via_bot")) + self.edit_date = data.get("edit_date") + self.has_protected_content = data.get("has_protected_content") + self.media_group_id = data.get("media_group_id") + self.author_signature = data.get("author_signature") + self.text = data.get("text") + self.animation = data.get("animation") + self.audio = data.get("audio") + self.document = data.get("document") + self.photo = data.get("photo") + self.sticker = data.get("sticker") + self.video = data.get("video") + self.video_note = data.get("video_note") + self.voice = data.get("voice") + self.caption = data.get("caption") + self.caption_entities = data.get("caption_entities") + self.has_media_spoiler = data.get("has_media_spoiler") + self.contact = data.get("contact") + self.dice = data.get("dice") + self.game = data.get("game") + self.poll = data.get("poll") + self.venue = data.get("venue") + self.location = data.get("location") + self.new_chat_members = data.get("new_chat_members") if self.new_chat_members: self.new_chat_members = [User(x) for x in self.new_chat_members] - self.left_chat_member = data.get('left_chat_member') + self.left_chat_member = data.get("left_chat_member") if self.left_chat_member: self.left_chat_member = User(self.left_chat_member) - self.new_chat_title = data.get('new_chat_title') + self.new_chat_title = data.get("new_chat_title") diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From def94db845a01b20a8566768f0b9f7276d0b9468 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:37:26 +0000 Subject: [PATCH 030/113] Restyled by isort --- EzTg/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/message.py b/EzTg/message.py index 8b38e2e..8f1c4ee 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -1,5 +1,5 @@ -from .user import User from .chat import Chat +from .user import User class Message: From 803493226b8555640645e60afdf372c36b307edf Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:37:29 +0000 Subject: [PATCH 031/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 9828785..6e1c955 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -77,12 +77,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") @@ -94,8 +94,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 12cb33360f5338a130bd8305923cc59e6b5873da Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 15:45:23 +0100 Subject: [PATCH 032/113] add ChatPermissions class --- EzTg/chat.py | 3 +++ EzTg/chatpermissions.py | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 EzTg/chatpermissions.py diff --git a/EzTg/chat.py b/EzTg/chat.py index 6e1c955..d2cf988 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,5 +1,6 @@ from .chatphoto import ChatPhoto from .message import Message +from .chatpermissions import ChatPermissions class Chat: @@ -91,6 +92,8 @@ def __init__(self, data: dict): if self.pinned_message: self.pinned_message = Message(self.pinned_message) self.permissions = data.get("permissions") + if self.permissions: + self.permissions = ChatPermissions(self.permissions) 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( diff --git a/EzTg/chatpermissions.py b/EzTg/chatpermissions.py new file mode 100644 index 0000000..0db9e64 --- /dev/null +++ b/EzTg/chatpermissions.py @@ -0,0 +1,51 @@ +class ChatPermissions: + """Describes actions that a non-administrator user is allowed to take in a chat. + + Attributes + ---------- + can_send_messages: `bool` + Optional. True, if the user is allowed to send text messages, contacts, locations and venues. + can_send_audios: `bool` + Optional. True, if the user is allowed to send audios. + can_send_documents: `bool` + Optional. True, if the user is allowed to send documents. + cabn_send_photos: `bool` + Optional. True, if the user is allowed to send photos. + can_send_videos: `bool` + Optional. True, if the user is allowed to send videos. + can_send_videos_notes: `bool` + Optional. True, if the user is allowed to send video notes. + can_send_voice_notes: `bool` + Optional. True, if the user is allowed to send voice notes. + can_send_polls: `bool` + Optional. True, if the user is allowed to send polls. + can_send_other_messages: `bool` + Optional. True, if the user is allowed to send animations, games, stickers and use inline bots. + can_add_web_page_previews: `bool` + Optional. True, if the user is allowed to add web page previews to their messages. + can_change_info: `bool` + Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups. + can_invite_users: `bool` + Optional. True, if the user is allowed to invite new users to the chat. + can_pin_messages: `bool` + Optional. True, if the user is allowed to pin messages. Ignored in public supergroups. + can_manage_topics: `bool` + Optional. True, if the user is allowed to create forum topics. If omitted defaults to the value of can_pin_messages.""" + + def __init__(self, data): + self.can_send_messages = data.get('can_send_messages') + self.can_send_audios = data.get('can_send_audios') + self.can_send_documents = data.get('can_send_documents') + self.cabn_send_photos = data.get('cabn_send_photos') + self.can_send_videos = data.get('can_send_videos') + self.can_send_videos_notes = data.get('can_send_videos_notes') + self.can_send_voice_notes = data.get('can_send_voice_notes') + self.can_send_polls = data.get('can_send_polls') + self.can_send_other_messages = data.get('can_send_other_messages') + self.can_add_web_page_previews = data.get('can_add_web_page_previews') + self.can_change_info = data.get('can_change_info') + self.can_invite_users = data.get('can_invite_users') + self.can_pin_messages = data.get('can_pin_messages') + self.can_manage_topics = data.get('can_manage_topics') + if self.can_manage_topics is None: + self.can_manage_topics = self.can_pin_messages \ No newline at end of file From ddea2af64d9e65b78759b1f3704d6c6367cfa1ac Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:45:34 +0000 Subject: [PATCH 033/113] Restyled by autopep8 --- EzTg/chatpermissions.py | 4 ++-- setup.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/EzTg/chatpermissions.py b/EzTg/chatpermissions.py index 0db9e64..9404c6e 100644 --- a/EzTg/chatpermissions.py +++ b/EzTg/chatpermissions.py @@ -1,6 +1,6 @@ class ChatPermissions: """Describes actions that a non-administrator user is allowed to take in a chat. - + Attributes ---------- can_send_messages: `bool` @@ -48,4 +48,4 @@ def __init__(self, data): self.can_pin_messages = data.get('can_pin_messages') self.can_manage_topics = data.get('can_manage_topics') if self.can_manage_topics is None: - self.can_manage_topics = self.can_pin_messages \ No newline at end of file + self.can_manage_topics = self.can_pin_messages 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 beb4c4771d291025a1dfed33cc934bd1168d96c2 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:45:36 +0000 Subject: [PATCH 034/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/chatpermissions.py | 31 +++++++++++------------ EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 5 files changed, 68 insertions(+), 65 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index d2cf988..4330e40 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,7 +97,8 @@ 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") diff --git a/EzTg/chatpermissions.py b/EzTg/chatpermissions.py index 9404c6e..7fd2739 100644 --- a/EzTg/chatpermissions.py +++ b/EzTg/chatpermissions.py @@ -30,22 +30,23 @@ class ChatPermissions: can_pin_messages: `bool` Optional. True, if the user is allowed to pin messages. Ignored in public supergroups. can_manage_topics: `bool` - Optional. True, if the user is allowed to create forum topics. If omitted defaults to the value of can_pin_messages.""" + Optional. True, if the user is allowed to create forum topics. If omitted defaults to the value of can_pin_messages. + """ def __init__(self, data): - self.can_send_messages = data.get('can_send_messages') - self.can_send_audios = data.get('can_send_audios') - self.can_send_documents = data.get('can_send_documents') - self.cabn_send_photos = data.get('cabn_send_photos') - self.can_send_videos = data.get('can_send_videos') - self.can_send_videos_notes = data.get('can_send_videos_notes') - self.can_send_voice_notes = data.get('can_send_voice_notes') - self.can_send_polls = data.get('can_send_polls') - self.can_send_other_messages = data.get('can_send_other_messages') - self.can_add_web_page_previews = data.get('can_add_web_page_previews') - self.can_change_info = data.get('can_change_info') - self.can_invite_users = data.get('can_invite_users') - self.can_pin_messages = data.get('can_pin_messages') - self.can_manage_topics = data.get('can_manage_topics') + self.can_send_messages = data.get("can_send_messages") + self.can_send_audios = data.get("can_send_audios") + self.can_send_documents = data.get("can_send_documents") + self.cabn_send_photos = data.get("cabn_send_photos") + self.can_send_videos = data.get("can_send_videos") + self.can_send_videos_notes = data.get("can_send_videos_notes") + self.can_send_voice_notes = data.get("can_send_voice_notes") + self.can_send_polls = data.get("can_send_polls") + self.can_send_other_messages = data.get("can_send_other_messages") + self.can_add_web_page_previews = data.get("can_add_web_page_previews") + self.can_change_info = data.get("can_change_info") + self.can_invite_users = data.get("can_invite_users") + self.can_pin_messages = data.get("can_pin_messages") + self.can_manage_topics = data.get("can_manage_topics") if self.can_manage_topics is None: self.can_manage_topics = self.can_pin_messages diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From 009d9ebc031394332c6dce92c7b770b307c82664 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:45:37 +0000 Subject: [PATCH 035/113] Restyled by isort --- EzTg/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 4330e40..8cbf086 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,6 +1,6 @@ +from .chatpermissions import ChatPermissions from .chatphoto import ChatPhoto from .message import Message -from .chatpermissions import ChatPermissions class Chat: From 7f93148fd55092340e22458cd5c1c6f6f937f7eb Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 14:45:39 +0000 Subject: [PATCH 036/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 8cbf086..3ee5502 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,8 +97,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 05b3a5e74584e37ebb520ff87e29c29954fbc70c Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 16:18:18 +0100 Subject: [PATCH 037/113] add ChatLocation and Location class #20 --- EzTg/chatlocation.py | 16 ++++++++++++++++ EzTg/location.py | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 EzTg/chatlocation.py create mode 100644 EzTg/location.py diff --git a/EzTg/chatlocation.py b/EzTg/chatlocation.py new file mode 100644 index 0000000..521bcdd --- /dev/null +++ b/EzTg/chatlocation.py @@ -0,0 +1,16 @@ +from .location import Location + +class ChatLocation: + """Represents a location to which a chat is connected. + + Attributes + ---------- + location: `Location` + The location to which the supergroup is connected. Can't be a live location. + address: `str` + Location address; 1-64 characters, as defined by the chat owner + """ + + def __init__(self, data): + self.location = Location(data["location"]) + self.address = data["address"] \ No newline at end of file diff --git a/EzTg/location.py b/EzTg/location.py new file mode 100644 index 0000000..0e1f234 --- /dev/null +++ b/EzTg/location.py @@ -0,0 +1,26 @@ +class Location: + """Represents a point on the map. + + Attributes + ---------- + longitude: `float` + Longitude as defined by sender + latitude: `float` + Latitude as defined by sender + horizontal_accuracy: `float` + Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + live_period: `int` + Optional. Time relative to the message sending date, during which the location can be updated, in seconds. For active live locations only. + heading: `int` + Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. + proximity_alert_radius: `int` + Optional. Maximum distance for proximity alerts about approaching another chat member, in meters. For sent live locations only. + """ + + def __init__(self, data): + self.longitude = data["longitude"] + self.latitude = data["latitude"] + self.horizontal_accuracy = data.get("horizontal_accuracy") + self.live_period = data.get("live_period") + self.heading = data.get("heading") + self.proximity_alert_radius = data.get("proximity_alert_radius") \ No newline at end of file From ac0f627619241d76fe93895bbcb2d782ea1356a1 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 16:19:01 +0100 Subject: [PATCH 038/113] implement ChatLocation in Chat class #20 --- EzTg/chat.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EzTg/chat.py b/EzTg/chat.py index d2cf988..6c821db 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,6 +1,7 @@ from .chatphoto import ChatPhoto from .message import Message from .chatpermissions import ChatPermissions +from .chatlocation import ChatLocation class Chat: @@ -104,3 +105,5 @@ def __init__(self, data: dict): self.can_set_sticker_set = data.get("can_set_sticker_set") self.linked_chat_id = data.get("linked_chat_id") self.location = data.get("location") + if self.location: + self.location = ChatLocation(self.location) From 5dd6daee8bd8df07c9319ec60f0c0887b11fba7c Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 16:21:46 +0100 Subject: [PATCH 039/113] changes for #20 --- EzTg/chat.py | 4 ++++ EzTg/chatpermissions.py | 35 ++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 6c821db..dc7a01c 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,7 +1,11 @@ +from .chatpermissions import ChatPermissions from .chatphoto import ChatPhoto from .message import Message +<<<<<<< HEAD from .chatpermissions import ChatPermissions from .chatlocation import ChatLocation +======= +>>>>>>> d4c95a189ec71e783e7604fcd1e46420e6f8c79f class Chat: diff --git a/EzTg/chatpermissions.py b/EzTg/chatpermissions.py index 0db9e64..7fd2739 100644 --- a/EzTg/chatpermissions.py +++ b/EzTg/chatpermissions.py @@ -1,6 +1,6 @@ class ChatPermissions: """Describes actions that a non-administrator user is allowed to take in a chat. - + Attributes ---------- can_send_messages: `bool` @@ -30,22 +30,23 @@ class ChatPermissions: can_pin_messages: `bool` Optional. True, if the user is allowed to pin messages. Ignored in public supergroups. can_manage_topics: `bool` - Optional. True, if the user is allowed to create forum topics. If omitted defaults to the value of can_pin_messages.""" + Optional. True, if the user is allowed to create forum topics. If omitted defaults to the value of can_pin_messages. + """ def __init__(self, data): - self.can_send_messages = data.get('can_send_messages') - self.can_send_audios = data.get('can_send_audios') - self.can_send_documents = data.get('can_send_documents') - self.cabn_send_photos = data.get('cabn_send_photos') - self.can_send_videos = data.get('can_send_videos') - self.can_send_videos_notes = data.get('can_send_videos_notes') - self.can_send_voice_notes = data.get('can_send_voice_notes') - self.can_send_polls = data.get('can_send_polls') - self.can_send_other_messages = data.get('can_send_other_messages') - self.can_add_web_page_previews = data.get('can_add_web_page_previews') - self.can_change_info = data.get('can_change_info') - self.can_invite_users = data.get('can_invite_users') - self.can_pin_messages = data.get('can_pin_messages') - self.can_manage_topics = data.get('can_manage_topics') + self.can_send_messages = data.get("can_send_messages") + self.can_send_audios = data.get("can_send_audios") + self.can_send_documents = data.get("can_send_documents") + self.cabn_send_photos = data.get("cabn_send_photos") + self.can_send_videos = data.get("can_send_videos") + self.can_send_videos_notes = data.get("can_send_videos_notes") + self.can_send_voice_notes = data.get("can_send_voice_notes") + self.can_send_polls = data.get("can_send_polls") + self.can_send_other_messages = data.get("can_send_other_messages") + self.can_add_web_page_previews = data.get("can_add_web_page_previews") + self.can_change_info = data.get("can_change_info") + self.can_invite_users = data.get("can_invite_users") + self.can_pin_messages = data.get("can_pin_messages") + self.can_manage_topics = data.get("can_manage_topics") if self.can_manage_topics is None: - self.can_manage_topics = self.can_pin_messages \ No newline at end of file + self.can_manage_topics = self.can_pin_messages From 9197ab80211e31e312f7d831d26490c7d07ae0e4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:24:30 +0000 Subject: [PATCH 040/113] Restyled by autopep8 --- EzTg/chatlocation.py | 5 +++-- EzTg/location.py | 4 ++-- setup.py | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/EzTg/chatlocation.py b/EzTg/chatlocation.py index 521bcdd..0119675 100644 --- a/EzTg/chatlocation.py +++ b/EzTg/chatlocation.py @@ -1,8 +1,9 @@ from .location import Location + class ChatLocation: """Represents a location to which a chat is connected. - + Attributes ---------- location: `Location` @@ -13,4 +14,4 @@ class ChatLocation: def __init__(self, data): self.location = Location(data["location"]) - self.address = data["address"] \ No newline at end of file + self.address = data["address"] diff --git a/EzTg/location.py b/EzTg/location.py index 0e1f234..7611f42 100644 --- a/EzTg/location.py +++ b/EzTg/location.py @@ -1,6 +1,6 @@ class Location: """Represents a point on the map. - + Attributes ---------- longitude: `float` @@ -23,4 +23,4 @@ def __init__(self, data): self.horizontal_accuracy = data.get("horizontal_accuracy") self.live_period = data.get("live_period") self.heading = data.get("heading") - self.proximity_alert_radius = data.get("proximity_alert_radius") \ No newline at end of file + self.proximity_alert_radius = data.get("proximity_alert_radius") 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 1a5453b18cf4e7640e191707004f771d08881c14 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:24:31 +0000 Subject: [PATCH 041/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 0919ef5..fb12e9b 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,7 +98,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From 7e7140a3ab9fa5a5e73f1dbb9c4f0fe0ac688749 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:24:32 +0000 Subject: [PATCH 042/113] Restyled by isort --- EzTg/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index fb12e9b..e554071 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,7 +1,7 @@ +from .chatlocation import ChatLocation from .chatpermissions import ChatPermissions from .chatphoto import ChatPhoto from .message import Message -from .chatlocation import ChatLocation class Chat: From 21bb6689e07629c548a442bb09f2787560ee59c1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:24:34 +0000 Subject: [PATCH 043/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e554071..124d360 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,8 +98,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From c770bd6e0fa20a0b7a1debe038deec0a37e9391d Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 5 Mar 2023 16:30:22 +0100 Subject: [PATCH 044/113] Message class update for Location #25 + small fix --- EzTg/message.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/EzTg/message.py b/EzTg/message.py index 8f1c4ee..13be925 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -1,5 +1,6 @@ from .chat import Chat from .user import User +from .location import Location class Message: @@ -114,7 +115,9 @@ def __init__(self, data): self.forward_date = data.get("forward_date") self.is_topic_message = data.get("is_topic_message") self.is_automatic_forward = data.get("is_automatic_forward") - self.reply_to_message = Message(data.get("reply_to_message")) + self.reply_to_message = data.get("reply_to_message") + if self.reply_to_message: + self.reply_to_message = Message(self.reply_to_message) self.via_bot = User(data.get("via_bot")) self.edit_date = data.get("edit_date") self.has_protected_content = data.get("has_protected_content") @@ -138,6 +141,8 @@ def __init__(self, data): self.poll = data.get("poll") self.venue = data.get("venue") self.location = data.get("location") + if self.location: + self.location = Location(self.location) self.new_chat_members = data.get("new_chat_members") if self.new_chat_members: self.new_chat_members = [User(x) for x in self.new_chat_members] From c47f003200c81713b7725a923b52b0198239938d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:30:31 +0000 Subject: [PATCH 045/113] Restyled by autopep8 --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 8b81df98a5a6fd4841fdd37d732b2a17925b8d4b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:30:32 +0000 Subject: [PATCH 046/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 124d360..e554071 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,7 +98,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From 5b7abded9becc98fbd0e303c25c09bb08a67177e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:30:33 +0000 Subject: [PATCH 047/113] Restyled by isort --- EzTg/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/message.py b/EzTg/message.py index 13be925..32585c0 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -1,6 +1,6 @@ from .chat import Chat -from .user import User from .location import Location +from .user import User class Message: From d5add395bb9e87c5d5e93407dc949a310b536c74 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 5 Mar 2023 15:30:35 +0000 Subject: [PATCH 048/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e554071..124d360 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,8 +98,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 6cdf58eedfe45cb0b7c868a1603891f0f12f1021 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:32:59 +0100 Subject: [PATCH 049/113] add Animation class #25 --- EzTg/animation.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 EzTg/animation.py diff --git a/EzTg/animation.py b/EzTg/animation.py new file mode 100644 index 0000000..5cd845f --- /dev/null +++ b/EzTg/animation.py @@ -0,0 +1,35 @@ +class Animation: + """Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). + + Attributes + ---------- + file_id: `str` + Identifier for this file, which can be used to download or reuse the file. + file_unique_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + width: `int` + Video width as defined by sender. + height: `int` + Video height as defined by sender. + duration: `int` + Duration of the video in seconds as defined by sender. + thumb: `PhotoSize` + Optional. Animation thumbnail as defined by sender. + file_name: `str` + Optional. Original animation filename as defined by sender. + mime_type: `str` + Optional. MIME type of the file as defined by sender. + file_size: `int` + Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. + """ + + def __init__(self, data): + self.file_id = data['file_id'] + self.file_unique_id = data['file_unique_id'] + self.width = data['width'] + self.height = data['height'] + self.duration = data['duration'] + self.thumb = PhotoSize(data['thumb']) if 'thumb' in data else None + self.file_name = data['file_name'] if 'file_name' in data else None + self.mime_type = data['mime_type'] if 'mime_type' in data else None + self.file_size = data['file_size'] if 'file_size' in data else None From 9ffb2635e930fd8a29e59c76e396966e1081407a Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:35:30 +0100 Subject: [PATCH 050/113] add PhotoSize for Animation class #25 --- EzTg/animation.py | 12 ++++++++---- EzTg/photosize.py | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 EzTg/photosize.py diff --git a/EzTg/animation.py b/EzTg/animation.py index 5cd845f..77c57f0 100644 --- a/EzTg/animation.py +++ b/EzTg/animation.py @@ -1,3 +1,5 @@ +from .photo_size import PhotoSize + class Animation: """Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). @@ -29,7 +31,9 @@ def __init__(self, data): self.width = data['width'] self.height = data['height'] self.duration = data['duration'] - self.thumb = PhotoSize(data['thumb']) if 'thumb' in data else None - self.file_name = data['file_name'] if 'file_name' in data else None - self.mime_type = data['mime_type'] if 'mime_type' in data else None - self.file_size = data['file_size'] if 'file_size' in data else None + self.thumb = data.get('thumb') + if self.thumb: + self.thumb = PhotoSize(self.thumb) + self.file_name = data.get('file_name') + self.mime_type = data.get('mime_type') + self.file_size = data.get('file_size') diff --git a/EzTg/photosize.py b/EzTg/photosize.py new file mode 100644 index 0000000..20ee379 --- /dev/null +++ b/EzTg/photosize.py @@ -0,0 +1,24 @@ +class PhotoSize: + """Represents one size of a photo or a file / sticker thumbnail. + + Attributes + ---------- + + file_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + file_unique_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + width: `int` + Photo width. + height: `int` + Photo height. + file_size: `int` + Optional. File size. + """ + + def __init__(self, data): + self.file_id = data['file_id'] + self.file_unique_id = data['file_unique_id'] + self.width = data['width'] + self.height = data['height'] + self.file_size = data.get('file_size') \ No newline at end of file From a5c61694e6122119dab2e6278a375a89322462ce Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:35:38 +0000 Subject: [PATCH 051/113] Restyled by autopep8 --- EzTg/animation.py | 3 ++- EzTg/photosize.py | 8 ++++---- setup.py | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/EzTg/animation.py b/EzTg/animation.py index 77c57f0..d3b348e 100644 --- a/EzTg/animation.py +++ b/EzTg/animation.py @@ -1,8 +1,9 @@ from .photo_size import PhotoSize + class Animation: """Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). - + Attributes ---------- file_id: `str` diff --git a/EzTg/photosize.py b/EzTg/photosize.py index 20ee379..13933a3 100644 --- a/EzTg/photosize.py +++ b/EzTg/photosize.py @@ -1,9 +1,9 @@ class PhotoSize: """Represents one size of a photo or a file / sticker thumbnail. - + Attributes ---------- - + file_id: `str` Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. file_unique_id: `str` @@ -15,10 +15,10 @@ class PhotoSize: file_size: `int` Optional. File size. """ - + def __init__(self, data): self.file_id = data['file_id'] self.file_unique_id = data['file_unique_id'] self.width = data['width'] self.height = data['height'] - self.file_size = data.get('file_size') \ No newline at end of file + self.file_size = data.get('file_size') 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 4bf9be55df54cd742ffaaecb9d8aac80884805c9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:35:40 +0000 Subject: [PATCH 052/113] Restyled by black --- EzTg/animation.py | 18 +++++++------- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/photosize.py | 10 ++++---- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 6 files changed, 66 insertions(+), 64 deletions(-) diff --git a/EzTg/animation.py b/EzTg/animation.py index d3b348e..ee3076d 100644 --- a/EzTg/animation.py +++ b/EzTg/animation.py @@ -27,14 +27,14 @@ class Animation: """ def __init__(self, data): - self.file_id = data['file_id'] - self.file_unique_id = data['file_unique_id'] - self.width = data['width'] - self.height = data['height'] - self.duration = data['duration'] - self.thumb = data.get('thumb') + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.width = data["width"] + self.height = data["height"] + self.duration = data["duration"] + self.thumb = data.get("thumb") if self.thumb: self.thumb = PhotoSize(self.thumb) - self.file_name = data.get('file_name') - self.mime_type = data.get('mime_type') - self.file_size = data.get('file_size') + self.file_name = data.get("file_name") + self.mime_type = data.get("mime_type") + self.file_size = data.get("file_size") diff --git a/EzTg/chat.py b/EzTg/chat.py index 124d360..e554071 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,7 +98,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/photosize.py b/EzTg/photosize.py index 13933a3..f4081db 100644 --- a/EzTg/photosize.py +++ b/EzTg/photosize.py @@ -17,8 +17,8 @@ class PhotoSize: """ def __init__(self, data): - self.file_id = data['file_id'] - self.file_unique_id = data['file_unique_id'] - self.width = data['width'] - self.height = data['height'] - self.file_size = data.get('file_size') + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.width = data["width"] + self.height = data["height"] + self.file_size = data.get("file_size") diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From dc696505d18f96a2c149b645390427ff7d5d1e05 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:35:43 +0000 Subject: [PATCH 053/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e554071..124d360 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,8 +98,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 6df2ba3ac7086ce3ac4b80165bae63ea52e7fa81 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:38:45 +0100 Subject: [PATCH 054/113] fix photosize import --- EzTg/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EzTg/animation.py b/EzTg/animation.py index 77c57f0..b9f5fb4 100644 --- a/EzTg/animation.py +++ b/EzTg/animation.py @@ -1,4 +1,4 @@ -from .photo_size import PhotoSize +from .photosize import PhotoSize class Animation: """Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). From cdf10513ae81fb4bf486cf72b4153d7d0a9aa6ea Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:42:13 +0100 Subject: [PATCH 055/113] add Audio class #25 --- EzTg/audio.py | 40 ++++++++++++++++++++++++++++++++++++++++ EzTg/message.py | 6 ++++++ 2 files changed, 46 insertions(+) create mode 100644 EzTg/audio.py diff --git a/EzTg/audio.py b/EzTg/audio.py new file mode 100644 index 0000000..aac7d77 --- /dev/null +++ b/EzTg/audio.py @@ -0,0 +1,40 @@ +from .photosize import PhotoSize + +class Audio: + """Represents an audio file to be treated as music by the Telegram clients. + + Attributes + ---------- + file_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + file_unique_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + duration: `int` + Duration of the audio in seconds as defined by sender. + performer: `str` + Optional. Performer of the audio as defined by sender or by audio tags. + title: `str` + Optional. Title of the audio as defined by sender or by audio tags. + file_name: `str` + Optional. Original filename as defined by sender. + mime_type: `str` + Optional. MIME type of the file as defined by sender. + file_size: `int` + Optional. File size. + thumb: `PhotoSize` + Optional. Thumbnail of the album cover to which the music file belongs. + """ + + def __init__(self, data): + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.duration = data["duration"] + self.performer = data.get("performer") + self.title = data.get("title") + self.file_name = data.get("file_name") + self.mime_type = data.get("mime_type") + self.file_size = data.get("file_size") + self.thumb = data.get("thumb") + if self.thumb: + self.thumb = PhotoSize(self.thumb) + \ No newline at end of file diff --git a/EzTg/message.py b/EzTg/message.py index 32585c0..fe4d074 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -1,3 +1,5 @@ +from .animation import Animation +from .audio import Audio from .chat import Chat from .location import Location from .user import User @@ -125,7 +127,11 @@ def __init__(self, data): self.author_signature = data.get("author_signature") self.text = data.get("text") self.animation = data.get("animation") + if self.animation: + self.animation = Animation(self.animation) self.audio = data.get("audio") + if self.audio: + self.audio = Audio(self.audio) self.document = data.get("document") self.photo = data.get("photo") self.sticker = data.get("sticker") From a457f162672364492a10c6cb5c3f2e660b821960 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:42:21 +0000 Subject: [PATCH 056/113] Restyled by autopep8 --- EzTg/audio.py | 4 ++-- setup.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/EzTg/audio.py b/EzTg/audio.py index aac7d77..d469a05 100644 --- a/EzTg/audio.py +++ b/EzTg/audio.py @@ -1,8 +1,9 @@ from .photosize import PhotoSize + class Audio: """Represents an audio file to be treated as music by the Telegram clients. - + Attributes ---------- file_id: `str` @@ -37,4 +38,3 @@ def __init__(self, data): self.thumb = data.get("thumb") if self.thumb: self.thumb = PhotoSize(self.thumb) - \ No newline at end of file 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 153f14a98c2212dbaf3002721155d34a69daac92 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:42:23 +0000 Subject: [PATCH 057/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 124d360..e554071 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,7 +98,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From 06c80fa5bc670ec28948ca80cce8028cc032d45f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:42:26 +0000 Subject: [PATCH 058/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e554071..124d360 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,8 +98,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From c32eded12109dabf926d0f4d9582e2a978850fd2 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:45:52 +0100 Subject: [PATCH 059/113] add Document class #25 --- EzTg/document.py | 30 ++++++++++++++++++++++++++++++ EzTg/message.py | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 EzTg/document.py diff --git a/EzTg/document.py b/EzTg/document.py new file mode 100644 index 0000000..4c55d12 --- /dev/null +++ b/EzTg/document.py @@ -0,0 +1,30 @@ +from .photosize import PhotoSize + +class Document: + """Represents a general file (as opposed to photos, voice messages and audio files). + + Attributes + ---------- + file_id: `str` + Unique file identifier. + file_unique_id: `str` + Unique file identifier. + thumb: `PhotoSize` + Optional. Document thumbnail as defined by sender. + file_name: `str` + Optional. Original filename as defined by sender. + mime_type: `str` + Optional. MIME type of the file as defined by sender. + file_size: `int` + Optional. File size. + """ + + def __init__(self, data): + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.thumb = data.get("thumb") + if self.thumb: + self.thumb = PhotoSize(self.thumb) + self.file_name = data.get("file_name") + self.mime_type = data.get("mime_type") + self.file_size = data.get("file_size") \ No newline at end of file diff --git a/EzTg/message.py b/EzTg/message.py index fe4d074..fbbca30 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -1,6 +1,7 @@ from .animation import Animation from .audio import Audio from .chat import Chat +from .document import Document from .location import Location from .user import User @@ -133,6 +134,8 @@ def __init__(self, data): if self.audio: self.audio = Audio(self.audio) self.document = data.get("document") + if self.document: + self.document = Document(self.document) self.photo = data.get("photo") self.sticker = data.get("sticker") self.video = data.get("video") From e03c3669bca4d55b1e64369fe828ddaf044507e0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:46:01 +0000 Subject: [PATCH 060/113] Restyled by autopep8 --- EzTg/document.py | 7 ++++--- setup.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/EzTg/document.py b/EzTg/document.py index 4c55d12..63dc1a8 100644 --- a/EzTg/document.py +++ b/EzTg/document.py @@ -1,8 +1,9 @@ from .photosize import PhotoSize + class Document: """Represents a general file (as opposed to photos, voice messages and audio files). - + Attributes ---------- file_id: `str` @@ -18,7 +19,7 @@ class Document: file_size: `int` Optional. File size. """ - + def __init__(self, data): self.file_id = data["file_id"] self.file_unique_id = data["file_unique_id"] @@ -27,4 +28,4 @@ def __init__(self, data): self.thumb = PhotoSize(self.thumb) self.file_name = data.get("file_name") self.mime_type = data.get("mime_type") - self.file_size = data.get("file_size") \ No newline at end of file + self.file_size = data.get("file_size") 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 dac4802972b4b73b3b0b7d6f8ed913f33c63db8e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:46:03 +0000 Subject: [PATCH 061/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 124d360..e554071 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,7 +98,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From a1ea4f01fbc8f1ff1a94b724f8a3be218a1e3477 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 6 Mar 2023 17:46:06 +0000 Subject: [PATCH 062/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e554071..124d360 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,8 +98,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 99632c6a0de4ebfbe05dc238917242079bdc5ce7 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:48:32 +0100 Subject: [PATCH 063/113] little message class fix #25 --- EzTg/message.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/EzTg/message.py b/EzTg/message.py index fbbca30..33b4d09 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -3,6 +3,7 @@ from .chat import Chat from .document import Document from .location import Location +from .photosize import PhotoSize from .user import User @@ -137,6 +138,8 @@ def __init__(self, data): if self.document: self.document = Document(self.document) self.photo = data.get("photo") + if self.photo: + self.photo = [PhotoSize(p) for p in self.photo] self.sticker = data.get("sticker") self.video = data.get("video") self.video_note = data.get("video_note") @@ -159,3 +162,8 @@ def __init__(self, data): if self.left_chat_member: self.left_chat_member = User(self.left_chat_member) self.new_chat_title = data.get("new_chat_title") + self.new_chat_photo = data.get("new_chat_photo") + if self.new_chat_photo: + self.new_chat_photo = [PhotoSize(p) for p in self.new_chat_photo] + self.delete_chat_photo = data.get("delete_chat_photo") + self.group_chat_created = data.get("group_chat_created") From 31c9e83a87af027a81b350311437bc9c24f9c1bb Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Tue, 7 Mar 2023 17:34:41 +0100 Subject: [PATCH 064/113] add jetbrains contribuition --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e318eb7..914645a 100644 --- a/README.rst +++ b/README.rst @@ -14,4 +14,6 @@ EzTg Python api wrapper for telegram, easy to clearly choose every parameter for the method you are calling. Telegram support group: https://t.me/EzTg_Api -Telergam core api: https://core.telegram.org/bots/api \ No newline at end of file +Telergam core api: https://core.telegram.org/bots/api + +![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png) \ No newline at end of file From 587b1c52ac33126c74fad1501079aa159451172e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:36:19 +0000 Subject: [PATCH 065/113] Restyled by autopep8 --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 bbe25d0eaf5592f6258ea25ca542038cbe6d137c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:36:22 +0000 Subject: [PATCH 066/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 124d360..e554071 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,7 +98,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From a6f0fb36b92924abc9d399390bb0dd7cf9efd01a Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:36:25 +0000 Subject: [PATCH 067/113] Restyled by whitespace --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 914645a..4ce7566 100644 --- a/README.rst +++ b/README.rst @@ -16,4 +16,4 @@ Python api wrapper for telegram, easy to clearly choose every parameter for the Telegram support group: https://t.me/EzTg_Api Telergam core api: https://core.telegram.org/bots/api -![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png) \ No newline at end of file +![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png) From 3ba8f5f44b44f55668c341d65d5e9c22931a5b0e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:36:26 +0000 Subject: [PATCH 068/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index e554071..124d360 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -79,12 +79,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") @@ -98,8 +98,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 6ef71cd0f4a150951bcfc2b5cde840c2e6e433ba Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Tue, 7 Mar 2023 17:38:37 +0100 Subject: [PATCH 069/113] Update README.rst --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 4ce7566..42ff965 100644 --- a/README.rst +++ b/README.rst @@ -16,4 +16,6 @@ Python api wrapper for telegram, easy to clearly choose every parameter for the Telegram support group: https://t.me/EzTg_Api Telergam core api: https://core.telegram.org/bots/api -![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png) +.. image:: https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png + :target: https://jb.gg/OpenSourceSupport + :alt: JetBrains Logo (Main) logo From 877ce9840c07c7e07134ca4159b1b52448b499ca Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Tue, 7 Mar 2023 17:57:46 +0100 Subject: [PATCH 070/113] solve ciruclar import + add Video class #25 --- EzTg/chat.py | 11 +++++------ EzTg/video.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 EzTg/video.py diff --git a/EzTg/chat.py b/EzTg/chat.py index 124d360..352de22 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -1,9 +1,3 @@ -from .chatlocation import ChatLocation -from .chatpermissions import ChatPermissions -from .chatphoto import ChatPhoto -from .message import Message - - class Chat: """Represents a telegram chat. @@ -68,6 +62,11 @@ class Chat: """ def __init__(self, data: dict): + from .chatlocation import ChatLocation + from .chatpermissions import ChatPermissions + from .chatphoto import ChatPhoto + from .message import Message + self.id = data["id"] self.type = data["type"] self.title = data.get("title") diff --git a/EzTg/video.py b/EzTg/video.py new file mode 100644 index 0000000..37dd056 --- /dev/null +++ b/EzTg/video.py @@ -0,0 +1,40 @@ +from .photosize import PhotoSize + +class Video: + """Represents a video file. + + Attributes + ---------- + file_id: `str` + Unique identifier for this file. + file_unique_id: `str` + Unique identifier for this file. + width: `int` + Video width as defined by sender. + height: `int` + Video height as defined by sender. + duration: `int` + Duration of the video in seconds as defined by sender. + thumb: `PhotoSize` + Optional. Video thumbnail. + file_name: `str` + Optional. Original filename as defined by sender. + mime_type: `str` + Optional. MIME type of the file as defined by sender. + file_size: `int` + Optional. File size. + """ + + def __init__(self, data): + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.width = data["width"] + self.height = data["height"] + self.duration = data["duration"] + self.thumb = data.get("thumb") + if self.thumb: + self.thumb = PhotoSize(self.thumb) + self.file_name = data.get("file_name") + self.mime_type = data.get("mime_type") + self.file_size = data.get("file_size") + \ No newline at end of file From 39d3604afa3892b6ad8da3ba51bf0e5e549dcc6f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:57:56 +0000 Subject: [PATCH 071/113] Restyled by autopep8 --- EzTg/chat.py | 2 +- EzTg/video.py | 4 ++-- setup.py | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 352de22..ea294d9 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -66,7 +66,7 @@ def __init__(self, data: dict): from .chatpermissions import ChatPermissions from .chatphoto import ChatPhoto from .message import Message - + self.id = data["id"] self.type = data["type"] self.title = data.get("title") diff --git a/EzTg/video.py b/EzTg/video.py index 37dd056..ce3936b 100644 --- a/EzTg/video.py +++ b/EzTg/video.py @@ -1,8 +1,9 @@ from .photosize import PhotoSize + class Video: """Represents a video file. - + Attributes ---------- file_id: `str` @@ -37,4 +38,3 @@ def __init__(self, data): self.file_name = data.get("file_name") self.mime_type = data.get("mime_type") self.file_size = data.get("file_size") - \ No newline at end of file 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 24f632588370924e2e647c12000ff595d2478cf3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:57:57 +0000 Subject: [PATCH 072/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index ea294d9..0bdbebc 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,7 +97,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From 6a24a4077872124bd479c2fbeb3e4bb50d34cf5d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 Mar 2023 16:58:01 +0000 Subject: [PATCH 073/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 0bdbebc..ea294d9 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,8 +97,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 52afdad588d452bbf7941d7f1be3724cda152907 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Tue, 7 Mar 2023 18:03:09 +0100 Subject: [PATCH 074/113] fix docs and add replymarkupkeyboard to setup --- EzTg/__init__.py | 1 + docs/EzTg.rst | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/EzTg/__init__.py b/EzTg/__init__.py index 8830041..e046e72 100644 --- a/EzTg/__init__.py +++ b/EzTg/__init__.py @@ -3,3 +3,4 @@ from .inlinekeyboard import InlineKeyboard from .main import TelegramClient +from .replykeyboardmarkup import ReplyKeyboardMarkup diff --git a/docs/EzTg.rst b/docs/EzTg.rst index 279a19b..c126e01 100644 --- a/docs/EzTg.rst +++ b/docs/EzTg.rst @@ -20,6 +20,14 @@ EzTg.main module :undoc-members: :show-inheritance: +EzTg.replykeyboardmarkup module +------------------------------- + +.. automodule:: EzTg.replykeyboardmarkup + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- From 4f91912c8983916c280355c7820f23cffda23811 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Tue, 7 Mar 2023 18:06:08 +0100 Subject: [PATCH 075/113] edit docs config --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 52d0a92..6d12a10 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,7 @@ project = "EzTg" copyright = "2022, Hexye" author = "Hexye" -release = "0.2.0" +release = "0.3.2" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration From e9265b82e2b37f1e1ff0fef5576a6a410933b4fd Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:10:47 +0100 Subject: [PATCH 076/113] testing shi --- EzTg/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/EzTg/__init__.py b/EzTg/__init__.py index e046e72..bfcf398 100644 --- a/EzTg/__init__.py +++ b/EzTg/__init__.py @@ -1,6 +1,18 @@ __title__ = "EzTg" __author__ = "Hexye" +from .animation import Animation +from .audio import Audio +from .chat import Chat +from .chatlocation import ChatLocation +from .chatpermissions import ChatPermissions +from .chatphoto import ChatPhoto +from .document import Document from .inlinekeyboard import InlineKeyboard +from .location import Location from .main import TelegramClient +from .message import Message +from .photosize import PhotoSize from .replykeyboardmarkup import ReplyKeyboardMarkup +from .user import User +from .video import Video From e17b39e8f2a948574798479e3536f60039501d0b Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:15:55 +0100 Subject: [PATCH 077/113] trying other shi --- __pycache__/setup.cpython-311.pyc | Bin 1448 -> 1359 bytes docs/EzTg.rst | 96 ++++++++++++++++++++++++++++++ docs/setup.rst | 7 +++ 3 files changed, 103 insertions(+) create mode 100644 docs/setup.rst diff --git a/__pycache__/setup.cpython-311.pyc b/__pycache__/setup.cpython-311.pyc index e2d65c56bd6879b08a5a85fcfdbc0cf5d81d2390..2d1dadcf77f2ebc8ba06f6782c6c9112fd284786 100644 GIT binary patch delta 345 zcmXv|Jxjw-6umbee!Mod6$@4zf|~`CqJz*y1*Jp5MW@mw_CC{;nuO$4AxlSR$>8qb z2kPVx@F&<&I=Q+?!A%f+Q9Rsp;atwSoZH+BGj0rnfyDOKbLacQs0`auTmk`MA6h_4 z3l-qdQ!-NqQb{A7rf8ZY&Co0{%2D1!7s$9mQeC71%~8=+9!l2*fP2Y5p!|6NtMl)f z+)o~NeA5X%^DJ`0kVocm5SfCfP26ORH9XNB9M#SA11n8_YVRe7E@QhvXK=!O;RrAA z>t*J#`^E!4nDJTU)8j&EvG}RQeBb~CF66sCMqJnLTU6r6Acy`>IjN&P)yhKo*peq F+Yi_ES@Zw^ delta 514 zcmZusJ4gdT5S`iEOU%VH#xFq;#7cx<0$SM$RyNusojU6o33uTxl8;5Svl3$jZ3MB1 zO02Z9v$RveLawsZE`Ew&OV_MBmv=Lz&Fai6O>BD<2wT2|U|xs?&7 z%NCbhZi_jxb$O+$HVaPR)f@00tE}^Wzern|lxbA Date: Fri, 24 Mar 2023 21:42:58 +0100 Subject: [PATCH 078/113] trying shi again --- docs/conf.py | 2 +- docs/setup.rst | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 docs/setup.rst diff --git a/docs/conf.py b/docs/conf.py index 6d12a10..c2f0989 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ extensions = ["sphinx.ext.autodoc", "sphinx.ext.todo", "sphinx.ext.viewcode"] templates_path = ["_templates"] -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "setup.py"] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output diff --git a/docs/setup.rst b/docs/setup.rst deleted file mode 100644 index 552eb49..0000000 --- a/docs/setup.rst +++ /dev/null @@ -1,7 +0,0 @@ -setup module -============ - -.. automodule:: setup - :members: - :undoc-members: - :show-inheritance: From def61518521a924d3642e46b355436eadd29b8b4 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:47:48 +0100 Subject: [PATCH 079/113] add VideoNote class #25 --- EzTg/message.py | 3 +++ EzTg/videonote.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 EzTg/videonote.py diff --git a/EzTg/message.py b/EzTg/message.py index 33b4d09..14c195a 100644 --- a/EzTg/message.py +++ b/EzTg/message.py @@ -5,6 +5,7 @@ from .location import Location from .photosize import PhotoSize from .user import User +from .videonote import VideoNote class Message: @@ -143,6 +144,8 @@ def __init__(self, data): self.sticker = data.get("sticker") self.video = data.get("video") self.video_note = data.get("video_note") + if self.video_note: + self.video_note = VideoNote(self.video_note) self.voice = data.get("voice") self.caption = data.get("caption") self.caption_entities = data.get("caption_entities") diff --git a/EzTg/videonote.py b/EzTg/videonote.py new file mode 100644 index 0000000..d5a7eb0 --- /dev/null +++ b/EzTg/videonote.py @@ -0,0 +1,29 @@ +from .photosize import PhotoSize + +class VideoNote: + """Represents a video message (available in Telegram apps as of v.4.0). + + Attributes: + file_id: `str` + Unique identifier for this file. + file_unique_id: `str` + Unique file identifier, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + length: `int` + Video width and height as defined by sender. + duration: `int` + Duration of the video in seconds as defined by sender. + thumb: `PhotoSize` + Optional. Video thumbnail. + file_size: `int` + Optional. File size. + """ + + def __init__(self, data): + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.length = data["length"] + self.duration = data["duration"] + self.thumb = data.get("thumb") + if self.thumb: + self.thumb = PhotoSize(self.thumb) + self.file_size = data.get("file_size") \ No newline at end of file From 442bba3a4faea2dbe3ccc8e8d0c976615601ffb0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:47:59 +0000 Subject: [PATCH 080/113] Restyled by autopep8 --- EzTg/videonote.py | 5 +++-- setup.py | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/EzTg/videonote.py b/EzTg/videonote.py index d5a7eb0..b6d3052 100644 --- a/EzTg/videonote.py +++ b/EzTg/videonote.py @@ -1,8 +1,9 @@ from .photosize import PhotoSize + class VideoNote: """Represents a video message (available in Telegram apps as of v.4.0). - + Attributes: file_id: `str` Unique identifier for this file. @@ -26,4 +27,4 @@ def __init__(self, data): self.thumb = data.get("thumb") if self.thumb: self.thumb = PhotoSize(self.thumb) - self.file_size = data.get("file_size") \ No newline at end of file + self.file_size = data.get("file_size") 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 b81e5d6e7e1fbe8a92511c09e05d7b458cd45589 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:48:00 +0000 Subject: [PATCH 081/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index ea294d9..0bdbebc 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,7 +97,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From f6806bd97ed6df406974a44d159d69eea4d2139f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:48:03 +0000 Subject: [PATCH 082/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 0bdbebc..ea294d9 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,8 +97,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From a975f681adfd9d788398d048885b89067c1ce631 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:54:06 +0100 Subject: [PATCH 083/113] Update README.rst --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 42ff965..c41e899 100644 --- a/README.rst +++ b/README.rst @@ -15,6 +15,7 @@ Python api wrapper for telegram, easy to clearly choose every parameter for the Telegram support group: https://t.me/EzTg_Api Telergam core api: https://core.telegram.org/bots/api +EzTg Documentation: https://EzTg.readthedocs.io .. image:: https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png :target: https://jb.gg/OpenSourceSupport From e89973ad9b73eb324c6360827b4a44f44265aa5e Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:56:25 +0100 Subject: [PATCH 084/113] Update SECURITY.md --- SECURITY.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index d5d8a31..8d5bf64 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,13 +2,11 @@ ## Supported Versions -Use this section to tell people about which versions of your project are -currently being supported with security updates. -| Version | Supported | -| ------- | ------------------ | -| 0.2.2 | :white_check_mark: | -| < 0.2.2 | :x: | +| Version | Supported | EndOfSupport | +| ------- | ------------------ | ---------- | +| 0.2.2 | :white_check_mark: | 30/12/2023 | +| < 0.2.2 | :x: | xx/xx/xxxx | ## Reporting a Vulnerability From d7aeb844d674317e846f8cf1cc3003f9884a55de Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:57:44 +0100 Subject: [PATCH 085/113] Update README.rst --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index c41e899..a77d18a 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,9 @@ EzTg Python api wrapper for telegram, easy to clearly choose every parameter for the method you are calling. Telegram support group: https://t.me/EzTg_Api + Telergam core api: https://core.telegram.org/bots/api + EzTg Documentation: https://EzTg.readthedocs.io .. image:: https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png From fc4437d98e61a2cfae6cfc0c70d12fa94d2d21ba Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:57:51 +0000 Subject: [PATCH 086/113] Restyled by autopep8 --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 7ff5be0faacb96e68fbc295698483d266ca266cb Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:57:53 +0000 Subject: [PATCH 087/113] Restyled by black --- EzTg/chat.py | 9 ++++--- EzTg/main.py | 49 ++++++++++++++++++------------------- EzTg/replykeyboardmarkup.py | 41 +++++++++++++++++-------------- EzTg/user.py | 3 +-- 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index ea294d9..0bdbebc 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,7 +97,8 @@ 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") diff --git a/EzTg/main.py b/EzTg/main.py index bd445bc..1230184 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,13 +6,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__ @@ -24,10 +29,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 @@ -42,9 +48,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) @@ -131,9 +137,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, @@ -191,11 +195,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 @@ -337,10 +339,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 @@ -368,9 +367,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index 8845380..ddde8c8 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -24,15 +23,17 @@ def add( request_poll=False, web_app=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, @@ -45,15 +46,17 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -36,6 +36,5 @@ 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") From 13a19f7f02efb965891782ba287d51a417d069e0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:57:55 +0000 Subject: [PATCH 088/113] Restyled by prettier-markdown --- SECURITY.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 8d5bf64..eb33169 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,11 +2,10 @@ ## Supported Versions - -| Version | Supported | EndOfSupport | -| ------- | ------------------ | ---------- | -| 0.2.2 | :white_check_mark: | 30/12/2023 | -| < 0.2.2 | :x: | xx/xx/xxxx | +| Version | Supported | EndOfSupport | +| ------- | ------------------ | ------------ | +| 0.2.2 | :white_check_mark: | 30/12/2023 | +| < 0.2.2 | :x: | xx/xx/xxxx | ## Reporting a Vulnerability From 023f6ddced71527d61336f8ffbc84c283ae5f79f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 Mar 2023 20:57:57 +0000 Subject: [PATCH 089/113] Restyled by yapf --- EzTg/chat.py | 9 +++---- EzTg/main.py | 49 +++++++++++++++++++------------------ EzTg/replykeyboardmarkup.py | 41 ++++++++++++++----------------- EzTg/user.py | 3 ++- setup.py | 3 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/EzTg/chat.py b/EzTg/chat.py index 0bdbebc..ea294d9 100644 --- a/EzTg/chat.py +++ b/EzTg/chat.py @@ -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") @@ -97,8 +97,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") diff --git a/EzTg/main.py b/EzTg/main.py index 1230184..bd445bc 100644 --- a/EzTg/main.py +++ b/EzTg/main.py @@ -6,18 +6,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__ @@ -29,11 +24,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 @@ -48,9 +42,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) @@ -137,7 +131,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, @@ -195,9 +191,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 @@ -339,7 +337,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 @@ -367,9 +368,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/EzTg/replykeyboardmarkup.py b/EzTg/replykeyboardmarkup.py index ddde8c8..8845380 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -23,17 +24,15 @@ def add( request_poll=False, web_app=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, @@ -46,17 +45,15 @@ def add_new_row( web_app=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 { diff --git a/EzTg/user.py b/EzTg/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/user.py +++ b/EzTg/user.py @@ -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") 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/", From 8b47904a6f65f0f283c376fef6b18cba49c36f28 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 26 Mar 2023 18:30:50 +0200 Subject: [PATCH 090/113] restyle (hope docs work) --- EzTg/{main.py => EzTg.py} | 39 ++++++++---------- EzTg/__init__.py | 22 +++++----- EzTg/types/__init__.py | 3 ++ EzTg/types/chat/__init__.py | 4 ++ EzTg/{ => types/chat}/chat.py | 16 ++++--- .../chat/location.py} | 2 +- .../chat/permissions.py} | 0 EzTg/{chatphoto.py => types/chat/photo.py} | 0 EzTg/{ => types}/inlinekeyboard.py | 0 EzTg/{ => types}/location.py | 0 EzTg/types/message/__init__.py | 6 +++ EzTg/{ => types/message}/animation.py | 0 EzTg/{ => types/message}/audio.py | 0 EzTg/{ => types/message}/document.py | 0 EzTg/{ => types/message}/message.py | 6 +-- EzTg/{ => types/message}/photosize.py | 0 EzTg/{ => types/message}/video.py | 0 EzTg/{ => types/message}/videonote.py | 0 EzTg/{ => types}/replykeyboardmarkup.py | 2 + EzTg/types/user/__init__.py | 1 + EzTg/{ => types/user}/user.py | 0 __pycache__/setup.cpython-311.pyc | Bin 1359 -> 0 bytes 22 files changed, 56 insertions(+), 45 deletions(-) rename EzTg/{main.py => EzTg.py} (94%) create mode 100644 EzTg/types/__init__.py create mode 100644 EzTg/types/chat/__init__.py rename EzTg/{ => types/chat}/chat.py (92%) rename EzTg/{chatlocation.py => types/chat/location.py} (93%) rename EzTg/{chatpermissions.py => types/chat/permissions.py} (100%) rename EzTg/{chatphoto.py => types/chat/photo.py} (100%) rename EzTg/{ => types}/inlinekeyboard.py (100%) rename EzTg/{ => types}/location.py (100%) create mode 100644 EzTg/types/message/__init__.py rename EzTg/{ => types/message}/animation.py (100%) rename EzTg/{ => types/message}/audio.py (100%) rename EzTg/{ => types/message}/document.py (100%) rename EzTg/{ => types/message}/message.py (98%) rename EzTg/{ => types/message}/photosize.py (100%) rename EzTg/{ => types/message}/video.py (100%) rename EzTg/{ => types/message}/videonote.py (100%) rename EzTg/{ => types}/replykeyboardmarkup.py (93%) create mode 100644 EzTg/types/user/__init__.py rename EzTg/{ => types/user}/user.py (100%) delete mode 100644 __pycache__/setup.cpython-311.pyc diff --git a/EzTg/main.py b/EzTg/EzTg.py similarity index 94% rename from EzTg/main.py rename to EzTg/EzTg.py index bd445bc..577846b 100644 --- a/EzTg/main.py +++ b/EzTg/EzTg.py @@ -1,8 +1,7 @@ import aiohttp -import requests -from .chat import Chat -from .user import User +from .types.chat.chat import Chat +from .types.user.user import User class Parse(dict): @@ -26,12 +25,8 @@ class TokenError(Exception): class TelegramClient: def __init__(self, token): - 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 - self.api = "https://api.telegram.org/bot{}/{}" + self.token = token + self.api = "https://api.telegram.org/bot{}/{}" async def send(self, method, **kwargs): """Send a request to the telegram api. @@ -57,6 +52,8 @@ async def start_polling(self, callback, callback_query=None): The function you want to call when a message is received. callback_query: `function` The function you want to call when a callback query is received.""" + if self.send("getMe").ok == False: + raise TokenError("The token you provided is wrong") offset = None while 1: update = await self.send("getUpdates", offset=offset) @@ -71,7 +68,7 @@ async def start_polling(self, callback, callback_query=None): await callback_query(x) offset = update[-1].update_id + 1 - async def sendMessage( + async def send_message( self, chat_id, text, @@ -122,7 +119,7 @@ async def sendMessage( reply_to_message_id=reply_to_message_id, ) - async def deleteMessage(self, chat_id, message_id): + async def delete_message(self, chat_id, message_id): """Delete a message. Parameters @@ -135,7 +132,7 @@ async def deleteMessage(self, chat_id, message_id): chat_id=chat_id, message_id=message_id) - async def editMessageText( + async def edit_message_text( self, chat_id, message_id, @@ -191,7 +188,7 @@ async def editMessageText( disable_web_page_preview=disable_web_page_preview, ) - async def forwardMessage(self, + async def forward_message(self, chat_id, from_chat_id, message_id, @@ -217,7 +214,7 @@ async def forwardMessage(self, disable_notification=disable_notification, ) - async def getMe(self): + async def get_me(self): """Get information about the bot.""" r = await self.send("getMe") user = User( @@ -235,7 +232,7 @@ async def getMe(self): ) return user - async def copyMessage( + async def copy_message( self, chat_id, message_id, @@ -286,7 +283,7 @@ async def copyMessage( allow_sending_without_reply=allow_sending_without_reply, ) - async def exportChatInviteLink(self, chat_id): + async def export_chat_invite_link(self, chat_id): """Export a chat invite link. Parameters @@ -295,7 +292,7 @@ async def exportChatInviteLink(self, chat_id): The chat id you want to make the invite link.""" return await self.send("exportChatInviteLink", chat_id=chat_id) - async def createChatInviteLink( + async def create_chat_invite_link( self, chat_id, name=None, @@ -326,7 +323,7 @@ async def createChatInviteLink( creates_join_request=creates_join_request, ) - async def setChatPhoto(self, chat_id, photo): + async def set_chat_photo(self, chat_id, photo): """Set the chat photo. Parameters @@ -337,7 +334,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, + async def pin_chat_message(self, chat_id, message_id, disable_notification=False): @@ -359,7 +356,7 @@ async def pinChatMessage(self, disable_notification=disable_notification, ) - async def unpinChatMessage(self, chat_id, message_id): + async def unpin_chat_message(self, chat_id, message_id): """Unpin a message. Parameters @@ -372,7 +369,7 @@ async def unpinChatMessage(self, chat_id, message_id): chat_id=chat_id, message_id=message_id) - async def leaveChat(self, chat_id): + async def leave_chat(self, chat_id): """Leave a chat. Parameters diff --git a/EzTg/__init__.py b/EzTg/__init__.py index bfcf398..22d0715 100644 --- a/EzTg/__init__.py +++ b/EzTg/__init__.py @@ -1,18 +1,18 @@ __title__ = "EzTg" __author__ = "Hexye" -from .animation import Animation -from .audio import Audio -from .chat import Chat +from .types.message.animation import Animation +from .types.message.audio import Audio +from .types.chat.chat import Chat from .chatlocation import ChatLocation -from .chatpermissions import ChatPermissions -from .chatphoto import ChatPhoto -from .document import Document -from .inlinekeyboard import InlineKeyboard +from .types.chat.permissions import ChatPermissions +from .types.chat.photo import ChatPhoto +from .types.message.document import Document +from .types.inlinekeyboard import InlineKeyboard from .location import Location from .main import TelegramClient -from .message import Message +from .types.message.message import Message from .photosize import PhotoSize -from .replykeyboardmarkup import ReplyKeyboardMarkup -from .user import User -from .video import Video +from .types.replykeyboardmarkup import ReplyKeyboardMarkup +from .types.user.user import User +from .types.message.video import Video diff --git a/EzTg/types/__init__.py b/EzTg/types/__init__.py new file mode 100644 index 0000000..9fa9063 --- /dev/null +++ b/EzTg/types/__init__.py @@ -0,0 +1,3 @@ +from .inlinekeyboard import InlineKeyboard +from .location import Location +from .replykeyboardmarkup import ReplyKeyboardMarkup \ No newline at end of file diff --git a/EzTg/types/chat/__init__.py b/EzTg/types/chat/__init__.py new file mode 100644 index 0000000..75386d4 --- /dev/null +++ b/EzTg/types/chat/__init__.py @@ -0,0 +1,4 @@ +from .chat import Chat +from .location import ChatLocation +from .permissions import ChatPermissions +from .photo import ChatPhoto diff --git a/EzTg/chat.py b/EzTg/types/chat/chat.py similarity index 92% rename from EzTg/chat.py rename to EzTg/types/chat/chat.py index ea294d9..7c30567 100644 --- a/EzTg/chat.py +++ b/EzTg/types/chat/chat.py @@ -1,3 +1,7 @@ +from .location import ChatLocation +from .permissions import ChatPermissions +from .photo import ChatPhoto + class Chat: """Represents a telegram chat. @@ -37,8 +41,8 @@ class Chat: Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. invite_link: `str` Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. - pinned_message: `Message` - Optional. The most recent pinned message (by sending date). Returned only in getChat. + pinned_message_id: `int` + Optional. The most recent pinned message id (by sending date). Returned only in getChat. permissions: `ChatPermissions` Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. slow_mode_delay: `int` @@ -62,10 +66,6 @@ class Chat: """ def __init__(self, data: dict): - from .chatlocation import ChatLocation - from .chatpermissions import ChatPermissions - from .chatphoto import ChatPhoto - from .message import Message self.id = data["id"] self.type = data["type"] @@ -88,9 +88,7 @@ def __init__(self, data: dict): self.join_by_request = data.get("join_by_request") self.description = data.get("description") self.invite_link = data.get("invite_link") - self.pinned_message = data.get("pinned_message") - if self.pinned_message: - self.pinned_message = Message(self.pinned_message) + self.pinned_message_id = data.get("pinned_message").get("id") self.permissions = data.get("permissions") if self.permissions: self.permissions = ChatPermissions(self.permissions) diff --git a/EzTg/chatlocation.py b/EzTg/types/chat/location.py similarity index 93% rename from EzTg/chatlocation.py rename to EzTg/types/chat/location.py index 0119675..82dcb23 100644 --- a/EzTg/chatlocation.py +++ b/EzTg/types/chat/location.py @@ -1,4 +1,4 @@ -from .location import Location +from ..location import Location class ChatLocation: diff --git a/EzTg/chatpermissions.py b/EzTg/types/chat/permissions.py similarity index 100% rename from EzTg/chatpermissions.py rename to EzTg/types/chat/permissions.py diff --git a/EzTg/chatphoto.py b/EzTg/types/chat/photo.py similarity index 100% rename from EzTg/chatphoto.py rename to EzTg/types/chat/photo.py diff --git a/EzTg/inlinekeyboard.py b/EzTg/types/inlinekeyboard.py similarity index 100% rename from EzTg/inlinekeyboard.py rename to EzTg/types/inlinekeyboard.py diff --git a/EzTg/location.py b/EzTg/types/location.py similarity index 100% rename from EzTg/location.py rename to EzTg/types/location.py diff --git a/EzTg/types/message/__init__.py b/EzTg/types/message/__init__.py new file mode 100644 index 0000000..7c67481 --- /dev/null +++ b/EzTg/types/message/__init__.py @@ -0,0 +1,6 @@ +from .animation import Animation +from .audio import Audio +from .document import Document +from .message import Message +from .video import Video +from .videonote import VideoNote \ No newline at end of file diff --git a/EzTg/animation.py b/EzTg/types/message/animation.py similarity index 100% rename from EzTg/animation.py rename to EzTg/types/message/animation.py diff --git a/EzTg/audio.py b/EzTg/types/message/audio.py similarity index 100% rename from EzTg/audio.py rename to EzTg/types/message/audio.py diff --git a/EzTg/document.py b/EzTg/types/message/document.py similarity index 100% rename from EzTg/document.py rename to EzTg/types/message/document.py diff --git a/EzTg/message.py b/EzTg/types/message/message.py similarity index 98% rename from EzTg/message.py rename to EzTg/types/message/message.py index 14c195a..bf26aa1 100644 --- a/EzTg/message.py +++ b/EzTg/types/message/message.py @@ -1,10 +1,10 @@ from .animation import Animation from .audio import Audio -from .chat import Chat +from ..chat.chat import Chat from .document import Document -from .location import Location +from ..location import Location from .photosize import PhotoSize -from .user import User +from ..user.user import User from .videonote import VideoNote diff --git a/EzTg/photosize.py b/EzTg/types/message/photosize.py similarity index 100% rename from EzTg/photosize.py rename to EzTg/types/message/photosize.py diff --git a/EzTg/video.py b/EzTg/types/message/video.py similarity index 100% rename from EzTg/video.py rename to EzTg/types/message/video.py diff --git a/EzTg/videonote.py b/EzTg/types/message/videonote.py similarity index 100% rename from EzTg/videonote.py rename to EzTg/types/message/videonote.py diff --git a/EzTg/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py similarity index 93% rename from EzTg/replykeyboardmarkup.py rename to EzTg/types/replykeyboardmarkup.py index 8845380..dfc9761 100644 --- a/EzTg/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -13,6 +13,7 @@ def __init__( self.resize_keyboard = resize_keyboard self.one_time_keyboard = one_time_keyboard self.selective = selective + self.input_field_placeholder = input_field_placeholder def add( self, @@ -62,4 +63,5 @@ def send(self): "resize_keyboard": self.resize_keyboard, "one_time_keyboard": self.one_time_keyboard, "selective": self.selective, + "input_field_placeholder": self.input_field_placeholder, } diff --git a/EzTg/types/user/__init__.py b/EzTg/types/user/__init__.py new file mode 100644 index 0000000..b7bb9be --- /dev/null +++ b/EzTg/types/user/__init__.py @@ -0,0 +1 @@ +from .user import User \ No newline at end of file diff --git a/EzTg/user.py b/EzTg/types/user/user.py similarity index 100% rename from EzTg/user.py rename to EzTg/types/user/user.py diff --git a/__pycache__/setup.cpython-311.pyc b/__pycache__/setup.cpython-311.pyc deleted file mode 100644 index 2d1dadcf77f2ebc8ba06f6782c6c9112fd284786..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1359 zcmb_bOKTKC5boJmHoKc-Hzq0uaSTLRm6;^sYw;0ZXdoIfQA8G&cDkHQGBZ7P_r&a+ zyy-viDjpP3e}jJ^2MAVtzoN~BCGp5Y=g@Z2C- z*C2yrh*aIoo7#&(gkGz?xeR4<0o8{;YW8~a_IzmK$TJ@@97Vv)`;?gid~g{KOu)Qt z3Tnn2Eb}4-2B9#q<4{Jt(A78FP$dJaRJ!7crTAXMToNMU4cm6Ryyeiqz6xt?xCE>A zJCX=0n zVV8y+`!GE{;|AFC^@GXW{|qe|5U?if0J9ZBABM^PzeafZb~i#hss9tgRH88lo|G@d zuDQstvjQwR_)k5L^B8!&m`vPYR97m{<(R{v8)FyDM#H?(7E3hLr=!;K-e4zsgPrUR zb}Bj0i*HktJ>sU419P4OA@7Dazc6c_k0M4_f#@Kw%`Tchu9NY3)yJx6&`eb}Qq*|Nysfy$`h^+A~naR9P!6&P2YDGNAOsbsRU`EP;l zFIgtQ9p**4d1ck7q1*aZviDC(%b}rAFSkTH0-24OFDtr_e2Ph{%c)?N!4aC_vh4Vn zbML;VoRGyx^@XY{mqSsvtS#-W$CRMzgq zuZJ!+nzy*J+f?(i<~6tGkT=zAHuZQlyLc;Ve=VL4D2aVI%l0T$Lv8+8kxteyj1<+@ zx4upeja Date: Sun, 26 Mar 2023 18:39:26 +0200 Subject: [PATCH 091/113] maybe fix docs --- EzTg/__init__.py | 8 +-- docs/EzTg.rst | 122 +++--------------------------------- docs/EzTg.types.chat.rst | 45 +++++++++++++ docs/EzTg.types.message.rst | 69 ++++++++++++++++++++ docs/EzTg.types.rst | 47 ++++++++++++++ docs/EzTg.types.user.rst | 21 +++++++ docs/modules.rst | 1 + docs/setup.rst | 7 +++ 8 files changed, 203 insertions(+), 117 deletions(-) create mode 100644 docs/EzTg.types.chat.rst create mode 100644 docs/EzTg.types.message.rst create mode 100644 docs/EzTg.types.rst create mode 100644 docs/EzTg.types.user.rst create mode 100644 docs/setup.rst diff --git a/EzTg/__init__.py b/EzTg/__init__.py index 22d0715..6c8d353 100644 --- a/EzTg/__init__.py +++ b/EzTg/__init__.py @@ -4,15 +4,15 @@ from .types.message.animation import Animation from .types.message.audio import Audio from .types.chat.chat import Chat -from .chatlocation import ChatLocation +from .types.chat.location import ChatLocation from .types.chat.permissions import ChatPermissions from .types.chat.photo import ChatPhoto from .types.message.document import Document from .types.inlinekeyboard import InlineKeyboard -from .location import Location -from .main import TelegramClient +from .types.location import Location +from .EzTg import TelegramClient from .types.message.message import Message -from .photosize import PhotoSize +from .types.message.photosize import PhotoSize from .types.replykeyboardmarkup import ReplyKeyboardMarkup from .types.user.user import User from .types.message.video import Video diff --git a/docs/EzTg.rst b/docs/EzTg.rst index 35d1464..406ef00 100644 --- a/docs/EzTg.rst +++ b/docs/EzTg.rst @@ -1,125 +1,21 @@ EzTg package ============ -Submodules ----------- - -EzTg.animation module ---------------------- - -.. automodule:: EzTg.animation - :members: - :undoc-members: - :show-inheritance: - -EzTg.audio module ------------------ - -.. automodule:: EzTg.audio - :members: - :undoc-members: - :show-inheritance: - -EzTg.chat module ----------------- - -.. automodule:: EzTg.chat - :members: - :undoc-members: - :show-inheritance: - -EzTg.chatlocation module ------------------------- +Subpackages +----------- -.. automodule:: EzTg.chatlocation - :members: - :undoc-members: - :show-inheritance: - -EzTg.chatpermissions module ---------------------------- - -.. automodule:: EzTg.chatpermissions - :members: - :undoc-members: - :show-inheritance: - -EzTg.chatphoto module ---------------------- - -.. automodule:: EzTg.chatphoto - :members: - :undoc-members: - :show-inheritance: - -EzTg.document module --------------------- - -.. automodule:: EzTg.document - :members: - :undoc-members: - :show-inheritance: +.. toctree:: + :maxdepth: 4 -EzTg.inlinekeyboard module --------------------------- + EzTg.types -.. automodule:: EzTg.inlinekeyboard - :members: - :undoc-members: - :show-inheritance: - -EzTg.location module --------------------- - -.. automodule:: EzTg.location - :members: - :undoc-members: - :show-inheritance: - -EzTg.main module ----------------- - -.. automodule:: EzTg.main - :members: - :undoc-members: - :show-inheritance: - -EzTg.message module -------------------- - -.. automodule:: EzTg.message - :members: - :undoc-members: - :show-inheritance: - -EzTg.photosize module ---------------------- - -.. automodule:: EzTg.photosize - :members: - :undoc-members: - :show-inheritance: - -EzTg.replykeyboardmarkup module -------------------------------- - -.. automodule:: EzTg.replykeyboardmarkup - :members: - :undoc-members: - :show-inheritance: +Submodules +---------- -EzTg.user module +EzTg.EzTg module ---------------- -.. automodule:: EzTg.user - :members: - :undoc-members: - :show-inheritance: - -EzTg.video module ------------------ - -.. automodule:: EzTg.video +.. automodule:: EzTg.EzTg :members: :undoc-members: :show-inheritance: diff --git a/docs/EzTg.types.chat.rst b/docs/EzTg.types.chat.rst new file mode 100644 index 0000000..57585bb --- /dev/null +++ b/docs/EzTg.types.chat.rst @@ -0,0 +1,45 @@ +EzTg.types.chat package +======================= + +Submodules +---------- + +EzTg.types.chat.chat module +--------------------------- + +.. automodule:: EzTg.types.chat.chat + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.chat.location module +------------------------------- + +.. automodule:: EzTg.types.chat.location + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.chat.permissions module +---------------------------------- + +.. automodule:: EzTg.types.chat.permissions + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.chat.photo module +---------------------------- + +.. automodule:: EzTg.types.chat.photo + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: EzTg.types.chat + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/EzTg.types.message.rst b/docs/EzTg.types.message.rst new file mode 100644 index 0000000..24d548b --- /dev/null +++ b/docs/EzTg.types.message.rst @@ -0,0 +1,69 @@ +EzTg.types.message package +========================== + +Submodules +---------- + +EzTg.types.message.animation module +----------------------------------- + +.. automodule:: EzTg.types.message.animation + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.message.audio module +------------------------------- + +.. automodule:: EzTg.types.message.audio + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.message.document module +---------------------------------- + +.. automodule:: EzTg.types.message.document + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.message.message module +--------------------------------- + +.. automodule:: EzTg.types.message.message + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.message.photosize module +----------------------------------- + +.. automodule:: EzTg.types.message.photosize + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.message.video module +------------------------------- + +.. automodule:: EzTg.types.message.video + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.message.videonote module +----------------------------------- + +.. automodule:: EzTg.types.message.videonote + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: EzTg.types.message + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/EzTg.types.rst b/docs/EzTg.types.rst new file mode 100644 index 0000000..28904bb --- /dev/null +++ b/docs/EzTg.types.rst @@ -0,0 +1,47 @@ +EzTg.types package +================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + EzTg.types.chat + EzTg.types.message + EzTg.types.user + +Submodules +---------- + +EzTg.types.inlinekeyboard module +-------------------------------- + +.. automodule:: EzTg.types.inlinekeyboard + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.location module +-------------------------- + +.. automodule:: EzTg.types.location + :members: + :undoc-members: + :show-inheritance: + +EzTg.types.replykeyboardmarkup module +------------------------------------- + +.. automodule:: EzTg.types.replykeyboardmarkup + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: EzTg.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/EzTg.types.user.rst b/docs/EzTg.types.user.rst new file mode 100644 index 0000000..3251bc3 --- /dev/null +++ b/docs/EzTg.types.user.rst @@ -0,0 +1,21 @@ +EzTg.types.user package +======================= + +Submodules +---------- + +EzTg.types.user.user module +--------------------------- + +.. automodule:: EzTg.types.user.user + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: EzTg.types.user + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/modules.rst b/docs/modules.rst index d97ad3f..a017961 100644 --- a/docs/modules.rst +++ b/docs/modules.rst @@ -5,3 +5,4 @@ EzTg :maxdepth: 4 EzTg + setup diff --git a/docs/setup.rst b/docs/setup.rst new file mode 100644 index 0000000..552eb49 --- /dev/null +++ b/docs/setup.rst @@ -0,0 +1,7 @@ +setup module +============ + +.. automodule:: setup + :members: + :undoc-members: + :show-inheritance: From 3223915f0a8eb2b658d2a75e7c4d4e92f09c17e9 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Mon, 27 Mar 2023 17:27:44 +0200 Subject: [PATCH 092/113] add missing docstrings --- EzTg/EzTg.py | 8 +++++ EzTg/types/replykeyboardmarkup.py | 51 +++++++++++++++++++++++++++++++ docs/modules.rst | 1 - 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index 577846b..fc60e16 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -23,8 +23,16 @@ class TokenError(Exception): class TelegramClient: + """A class that represents a telegram client.""" def __init__(self, token): + """Initialize the client. + + Parameters + ---------- + token: `str` + The token of your bot.""" + self.token = token self.api = "https://api.telegram.org/bot{}/{}" diff --git a/EzTg/types/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py index dfc9761..4937581 100644 --- a/EzTg/types/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -8,6 +8,20 @@ def __init__( selective=False, input_field_placeholder=None, ): + """Create a new reply keyboard markup + + Parameters + ---------- + is_persistent : bool + Optional. The keyboard is persistent, by default False + resize_keyboard : bool + Optional. The keyboard is resized, by default False + one_time_keyboard : bool + Optional. The keyboard is one time, by default False + selective : bool + Optional. The keyboard is selective, by default False + input_field_placeholder : str + Optional. The placeholder of the input field, by default None""" self.keyboard = [[]] self.is_persistent = is_persistent self.resize_keyboard = resize_keyboard @@ -25,6 +39,24 @@ def add( request_poll=False, web_app=None, ): + """Add a new button to the keyboard. + + Parameters + ---------- + text : str + The text of the button + request_user : str + Optional. The request user of the button, by default None + request_chat : str + Optional. The request chat of the button, by default None + request_contact : bool + Optional. The request contact of the button, by default False + request_location : bool + Optional. The request location of the button, by default False + request_poll : bool + 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, @@ -45,6 +77,24 @@ def add_new_row( request_poll=False, web_app=None, ): + """Add a new button to the keyboard in a new row. + + Parameters + ---------- + text : str + The text of the button + request_user : str + Optional. The request user of the button, by default None + request_chat : str + Optional. The request chat of the button, by default None + request_contact : bool + Optional. The request contact of the button, by default False + request_location : bool + Optional. The request location of the button, by default False + request_poll : bool + 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.append([]) self.keyboard[-1].append({ "text": text, @@ -57,6 +107,7 @@ def add_new_row( }) def send(self): + """Return the keyboard.""" return { "reply_markup": self.keyboard, "is_persistent": self.is_persistent, diff --git a/docs/modules.rst b/docs/modules.rst index a017961..d97ad3f 100644 --- a/docs/modules.rst +++ b/docs/modules.rst @@ -5,4 +5,3 @@ EzTg :maxdepth: 4 EzTg - setup From f005e7b2737d3f21a4d8fd55962696773bfb9efa Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sat, 27 May 2023 00:06:37 +0200 Subject: [PATCH 093/113] add Voice class #25 --- EzTg/types/message/message.py | 3 +++ EzTg/types/message/voice.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 EzTg/types/message/voice.py diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index bf26aa1..2e53cff 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -6,6 +6,7 @@ from .photosize import PhotoSize from ..user.user import User from .videonote import VideoNote +from .voice import Voice class Message: @@ -147,6 +148,8 @@ def __init__(self, data): if self.video_note: self.video_note = VideoNote(self.video_note) self.voice = data.get("voice") + if self.voice: + self.voice = Voice(self.voice) self.caption = data.get("caption") self.caption_entities = data.get("caption_entities") self.has_media_spoiler = data.get("has_media_spoiler") diff --git a/EzTg/types/message/voice.py b/EzTg/types/message/voice.py new file mode 100644 index 0000000..8a592a6 --- /dev/null +++ b/EzTg/types/message/voice.py @@ -0,0 +1,23 @@ +class Voice: + """This object represents a voice note. + + Attributes + ---------- + file_id: `str` + Unique identifier for this file. + file_unique_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + duration: `int` + Duration of the audio in seconds as defined by sender. + mime_type: `str` + Optional. MIME type of the file as defined by sender. + file_size: `int` + Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. + """ + + def __init__(self, data): + self.file_id = data['file_id'] + self.file_unique_id = data['file_unique_id'] + self.duration = data['duration'] + self.mime_type = data.get('mime_type') + self.file_size = data.get('file_size') \ No newline at end of file From d619e463158d2b304eded89cb3c1beefcf3e59e3 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sat, 27 May 2023 00:12:24 +0200 Subject: [PATCH 094/113] add MessageEntity class #25 --- EzTg/types/message/message.py | 3 +++ EzTg/types/message/messageentity.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 EzTg/types/message/messageentity.py diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 2e53cff..a1b56cd 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -3,6 +3,7 @@ from ..chat.chat import Chat from .document import Document from ..location import Location +from .messageentity import MessageEntity from .photosize import PhotoSize from ..user.user import User from .videonote import VideoNote @@ -152,6 +153,8 @@ def __init__(self, data): self.voice = Voice(self.voice) 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.has_media_spoiler = data.get("has_media_spoiler") self.contact = data.get("contact") self.dice = data.get("dice") diff --git a/EzTg/types/message/messageentity.py b/EzTg/types/message/messageentity.py new file mode 100644 index 0000000..f97e667 --- /dev/null +++ b/EzTg/types/message/messageentity.py @@ -0,0 +1,29 @@ +from ..user import User + +class MessageEntity: + """This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. + + Attributes + ---------- + type: `str` + Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), underline (underlined text), strikethrough (strikethrough text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames). + offset: `int` + Offset in UTF-16 code units to the start of the entity. + url: `str` + Optional. For “text_link” only, URL that will be opened after user taps on the text. + user: `User` + Optional. For “text_mention” only, the mentioned user. + language: `str` + Optional. For “pre” only, the programming language of the entity text. + custom_emoji_id: `str` + Optional. For “custom_emoji” only, unique identifier of the custom emoji. + """ + def __init__(self, data): + self.type = data['type'] + self.offset = data['offset'] + self.url = data.get('url') + self.user = data.get('user') + if self.user: + self.user = User(self.user) + self.language = data.get('language') + self.custom_emoji_id = data.get('custom_emoji_id') \ No newline at end of file From b32db35b0a8e6f7b4f07786b3fd9e5759ae34d2c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 26 May 2023 22:12:36 +0000 Subject: [PATCH 095/113] Restyled by autopep8 --- EzTg/EzTg.py | 16 ++++++++-------- EzTg/types/__init__.py | 2 +- EzTg/types/chat/chat.py | 1 + EzTg/types/message/__init__.py | 2 +- EzTg/types/message/message.py | 3 ++- EzTg/types/message/messageentity.py | 6 ++++-- EzTg/types/message/voice.py | 4 ++-- EzTg/types/replykeyboardmarkup.py | 6 +++--- EzTg/types/user/__init__.py | 2 +- setup.py | 3 +-- 10 files changed, 24 insertions(+), 21 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index fc60e16..0a620e6 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -32,7 +32,7 @@ def __init__(self, token): ---------- token: `str` The token of your bot.""" - + self.token = token self.api = "https://api.telegram.org/bot{}/{}" @@ -197,10 +197,10 @@ async def edit_message_text( ) async def forward_message(self, - chat_id, - from_chat_id, - message_id, - disable_notification=False): + chat_id, + from_chat_id, + message_id, + disable_notification=False): """Foward a message. Parameters @@ -343,9 +343,9 @@ async def set_chat_photo(self, chat_id, photo): return await self.send("setChatPhoto", chat_id=chat_id, photo=photo) async def pin_chat_message(self, - chat_id, - message_id, - disable_notification=False): + chat_id, + message_id, + disable_notification=False): """Pin a message. Parameters diff --git a/EzTg/types/__init__.py b/EzTg/types/__init__.py index 9fa9063..c138d69 100644 --- a/EzTg/types/__init__.py +++ b/EzTg/types/__init__.py @@ -1,3 +1,3 @@ from .inlinekeyboard import InlineKeyboard from .location import Location -from .replykeyboardmarkup import ReplyKeyboardMarkup \ No newline at end of file +from .replykeyboardmarkup import ReplyKeyboardMarkup diff --git a/EzTg/types/chat/chat.py b/EzTg/types/chat/chat.py index 7c30567..edb44b3 100644 --- a/EzTg/types/chat/chat.py +++ b/EzTg/types/chat/chat.py @@ -2,6 +2,7 @@ from .permissions import ChatPermissions from .photo import ChatPhoto + class Chat: """Represents a telegram chat. diff --git a/EzTg/types/message/__init__.py b/EzTg/types/message/__init__.py index 7c67481..82650ae 100644 --- a/EzTg/types/message/__init__.py +++ b/EzTg/types/message/__init__.py @@ -3,4 +3,4 @@ from .document import Document from .message import Message from .video import Video -from .videonote import VideoNote \ No newline at end of file +from .videonote import VideoNote diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index a1b56cd..1e98e1f 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -154,7 +154,8 @@ 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") self.dice = data.get("dice") diff --git a/EzTg/types/message/messageentity.py b/EzTg/types/message/messageentity.py index f97e667..df1cdca 100644 --- a/EzTg/types/message/messageentity.py +++ b/EzTg/types/message/messageentity.py @@ -1,8 +1,9 @@ from ..user import User + class MessageEntity: """This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. - + Attributes ---------- type: `str` @@ -18,6 +19,7 @@ class MessageEntity: custom_emoji_id: `str` Optional. For “custom_emoji” only, unique identifier of the custom emoji. """ + def __init__(self, data): self.type = data['type'] self.offset = data['offset'] @@ -26,4 +28,4 @@ def __init__(self, data): if self.user: self.user = User(self.user) self.language = data.get('language') - self.custom_emoji_id = data.get('custom_emoji_id') \ No newline at end of file + self.custom_emoji_id = data.get('custom_emoji_id') diff --git a/EzTg/types/message/voice.py b/EzTg/types/message/voice.py index 8a592a6..7085574 100644 --- a/EzTg/types/message/voice.py +++ b/EzTg/types/message/voice.py @@ -1,6 +1,6 @@ class Voice: """This object represents a voice note. - + Attributes ---------- file_id: `str` @@ -20,4 +20,4 @@ def __init__(self, data): self.file_unique_id = data['file_unique_id'] self.duration = data['duration'] self.mime_type = data.get('mime_type') - self.file_size = data.get('file_size') \ No newline at end of file + self.file_size = data.get('file_size') diff --git a/EzTg/types/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py index 4937581..9a2d921 100644 --- a/EzTg/types/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -9,7 +9,7 @@ def __init__( input_field_placeholder=None, ): """Create a new reply keyboard markup - + Parameters ---------- is_persistent : bool @@ -40,7 +40,7 @@ def add( web_app=None, ): """Add a new button to the keyboard. - + Parameters ---------- text : str @@ -78,7 +78,7 @@ def add_new_row( web_app=None, ): """Add a new button to the keyboard in a new row. - + Parameters ---------- text : str diff --git a/EzTg/types/user/__init__.py b/EzTg/types/user/__init__.py index b7bb9be..ee4c00b 100644 --- a/EzTg/types/user/__init__.py +++ b/EzTg/types/user/__init__.py @@ -1 +1 @@ -from .user import User \ No newline at end of file +from .user import User 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 5f40a2cc36ce6f768dc27db9c8d21770b7cbca1f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 26 May 2023 22:12:39 +0000 Subject: [PATCH 096/113] Restyled by black --- EzTg/EzTg.py | 42 ++++++++++++++--------------- EzTg/types/chat/chat.py | 10 +++---- EzTg/types/inlinekeyboard.py | 11 ++------ EzTg/types/message/message.py | 3 +-- EzTg/types/message/messageentity.py | 12 ++++----- EzTg/types/message/voice.py | 10 +++---- EzTg/types/replykeyboardmarkup.py | 41 +++++++++++++++------------- EzTg/types/user/user.py | 3 +-- 8 files changed, 62 insertions(+), 70 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index 0a620e6..b26710f 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -5,13 +5,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__ @@ -45,9 +50,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) @@ -136,9 +141,7 @@ 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, @@ -196,11 +199,9 @@ 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 @@ -342,10 +343,7 @@ 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 @@ -373,9 +371,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. diff --git a/EzTg/types/chat/chat.py b/EzTg/types/chat/chat.py index edb44b3..3d99768 100644 --- a/EzTg/types/chat/chat.py +++ b/EzTg/types/chat/chat.py @@ -67,7 +67,6 @@ class Chat: """ def __init__(self, data: dict): - self.id = data["id"] self.type = data["type"] self.title = data.get("title") @@ -79,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") @@ -96,7 +95,8 @@ 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") diff --git a/EzTg/types/inlinekeyboard.py b/EzTg/types/inlinekeyboard.py index 163a02d..a7cef55 100644 --- a/EzTg/types/inlinekeyboard.py +++ b/EzTg/types/inlinekeyboard.py @@ -1,5 +1,4 @@ class InlineKeyboard: - def __init__(self): """Create a new inline keyboard""" self.keyboard = [[]] @@ -36,10 +35,7 @@ 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. @@ -51,10 +47,7 @@ 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.""" diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 1e98e1f..a1b56cd 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -154,8 +154,7 @@ 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") self.dice = data.get("dice") diff --git a/EzTg/types/message/messageentity.py b/EzTg/types/message/messageentity.py index df1cdca..a9eba5a 100644 --- a/EzTg/types/message/messageentity.py +++ b/EzTg/types/message/messageentity.py @@ -21,11 +21,11 @@ class MessageEntity: """ def __init__(self, data): - self.type = data['type'] - self.offset = data['offset'] - self.url = data.get('url') - self.user = data.get('user') + self.type = data["type"] + self.offset = data["offset"] + self.url = data.get("url") + self.user = data.get("user") if self.user: self.user = User(self.user) - self.language = data.get('language') - self.custom_emoji_id = data.get('custom_emoji_id') + self.language = data.get("language") + self.custom_emoji_id = data.get("custom_emoji_id") diff --git a/EzTg/types/message/voice.py b/EzTg/types/message/voice.py index 7085574..e849eb8 100644 --- a/EzTg/types/message/voice.py +++ b/EzTg/types/message/voice.py @@ -16,8 +16,8 @@ class Voice: """ def __init__(self, data): - self.file_id = data['file_id'] - self.file_unique_id = data['file_unique_id'] - self.duration = data['duration'] - self.mime_type = data.get('mime_type') - self.file_size = data.get('file_size') + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.duration = data["duration"] + self.mime_type = data.get("mime_type") + self.file_size = data.get("file_size") diff --git a/EzTg/types/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py index 9a2d921..6833f32 100644 --- a/EzTg/types/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -57,15 +56,17 @@ 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, @@ -96,15 +97,17 @@ 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.""" diff --git a/EzTg/types/user/user.py b/EzTg/types/user/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/types/user/user.py +++ b/EzTg/types/user/user.py @@ -36,6 +36,5 @@ 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") From acad7f729d0bf5661639c7e37bc8e6e69f57839e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 26 May 2023 22:12:40 +0000 Subject: [PATCH 097/113] Restyled by isort --- EzTg/__init__.py | 10 +++++----- EzTg/types/message/message.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/EzTg/__init__.py b/EzTg/__init__.py index 6c8d353..5a9d87b 100644 --- a/EzTg/__init__.py +++ b/EzTg/__init__.py @@ -1,18 +1,18 @@ __title__ = "EzTg" __author__ = "Hexye" -from .types.message.animation import Animation -from .types.message.audio import Audio +from .EzTg import TelegramClient from .types.chat.chat import Chat from .types.chat.location import ChatLocation from .types.chat.permissions import ChatPermissions from .types.chat.photo import ChatPhoto -from .types.message.document import Document from .types.inlinekeyboard import InlineKeyboard from .types.location import Location -from .EzTg import TelegramClient +from .types.message.animation import Animation +from .types.message.audio import Audio +from .types.message.document import Document from .types.message.message import Message from .types.message.photosize import PhotoSize +from .types.message.video import Video from .types.replykeyboardmarkup import ReplyKeyboardMarkup from .types.user.user import User -from .types.message.video import Video diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index a1b56cd..0febb1d 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -1,11 +1,11 @@ +from ..chat.chat import Chat +from ..location import Location +from ..user.user import User from .animation import Animation from .audio import Audio -from ..chat.chat import Chat from .document import Document -from ..location import Location from .messageentity import MessageEntity from .photosize import PhotoSize -from ..user.user import User from .videonote import VideoNote from .voice import Voice From 1072c7947ebc7927194fd94857f9324a4d359be7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 26 May 2023 22:12:43 +0000 Subject: [PATCH 098/113] Restyled by yapf --- EzTg/EzTg.py | 42 ++++++++++++++++--------------- EzTg/types/chat/chat.py | 9 +++---- EzTg/types/inlinekeyboard.py | 11 ++++++-- EzTg/types/message/message.py | 4 ++- EzTg/types/replykeyboardmarkup.py | 41 ++++++++++++++---------------- EzTg/types/user/user.py | 3 ++- setup.py | 3 ++- 7 files changed, 61 insertions(+), 52 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index b26710f..0a620e6 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.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__ @@ -50,9 +45,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) @@ -141,7 +136,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, @@ -199,9 +196,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 @@ -343,7 +342,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 @@ -371,9 +373,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. diff --git a/EzTg/types/chat/chat.py b/EzTg/types/chat/chat.py index 3d99768..8494a80 100644 --- a/EzTg/types/chat/chat.py +++ b/EzTg/types/chat/chat.py @@ -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") @@ -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") diff --git a/EzTg/types/inlinekeyboard.py b/EzTg/types/inlinekeyboard.py index a7cef55..163a02d 100644 --- a/EzTg/types/inlinekeyboard.py +++ b/EzTg/types/inlinekeyboard.py @@ -1,4 +1,5 @@ class InlineKeyboard: + def __init__(self): """Create a new inline keyboard""" self.keyboard = [[]] @@ -35,7 +36,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. @@ -47,7 +51,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.""" diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 0febb1d..81c59c4 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -154,7 +154,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") self.dice = data.get("dice") diff --git a/EzTg/types/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py index 6833f32..9a2d921 100644 --- a/EzTg/types/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -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, @@ -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.""" diff --git a/EzTg/types/user/user.py b/EzTg/types/user/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/types/user/user.py +++ b/EzTg/types/user/user.py @@ -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") 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/", From 95959e0612b7d8e8e3165a4d85a3d2f45f7215a3 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 18:42:57 +0200 Subject: [PATCH 099/113] add contact class --- EzTg/types/message/contact.py | 22 ++++++++++++++++++++++ EzTg/types/message/message.py | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 EzTg/types/message/contact.py diff --git a/EzTg/types/message/contact.py b/EzTg/types/message/contact.py new file mode 100644 index 0000000..f2a9db0 --- /dev/null +++ b/EzTg/types/message/contact.py @@ -0,0 +1,22 @@ +class Contact: + """This object represents a phone contact. + + Attributes + ---------- + phone_number: `str` + Contact's phone number. + first_name: `str` + Contact's first name. + last_name: `str` + Optional. Contact's last name. + user_id: `int` + Optional. Contact's user identifier in Telegram. + vcard: `str` + Optional. Additional data about the contact in the form of a vCard.""" + + def __init__(self, data): + self.phone_number = data["phone_number"] + self.first_name = data["first_name"] + self.last_name = data.get("last_name") + self.user_id = data.get("user_id") + self.vcard = data.get("vcard") \ No newline at end of file diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 81c59c4..83fd910 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -3,6 +3,7 @@ from ..user.user import User from .animation import Animation from .audio import Audio +from .contact import Contact from .document import Document from .messageentity import MessageEntity from .photosize import PhotoSize @@ -159,6 +160,8 @@ def __init__(self, data): ] self.has_media_spoiler = data.get("has_media_spoiler") self.contact = data.get("contact") + if self.contact: + self.contact = Contact(self.contact) self.dice = data.get("dice") self.game = data.get("game") self.poll = data.get("poll") From ee3883ec6fa89eeb66c52d5e3c507fd9eabb6f2f Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 18:46:09 +0200 Subject: [PATCH 100/113] add Dice class #25 --- EzTg/types/message/dice.py | 14 ++++++++++++++ EzTg/types/message/message.py | 3 +++ 2 files changed, 17 insertions(+) create mode 100644 EzTg/types/message/dice.py diff --git a/EzTg/types/message/dice.py b/EzTg/types/message/dice.py new file mode 100644 index 0000000..061e921 --- /dev/null +++ b/EzTg/types/message/dice.py @@ -0,0 +1,14 @@ +class Dice: + """This object represents an animated emoji that displays a random value. + + Attributes + ---------- + emoji: `str` + Emoji on which the dice throw animation is based. + value: `int` + Value of the dice, 1-6 for “🎲”, “🎯” and “🎳” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji. + """ + + def __init__(self, data): + self.emoji = data["emoji"] + self.value = data["value"] \ No newline at end of file diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 83fd910..b99f21b 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -4,6 +4,7 @@ from .animation import Animation from .audio import Audio from .contact import Contact +from .dice import Dice from .document import Document from .messageentity import MessageEntity from .photosize import PhotoSize @@ -163,6 +164,8 @@ def __init__(self, data): if self.contact: self.contact = Contact(self.contact) self.dice = data.get("dice") + if self.dice: + self.dice = Dice(self.dice) self.game = data.get("game") self.poll = data.get("poll") self.venue = data.get("venue") From 997a770e9345416c7a01c763c888a2b0d493b823 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 18:50:25 +0200 Subject: [PATCH 101/113] add Game class #25 --- EzTg/types/message/game.py | 30 ++++++++++++++++++++++++++++++ EzTg/types/message/message.py | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 EzTg/types/message/game.py diff --git a/EzTg/types/message/game.py b/EzTg/types/message/game.py new file mode 100644 index 0000000..bfb8839 --- /dev/null +++ b/EzTg/types/message/game.py @@ -0,0 +1,30 @@ +from .animation import Animation +from .photosize import PhotoSize +from .messageentity import MessageEntity + +class Game: + """This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. + + Attributes + ---------- + title: `str` + Title of the game. + description: `str` + Description of the game. + photo: `List[PhotoSize]` + Photo that will be displayed in the game message in chats. + text: `str` + Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. + text_entities: `List[MessageEntity]` + Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + animation: `Animation` + Optional. Animation that will be displayed in the game message in chats. Upload via BotFather. + """ + + def __init__(self, data): + self.title = data["title"] + self.description = data["description"] + self.photo = [PhotoSize(photo) for photo in data["photo"]] + self.text = data.get("text") + self.text_entities = [MessageEntity(entity) for entity in data.get("text_entities", [])] + self.animation = Animation(data.get("animation")) \ No newline at end of file diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index b99f21b..20eb682 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -6,6 +6,7 @@ from .contact import Contact from .dice import Dice from .document import Document +from .game import Game from .messageentity import MessageEntity from .photosize import PhotoSize from .videonote import VideoNote @@ -167,6 +168,8 @@ def __init__(self, data): if self.dice: self.dice = Dice(self.dice) self.game = data.get("game") + if self.game: + self.game = Game(self.game) self.poll = data.get("poll") self.venue = data.get("venue") self.location = data.get("location") From 107a625405fbe48c1958d3930ca56260e21ae886 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 18:52:48 +0200 Subject: [PATCH 102/113] fix exceptions not handles --- EzTg/EzTg.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index 0a620e6..f331ee2 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -1,4 +1,5 @@ import aiohttp +import asyncio from .types.chat.chat import Chat from .types.user.user import User @@ -70,11 +71,19 @@ async def start_polling(self, callback, callback_query=None): if update: for x in update: if "message" in x.keys(): - await callback(x) - offset = update[-1].update_id + 1 + try: + asyncio.get_event_loop().create_task(callback(x)) + except Exception as e: + raise e + finally: + offset = update[-1].update_id + 1 elif "callback_query" in x.keys() and callback_query: - await callback_query(x) - offset = update[-1].update_id + 1 + try: + asyncio.get_event_loop().create_task(callback_query(x)) + except Exception as e: + raise e + finally: + offset = update[-1].update_id + 1 async def send_message( self, From 71a02fa83c8c22cc750dfd6397838acfb2e81647 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 18:58:27 +0200 Subject: [PATCH 103/113] add Poll Full message class implementation #25 --- EzTg/types/message/message.py | 3 ++ EzTg/types/message/poll.py | 49 ++++++++++++++++++++++++++++++++ EzTg/types/message/polloption.py | 13 +++++++++ 3 files changed, 65 insertions(+) create mode 100644 EzTg/types/message/poll.py create mode 100644 EzTg/types/message/polloption.py diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 20eb682..166eb40 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -9,6 +9,7 @@ from .game import Game from .messageentity import MessageEntity from .photosize import PhotoSize +from .poll import Poll from .videonote import VideoNote from .voice import Voice @@ -171,6 +172,8 @@ def __init__(self, data): if self.game: self.game = Game(self.game) self.poll = data.get("poll") + if self.poll: + self.poll = Poll(self.poll) self.venue = data.get("venue") self.location = data.get("location") if self.location: diff --git a/EzTg/types/message/poll.py b/EzTg/types/message/poll.py new file mode 100644 index 0000000..c0f8d51 --- /dev/null +++ b/EzTg/types/message/poll.py @@ -0,0 +1,49 @@ +from .messageentity import MessageEntity +from .polloption import PollOption + +class Poll: + """This object contains information about a poll. + + Attributes + ---------- + id: `str` + Unique poll identifier. + question: `str` + Poll question, 1-300 characters. + options: `List[PollOption]` + List of poll options. + total_voter_count: `int` + Total number of users that voted in the poll. + is_closed: `bool` + True, if the poll is closed. + is_anonymous: `bool` + True, if the poll is anonymous. + type: `str` + Poll type, currently can be “regular” or “quiz”. + allows_multiple_answers: `bool` + True, if the poll allows multiple answers. + correct_option_id: `int` + Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot. + explanation: `str` + Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters. + explanation_entities: `List[MessageEntity]` + Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation. + open_period: `int` + Optional. Amount of time in seconds the poll will be active after creation. + close_date: `int` + Optional. Point in time (Unix timestamp) when the poll will be automatically closed.""" + + def __init__(self, data): + self.id = data["id"] + self.question = data["question"] + self.options = [PollOption(option) for option in data["options"]] + self.total_voter_count = data["total_voter_count"] + self.is_closed = data["is_closed"] + self.is_anonymous = data["is_anonymous"] + self.type = data["type"] + self.allows_multiple_answers = data["allows_multiple_answers"] + 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", [])] + self.open_period = data.get("open_period") + self.close_date = data.get("close_date") \ No newline at end of file diff --git a/EzTg/types/message/polloption.py b/EzTg/types/message/polloption.py new file mode 100644 index 0000000..89873cd --- /dev/null +++ b/EzTg/types/message/polloption.py @@ -0,0 +1,13 @@ +class PollOption: + """Represents one answer option in a poll. + + Attributes + ---------- + text: `str` + Option text, 1-100 characters. + voter_count: `int` + Number of users that voted for this option""" + + def __init__(self, data): + self.text = data["text"] + self.voter_count = data["voter_count"] \ No newline at end of file From 5080a0be836db833298b76aaff30252724498af5 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:02:22 +0200 Subject: [PATCH 104/113] add Venue class #25 --- EzTg/types/message/message.py | 3 +++ EzTg/types/message/venue.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 EzTg/types/message/venue.py diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 166eb40..9e7c378 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -10,6 +10,7 @@ from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll +from .venue import Venue from .videonote import VideoNote from .voice import Voice @@ -175,6 +176,8 @@ def __init__(self, data): if self.poll: self.poll = Poll(self.poll) self.venue = data.get("venue") + if self.venue: + self.venue = Venue(self.venue) self.location = data.get("location") if self.location: self.location = Location(self.location) diff --git a/EzTg/types/message/venue.py b/EzTg/types/message/venue.py new file mode 100644 index 0000000..fd01e0e --- /dev/null +++ b/EzTg/types/message/venue.py @@ -0,0 +1,31 @@ +from ..location import Location + +class Venue: + """This object represents a venue. + + Attributes + ---------- + location: `Location` + Venue location. + title: `str` + Name of the venue. + address: `str` + Address of the venue. + foursquare_id: `str` + Optional. Foursquare identifier of the venue. + foursquare_type: `str` + Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + google_place_id: `str` + Optional. Google Places identifier of the venue. + google_place_type: `str` + Optional. Google Places type of the venue. (See supported types.) + """ + + def __init__(self, data): + self.location = Location(data["location"]) + self.title = data["title"] + self.address = data["address"] + self.foursquare_id = data.get("foursquare_id") + self.foursquare_type = data.get("foursquare_type") + self.google_place_id = data.get("google_place_id") + self.google_place_type = data.get("google_place_type") \ No newline at end of file From 02f9a42ea3759591c112ea1f4a8d78b736097cbc Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:10:01 +0200 Subject: [PATCH 105/113] add Sticker class #25 --- EzTg/types/message/file.py | 20 ++++++++++ EzTg/types/message/maskposition.py | 20 ++++++++++ EzTg/types/message/message.py | 3 ++ EzTg/types/message/sticker.py | 63 ++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 EzTg/types/message/file.py create mode 100644 EzTg/types/message/maskposition.py create mode 100644 EzTg/types/message/sticker.py diff --git a/EzTg/types/message/file.py b/EzTg/types/message/file.py new file mode 100644 index 0000000..de036e5 --- /dev/null +++ b/EzTg/types/message/file.py @@ -0,0 +1,20 @@ +class File: + """This object represents a file ready to be downloaded. The file can be downloaded via the link `https://api.telegram.org/file/bot/`. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling `getFile`. + + Attributes + ---------- + file_id: `str` + Unique identifier for this file. + file_unique_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + file_size: `int` + Optional. File size, if known. + file_path: `str` + Optional. File path. Use `https://api.telegram.org/file/bot/` to get the file. + """ + + def __init__(self, data): + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.file_size = data.get("file_size") + self.file_path = data.get("file_path") \ No newline at end of file diff --git a/EzTg/types/message/maskposition.py b/EzTg/types/message/maskposition.py new file mode 100644 index 0000000..523cc56 --- /dev/null +++ b/EzTg/types/message/maskposition.py @@ -0,0 +1,20 @@ +class MaskPosition: + """Represents a point on the mask position of a sticker sent by the bot. + + Attributes + ---------- + point: `str` + The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or “chin”. + x_shift: `float` + Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position. + y_shift: `float` + Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position. + scale: `float` + Mask scaling coefficient. For example, 2.0 means double size. + """ + + def __init__(self, data): + self.point = data["point"] + self.x_shift = data["x_shift"] + self.y_shift = data["y_shift"] + self.scale = data["scale"] \ No newline at end of file diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 9e7c378..64f1c73 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -10,6 +10,7 @@ from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll +from .sticker import Sticker from .venue import Venue from .videonote import VideoNote from .voice import Voice @@ -149,6 +150,8 @@ def __init__(self, data): if self.photo: self.photo = [PhotoSize(p) for p in self.photo] self.sticker = data.get("sticker") + if self.sticker: + self.sticker = Sticker(self.sticker) self.video = data.get("video") self.video_note = data.get("video_note") if self.video_note: diff --git a/EzTg/types/message/sticker.py b/EzTg/types/message/sticker.py new file mode 100644 index 0000000..6316dd1 --- /dev/null +++ b/EzTg/types/message/sticker.py @@ -0,0 +1,63 @@ +from .file import File +from .maskposition import MaskPosition +from .photosize import PhotoSize + +class Sticker: + """This object represents a sticker. + + Attributes + ---------- + file_id: `str` + Unique identifier for this file. + file_unique_id: `str` + Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. + type: `str` + Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. The type of the sticker is independent from its format, which is determined by the fields is_animated and is_video. + width: `int` + Sticker width. + height: `int` + Sticker height. + is_animated: `bool` + True, if the sticker is animated. + is_video: `bool` + True, if the sticker is a video sticker. + thumbnail: `PhotoSize` + Optional. Sticker thumbnail in the .WEBP or .JPG format. + emoji: `str` + Optional. Emoji associated with the sticker. + set_name: `str` + Optional. Name of the sticker set to which the sticker belongs. + premium_animation: `File` + Optional. For premium regular stickers, premium animation for the sticker. + mask_position: `MaskPosition` + Optional. For mask stickers, the position where the mask should be placed. + custom_emoji_id: `str` + Optional. For custom emoji stickers, unique identifier of the custom emoji. + needs_repainting: `bool` + Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places. + file_size: `int` + Optional. File size in bytes. + """ + + def __init__(self, data): + self.file_id = data["file_id"] + self.file_unique_id = data["file_unique_id"] + self.type = data["type"] + self.width = data["width"] + self.height = data["height"] + self.is_animated = data["is_animated"] + self.is_video = data["is_video"] + self.thumbnail = data.get("thumb") + if self.thumbnail: + self.thumbnail = PhotoSize(self.thumbnail) + self.emoji = data.get("emoji") + self.set_name = data.get("set_name") + self.premium_animation = data.get("premium_animation") + if self.premium_animation: + self.premium_animation = File(self.premium_animation) + self.mask_position = data.get("mask_position") + if self.mask_position: + self.mask_position = MaskPosition(self.mask_position) + self.custom_emoji_id = data.get("custom_emoji_id") + self.needs_repainting = data.get("needs_repainting") + self.file_size = data.get("file_size") \ No newline at end of file From 68b850f09b754addabd95aab7cea8dfa20e9cc94 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:18:16 +0200 Subject: [PATCH 106/113] added inlinekeyboard to be added to message --- EzTg/types/inlinekeyboard.py | 6 ++++-- EzTg/types/message/message.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/EzTg/types/inlinekeyboard.py b/EzTg/types/inlinekeyboard.py index 163a02d..24f79c6 100644 --- a/EzTg/types/inlinekeyboard.py +++ b/EzTg/types/inlinekeyboard.py @@ -1,7 +1,9 @@ class InlineKeyboard: - def __init__(self): - """Create a new inline keyboard""" + 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: + self.keyboard = data self.keyboard = [[]] def url(self, text, url): diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 64f1c73..9715fd6 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -7,6 +7,7 @@ from .dice import Dice from .document import Document from .game import Game +from ..inlinekeyboard import InlineKeyboard from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll @@ -111,6 +112,8 @@ class Message: Optional. Service message: the group has been created. supergroup_chat_created: `bool` Optional. Service message: the supergroup has been created. + reply_markup: `InlineKeyboard` + Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. """ def __init__(self, data): @@ -196,3 +199,8 @@ def __init__(self, data): self.new_chat_photo = [PhotoSize(p) for p in self.new_chat_photo] self.delete_chat_photo = data.get("delete_chat_photo") self.group_chat_created = data.get("group_chat_created") + self.supergroup_chat_created = data.get("supergroup_chat_created") + self.reply_markup = data.get("reply_markup") + if self.reply_markup: + self.reply_markup = InlineKeyboard(self.reply_markup) + \ No newline at end of file From a80b659a3b14f9440eaa86853104e5a2a2eef8a2 Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:20:36 +0200 Subject: [PATCH 107/113] update message init --- EzTg/types/message/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/EzTg/types/message/__init__.py b/EzTg/types/message/__init__.py index 82650ae..0f85139 100644 --- a/EzTg/types/message/__init__.py +++ b/EzTg/types/message/__init__.py @@ -1,6 +1,17 @@ from .animation import Animation from .audio import Audio +from .contact import Contact +from .dice import Dice from .document import Document -from .message import Message +from .file import File +from .game import Game +from .maskposition import MaskPosition +from .messageentity import MessageEntity +from .photosize import PhotoSize +from .poll import Poll +from .polloption import PollOption +from .sticker import Sticker +from .venue import Venue from .video import Video from .videonote import VideoNote +from .voice import Voice \ No newline at end of file From 6040d05abade2fbed7d69eb9e87b56a6255d9e3d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Jun 2023 17:20:47 +0000 Subject: [PATCH 108/113] Restyled by autopep8 --- EzTg/types/message/__init__.py | 2 +- EzTg/types/message/contact.py | 6 +++--- EzTg/types/message/dice.py | 4 ++-- EzTg/types/message/file.py | 4 ++-- EzTg/types/message/game.py | 8 +++++--- EzTg/types/message/maskposition.py | 4 ++-- EzTg/types/message/message.py | 1 - EzTg/types/message/poll.py | 10 ++++++---- EzTg/types/message/polloption.py | 6 +++--- EzTg/types/message/sticker.py | 5 +++-- EzTg/types/message/venue.py | 5 +++-- setup.py | 3 +-- 12 files changed, 31 insertions(+), 27 deletions(-) diff --git a/EzTg/types/message/__init__.py b/EzTg/types/message/__init__.py index 0f85139..4e0a779 100644 --- a/EzTg/types/message/__init__.py +++ b/EzTg/types/message/__init__.py @@ -14,4 +14,4 @@ from .venue import Venue from .video import Video from .videonote import VideoNote -from .voice import Voice \ No newline at end of file +from .voice import Voice diff --git a/EzTg/types/message/contact.py b/EzTg/types/message/contact.py index f2a9db0..7c0432f 100644 --- a/EzTg/types/message/contact.py +++ b/EzTg/types/message/contact.py @@ -1,6 +1,6 @@ class Contact: """This object represents a phone contact. - + Attributes ---------- phone_number: `str` @@ -13,10 +13,10 @@ class Contact: Optional. Contact's user identifier in Telegram. vcard: `str` Optional. Additional data about the contact in the form of a vCard.""" - + def __init__(self, data): self.phone_number = data["phone_number"] self.first_name = data["first_name"] self.last_name = data.get("last_name") self.user_id = data.get("user_id") - self.vcard = data.get("vcard") \ No newline at end of file + self.vcard = data.get("vcard") diff --git a/EzTg/types/message/dice.py b/EzTg/types/message/dice.py index 061e921..735d4b7 100644 --- a/EzTg/types/message/dice.py +++ b/EzTg/types/message/dice.py @@ -1,6 +1,6 @@ class Dice: """This object represents an animated emoji that displays a random value. - + Attributes ---------- emoji: `str` @@ -11,4 +11,4 @@ class Dice: def __init__(self, data): self.emoji = data["emoji"] - self.value = data["value"] \ No newline at end of file + self.value = data["value"] diff --git a/EzTg/types/message/file.py b/EzTg/types/message/file.py index de036e5..67d8b87 100644 --- a/EzTg/types/message/file.py +++ b/EzTg/types/message/file.py @@ -1,6 +1,6 @@ class File: """This object represents a file ready to be downloaded. The file can be downloaded via the link `https://api.telegram.org/file/bot/`. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling `getFile`. - + Attributes ---------- file_id: `str` @@ -17,4 +17,4 @@ def __init__(self, data): self.file_id = data["file_id"] self.file_unique_id = data["file_unique_id"] self.file_size = data.get("file_size") - self.file_path = data.get("file_path") \ No newline at end of file + self.file_path = data.get("file_path") diff --git a/EzTg/types/message/game.py b/EzTg/types/message/game.py index bfb8839..c3567da 100644 --- a/EzTg/types/message/game.py +++ b/EzTg/types/message/game.py @@ -2,9 +2,10 @@ from .photosize import PhotoSize from .messageentity import MessageEntity + class Game: """This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. - + Attributes ---------- title: `str` @@ -26,5 +27,6 @@ def __init__(self, data): self.description = data["description"] self.photo = [PhotoSize(photo) for photo in data["photo"]] self.text = data.get("text") - self.text_entities = [MessageEntity(entity) for entity in data.get("text_entities", [])] - self.animation = Animation(data.get("animation")) \ No newline at end of file + self.text_entities = [MessageEntity( + entity) for entity in data.get("text_entities", [])] + self.animation = Animation(data.get("animation")) diff --git a/EzTg/types/message/maskposition.py b/EzTg/types/message/maskposition.py index 523cc56..77d7f4b 100644 --- a/EzTg/types/message/maskposition.py +++ b/EzTg/types/message/maskposition.py @@ -1,6 +1,6 @@ class MaskPosition: """Represents a point on the mask position of a sticker sent by the bot. - + Attributes ---------- point: `str` @@ -17,4 +17,4 @@ def __init__(self, data): self.point = data["point"] self.x_shift = data["x_shift"] self.y_shift = data["y_shift"] - self.scale = data["scale"] \ No newline at end of file + self.scale = data["scale"] diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 9715fd6..9a8a1f1 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -203,4 +203,3 @@ def __init__(self, data): self.reply_markup = data.get("reply_markup") if self.reply_markup: self.reply_markup = InlineKeyboard(self.reply_markup) - \ No newline at end of file diff --git a/EzTg/types/message/poll.py b/EzTg/types/message/poll.py index c0f8d51..9e80ad2 100644 --- a/EzTg/types/message/poll.py +++ b/EzTg/types/message/poll.py @@ -1,9 +1,10 @@ from .messageentity import MessageEntity from .polloption import PollOption + class Poll: """This object contains information about a poll. - + Attributes ---------- id: `str` @@ -32,7 +33,7 @@ class Poll: Optional. Amount of time in seconds the poll will be active after creation. close_date: `int` Optional. Point in time (Unix timestamp) when the poll will be automatically closed.""" - + def __init__(self, data): self.id = data["id"] self.question = data["question"] @@ -44,6 +45,7 @@ def __init__(self, data): self.allows_multiple_answers = data["allows_multiple_answers"] 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", [])] + self.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") \ No newline at end of file + self.close_date = data.get("close_date") diff --git a/EzTg/types/message/polloption.py b/EzTg/types/message/polloption.py index 89873cd..0222e6f 100644 --- a/EzTg/types/message/polloption.py +++ b/EzTg/types/message/polloption.py @@ -1,13 +1,13 @@ class PollOption: """Represents one answer option in a poll. - + Attributes ---------- text: `str` Option text, 1-100 characters. voter_count: `int` Number of users that voted for this option""" - + def __init__(self, data): self.text = data["text"] - self.voter_count = data["voter_count"] \ No newline at end of file + self.voter_count = data["voter_count"] diff --git a/EzTg/types/message/sticker.py b/EzTg/types/message/sticker.py index 6316dd1..b4d9c2b 100644 --- a/EzTg/types/message/sticker.py +++ b/EzTg/types/message/sticker.py @@ -2,9 +2,10 @@ from .maskposition import MaskPosition from .photosize import PhotoSize + class Sticker: """This object represents a sticker. - + Attributes ---------- file_id: `str` @@ -60,4 +61,4 @@ def __init__(self, data): self.mask_position = MaskPosition(self.mask_position) self.custom_emoji_id = data.get("custom_emoji_id") self.needs_repainting = data.get("needs_repainting") - self.file_size = data.get("file_size") \ No newline at end of file + self.file_size = data.get("file_size") diff --git a/EzTg/types/message/venue.py b/EzTg/types/message/venue.py index fd01e0e..96cc462 100644 --- a/EzTg/types/message/venue.py +++ b/EzTg/types/message/venue.py @@ -1,8 +1,9 @@ from ..location import Location + class Venue: """This object represents a venue. - + Attributes ---------- location: `Location` @@ -28,4 +29,4 @@ def __init__(self, data): self.foursquare_id = data.get("foursquare_id") self.foursquare_type = data.get("foursquare_type") self.google_place_id = data.get("google_place_id") - self.google_place_type = data.get("google_place_type") \ No newline at end of file + self.google_place_type = data.get("google_place_type") 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 d0b0d1653506f1afc4f8d7df259025dfc9505ff0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Jun 2023 17:20:50 +0000 Subject: [PATCH 109/113] Restyled by black --- EzTg/EzTg.py | 42 +++++++++++++++---------------- EzTg/types/chat/chat.py | 9 ++++--- EzTg/types/inlinekeyboard.py | 11 ++------ EzTg/types/message/game.py | 5 ++-- EzTg/types/message/message.py | 4 +-- EzTg/types/message/poll.py | 8 +++--- EzTg/types/replykeyboardmarkup.py | 41 ++++++++++++++++-------------- EzTg/types/user/user.py | 3 +-- 8 files changed, 59 insertions(+), 64 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index f331ee2..7fd3033 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -6,13 +6,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__ @@ -46,9 +51,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) @@ -145,9 +150,7 @@ 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, @@ -205,11 +208,9 @@ 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 @@ -351,10 +352,7 @@ 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 @@ -382,9 +380,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. diff --git a/EzTg/types/chat/chat.py b/EzTg/types/chat/chat.py index 8494a80..3d99768 100644 --- a/EzTg/types/chat/chat.py +++ b/EzTg/types/chat/chat.py @@ -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") @@ -95,7 +95,8 @@ 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") diff --git a/EzTg/types/inlinekeyboard.py b/EzTg/types/inlinekeyboard.py index 24f79c6..6b1f277 100644 --- a/EzTg/types/inlinekeyboard.py +++ b/EzTg/types/inlinekeyboard.py @@ -1,5 +1,4 @@ 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: @@ -38,10 +37,7 @@ 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. @@ -53,10 +49,7 @@ 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.""" diff --git a/EzTg/types/message/game.py b/EzTg/types/message/game.py index c3567da..7ae570c 100644 --- a/EzTg/types/message/game.py +++ b/EzTg/types/message/game.py @@ -27,6 +27,7 @@ def __init__(self, data): self.description = data["description"] self.photo = [PhotoSize(photo) for photo in data["photo"]] self.text = data.get("text") - self.text_entities = [MessageEntity( - entity) for entity in data.get("text_entities", [])] + self.text_entities = [ + MessageEntity(entity) for entity in data.get("text_entities", []) + ] self.animation = Animation(data.get("animation")) diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 9a8a1f1..57f9923 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -165,9 +165,7 @@ 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: diff --git a/EzTg/types/message/poll.py b/EzTg/types/message/poll.py index 9e80ad2..38ddc49 100644 --- a/EzTg/types/message/poll.py +++ b/EzTg/types/message/poll.py @@ -32,7 +32,8 @@ class Poll: open_period: `int` Optional. Amount of time in seconds the poll will be active after creation. close_date: `int` - Optional. Point in time (Unix timestamp) when the poll will be automatically closed.""" + Optional. Point in time (Unix timestamp) when the poll will be automatically closed. + """ def __init__(self, data): self.id = data["id"] @@ -45,7 +46,8 @@ def __init__(self, data): self.allows_multiple_answers = data["allows_multiple_answers"] 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", [])] + self.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") diff --git a/EzTg/types/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py index 9a2d921..6833f32 100644 --- a/EzTg/types/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -1,5 +1,4 @@ class ReplyKeyboardMarkup: - def __init__( self, is_persistent=False, @@ -57,15 +56,17 @@ 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, @@ -96,15 +97,17 @@ 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.""" diff --git a/EzTg/types/user/user.py b/EzTg/types/user/user.py index 2eab1ba..7a0db55 100644 --- a/EzTg/types/user/user.py +++ b/EzTg/types/user/user.py @@ -36,6 +36,5 @@ 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") From 4a8300cf72fd84a2b666193a1e477d83c56f5a73 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Jun 2023 17:20:50 +0000 Subject: [PATCH 110/113] Restyled by isort --- EzTg/EzTg.py | 3 ++- EzTg/types/message/game.py | 2 +- EzTg/types/message/message.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index 7fd3033..c91d14d 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -1,6 +1,7 @@ -import aiohttp import asyncio +import aiohttp + from .types.chat.chat import Chat from .types.user.user import User diff --git a/EzTg/types/message/game.py b/EzTg/types/message/game.py index 7ae570c..838e162 100644 --- a/EzTg/types/message/game.py +++ b/EzTg/types/message/game.py @@ -1,6 +1,6 @@ from .animation import Animation -from .photosize import PhotoSize from .messageentity import MessageEntity +from .photosize import PhotoSize class Game: diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 57f9923..4df6ee1 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -1,4 +1,5 @@ from ..chat.chat import Chat +from ..inlinekeyboard import InlineKeyboard from ..location import Location from ..user.user import User from .animation import Animation @@ -7,7 +8,6 @@ from .dice import Dice from .document import Document from .game import Game -from ..inlinekeyboard import InlineKeyboard from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll From 6c584294a899cf732955e59863f4a4b7b79c82d8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 29 Jun 2023 17:20:54 +0000 Subject: [PATCH 111/113] Restyled by yapf --- EzTg/EzTg.py | 45 ++++++++++++++++--------------- EzTg/types/chat/chat.py | 9 +++---- EzTg/types/inlinekeyboard.py | 11 ++++++-- EzTg/types/message/message.py | 4 ++- EzTg/types/message/poll.py | 3 ++- EzTg/types/replykeyboardmarkup.py | 41 +++++++++++++--------------- EzTg/types/user/user.py | 3 ++- setup.py | 3 ++- 8 files changed, 65 insertions(+), 54 deletions(-) diff --git a/EzTg/EzTg.py b/EzTg/EzTg.py index c91d14d..077a54b 100644 --- a/EzTg/EzTg.py +++ b/EzTg/EzTg.py @@ -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__ @@ -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) @@ -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: @@ -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, @@ -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 @@ -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 @@ -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. diff --git a/EzTg/types/chat/chat.py b/EzTg/types/chat/chat.py index 3d99768..8494a80 100644 --- a/EzTg/types/chat/chat.py +++ b/EzTg/types/chat/chat.py @@ -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") @@ -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") diff --git a/EzTg/types/inlinekeyboard.py b/EzTg/types/inlinekeyboard.py index 6b1f277..24f79c6 100644 --- a/EzTg/types/inlinekeyboard.py +++ b/EzTg/types/inlinekeyboard.py @@ -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: @@ -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. @@ -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.""" diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 4df6ee1..2388b89 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -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: diff --git a/EzTg/types/message/poll.py b/EzTg/types/message/poll.py index 38ddc49..11293c6 100644 --- a/EzTg/types/message/poll.py +++ b/EzTg/types/message/poll.py @@ -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") diff --git a/EzTg/types/replykeyboardmarkup.py b/EzTg/types/replykeyboardmarkup.py index 6833f32..9a2d921 100644 --- a/EzTg/types/replykeyboardmarkup.py +++ b/EzTg/types/replykeyboardmarkup.py @@ -1,4 +1,5 @@ class ReplyKeyboardMarkup: + def __init__( self, is_persistent=False, @@ -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, @@ -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.""" diff --git a/EzTg/types/user/user.py b/EzTg/types/user/user.py index 7a0db55..2eab1ba 100644 --- a/EzTg/types/user/user.py +++ b/EzTg/types/user/user.py @@ -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") 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/", From 8bc730ce4046b2242cc57360696eddedf638e20a Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Sun, 20 Aug 2023 13:07:18 +0200 Subject: [PATCH 112/113] Add MessageAutoDeleteTimerChanged #25 --- EzTg/types/message/__init__.py | 1 + EzTg/types/message/message.py | 9 +++++++++ .../message/message_auto_delete_timer_changed.py | 11 +++++++++++ 3 files changed, 21 insertions(+) create mode 100644 EzTg/types/message/message_auto_delete_timer_changed.py diff --git a/EzTg/types/message/__init__.py b/EzTg/types/message/__init__.py index 4e0a779..1cf733f 100644 --- a/EzTg/types/message/__init__.py +++ b/EzTg/types/message/__init__.py @@ -6,6 +6,7 @@ from .file import File from .game import Game from .maskposition import MaskPosition +from .message_auto_delete_timer_changed import MessageAutoDeleteTimerChanged from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index 2388b89..cb76784 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -8,6 +8,7 @@ from .dice import Dice from .document import Document from .game import Game +from .message_auto_delete_timer_changed import MessageAutoDeleteTimerChanged from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll @@ -112,6 +113,10 @@ class Message: Optional. Service message: the group has been created. supergroup_chat_created: `bool` Optional. Service message: the supergroup has been created. + channgel_chat_created: `bool` + Optional. Service message: the channel has been created. + message_auto_delete_timer_changed: `MessageAutoDeleteTimerChanged` + Optional. Service message: auto-delete timer settings changed in the chat. reply_markup: `InlineKeyboard` Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. """ @@ -200,6 +205,10 @@ def __init__(self, data): self.delete_chat_photo = data.get("delete_chat_photo") self.group_chat_created = data.get("group_chat_created") self.supergroup_chat_created = data.get("supergroup_chat_created") + self.channel_chat_created = data.get("channgel_chat_created") + self.message_auto_delete_timer_changed = data.get("message_auto_delete_timer_changed") + if self.message_auto_delete_timer_changed: + self.message_auto_delete_timer_changed = MessageAutoDeleteTimerChanged(self.message_auto_delete_timer_changed) self.reply_markup = data.get("reply_markup") if self.reply_markup: self.reply_markup = InlineKeyboard(self.reply_markup) diff --git a/EzTg/types/message/message_auto_delete_timer_changed.py b/EzTg/types/message/message_auto_delete_timer_changed.py new file mode 100644 index 0000000..8f566c5 --- /dev/null +++ b/EzTg/types/message/message_auto_delete_timer_changed.py @@ -0,0 +1,11 @@ +class MessageAutoDeleteTimerChanged: + """Represents a service message about a change in auto-delete timer settings. + + Attributes + ---------- + message_auto_delete_time: `int` + New auto-delete time for messages in the chat; in seconds + """ + + def __init__(self, data): + self.message_auto_delete_time = data["message_auto_delete_time"] \ No newline at end of file From f24b216c7c4cf1ebb13f67ff75878ace90598ffd Mon Sep 17 00:00:00 2001 From: Hexye <65314629+HexyeDEV@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:45:02 +0100 Subject: [PATCH 113/113] added many classes #25 --- EzTg/types/message/__init__.py | 1 + EzTg/types/message/chat_shared.py | 14 + EzTg/types/message/external_reply_info.py | 138 ++++++++++ EzTg/types/message/giveaway.py | 34 +++ EzTg/types/message/invoice.py | 24 ++ EzTg/types/message/link_preview_options.py | 22 ++ .../message/maybe_inaccessible_message.py | 34 +++ EzTg/types/message/message.py | 249 ++++++++++++++---- EzTg/types/message/message_origin.py | 100 +++++++ EzTg/types/message/order_info.py | 24 ++ EzTg/types/message/shipping_address.py | 26 ++ EzTg/types/message/story.py | 5 + EzTg/types/message/successful_payment.py | 33 +++ EzTg/types/message/text_quote.py | 19 ++ EzTg/types/message/users_shared.py | 14 + EzTg/types/message/write_access_allowed.py | 17 ++ 16 files changed, 704 insertions(+), 50 deletions(-) create mode 100644 EzTg/types/message/chat_shared.py create mode 100644 EzTg/types/message/external_reply_info.py create mode 100644 EzTg/types/message/giveaway.py create mode 100644 EzTg/types/message/invoice.py create mode 100644 EzTg/types/message/link_preview_options.py create mode 100644 EzTg/types/message/maybe_inaccessible_message.py create mode 100644 EzTg/types/message/message_origin.py create mode 100644 EzTg/types/message/order_info.py create mode 100644 EzTg/types/message/shipping_address.py create mode 100644 EzTg/types/message/story.py create mode 100644 EzTg/types/message/successful_payment.py create mode 100644 EzTg/types/message/text_quote.py create mode 100644 EzTg/types/message/users_shared.py create mode 100644 EzTg/types/message/write_access_allowed.py diff --git a/EzTg/types/message/__init__.py b/EzTg/types/message/__init__.py index 1cf733f..94e4a2a 100644 --- a/EzTg/types/message/__init__.py +++ b/EzTg/types/message/__init__.py @@ -5,6 +5,7 @@ from .document import Document from .file import File from .game import Game +from .invoice import Invoice from .maskposition import MaskPosition from .message_auto_delete_timer_changed import MessageAutoDeleteTimerChanged from .messageentity import MessageEntity diff --git a/EzTg/types/message/chat_shared.py b/EzTg/types/message/chat_shared.py new file mode 100644 index 0000000..e63f581 --- /dev/null +++ b/EzTg/types/message/chat_shared.py @@ -0,0 +1,14 @@ +class ChatShared: + """This object contains information about the chat whose identifier was shared with the bot using a KeyboardButtonRequestChat button. + + Attributes + ---------- + request_id: `int` + Identifier of the request. + chat_id: `int` + Identifier of the shared chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot may not have access to the chat and could be unable to use this identifier, unless the chat is already known to the bot by some other means. + """ + + def __init__(self, data): + self.request_id = data["request_id"] + self.chat_id = data["chat_id"] \ No newline at end of file diff --git a/EzTg/types/message/external_reply_info.py b/EzTg/types/message/external_reply_info.py new file mode 100644 index 0000000..b5f1a04 --- /dev/null +++ b/EzTg/types/message/external_reply_info.py @@ -0,0 +1,138 @@ +from ..chat import Chat +from .animation import Animation +from .audio import Audio +from .document import Document +from .link_preview_options import LinkPreviewOptions +from ..location import Location +from .photosize import PhotoSize +from .sticker import Sticker +from .video import Video +from .videonote import VideoNote +from .voice import Voice +from .contact import Contact +from .dice import Dice +from .game import Game +from .giveaway import Giveaway +from .invoice import Invoice +from .message_origin import MessageOrigin +from .poll import Poll +from .story import Story +from .venue import Venue + +class ExternalReplyInfo: + """This object contains information about a message that is being replied to, which may come from another chat or forum topic. + + Attributes: + ----------- + origin: `MessageOrigin` + Origin of the message replied to by the given message. + chat: `Chat` + Optional. Chat the original message belongs to. Available only if the chat is a supergroup or a channel. + message_id: `int` + Optional. Unique message identifier inside the original chat. Available only if the original chat is a supergroup or a channel. + link_preview_options: `LinkPreviewOptions` + Optional. Options used for link preview generation for the original message, if it is a text message. + animation: `Animation` + Optional. Message is an animation, information about the animation. + audio: `Audio` + Optional. Message is an audio file, information about the file + document: `Document` + Optional. Message is a general file, information about the file + photo: `array of PhotoSize` + Optional. Message is a photo, available sizes of the photo. + sticker: `Sticker` + Optional. Message is a sticker, information about the sticker. + story: `Story` + Optional. Message is a forwarded story + video: `Video` + Optional. Message is a video, information about the video. + video_note: `VideoNote` + Optional. Message is a video note, information about the video message. + voice: `Voice` + Optional. Message is a voice message, information about the file. + has_media_spoiler: `bool` + Optional. True, if the message media is covered by a spoiler animation. + contact: `Contact` + Optional. Message is a shared contact, information about the contact. + dice: `Dice` + Optional. Message is a dice with random value from 1 to 6. + game: `Game` + Optional. Message is a game, information about the game. + giveaway: `Giveaway` + Optional. Message is a scheduled giveaway, information about the giveaway. + giveaway_winners: `GiveawayWinners` + Optional. A giveaway with public winners was completed. + invoice: `Invoice` + Optional. Message is an invoice for a payment, information about the invoice. + location: `Location` + Optional. Message is a shared location, information about the location + poll: `Poll` + Optional. Message is a native poll, information about the poll. + venue: `Venue` + Optional. Message is a venue, information about the venue.""" + + def __init__(self, data): + self.origin = MessageOrigin(data["origin"]) + self.chat = data.get("chat") + if self.chat: + self.chat = Chat(self.chat) + self.message_id = data.get("message_id") + self.link_preview_options = data.get("link_preview_options") + if self.link_preview_options: + self.link_preview_options = LinkPreviewOptions( + self.link_preview_options) + self.animation = data.get("animation") + if self.animation: + self.animation = Animation(self.animation) + self.audio = data.get("audio") + if self.audio: + self.audio = Audio(self.audio) + self.document = data.get("document") + if self.document: + self.document = Document(self.document) + self.photo = data.get("photo") + if self.photo: + self.photo = [PhotoSize(photo) for photo in self.photo] + self.sticker = data.get("sticker") + if self.sticker: + self.sticker = Sticker(self.sticker) + self.story = data.get("story") + if self.story: + self.story = Story(self.story) + self.video = data.get("video") + if self.video: + self.video = Video(self.video) + self.video_note = data.get("video_note") + if self.video_note: + self.video_note = VideoNote(self.video_note) + self.voice = data.get("voice") + if self.voice: + self.voice = Voice(self.voice) + self.has_media_spoiler = data.get("has_media_spoiler") + self.contact = data.get("contact") + if self.contact: + self.contact = Contact(self.contact) + self.dice = data.get("dice") + if self.dice: + self.dice = Dice(self.dice) + self.game = data.get("game") + if self.game: + self.game = Game(self.game) + self.giveaway = data.get("giveaway") + if self.giveaway: + self.giveaway = Giveaway(self.giveaway) + self.giveaway_winners = data.get("giveaway_winners") + if self.giveaway_winners: + self.giveaway_winners = GiveawayWinners(self.giveaway_winners) + self.invoice = data.get("invoice") + if self.invoice: + self.invoice = Invoice(self.invoice) + self.location = data.get("location") + if self.location: + self.location = Location(self.location) + self.poll = data.get("poll") + if self.poll: + self.poll = Poll(self.poll) + self.venue = data.get("venue") + if self.venue: + self.venue = Venue(self.venue) \ No newline at end of file diff --git a/EzTg/types/message/giveaway.py b/EzTg/types/message/giveaway.py new file mode 100644 index 0000000..08bc7b8 --- /dev/null +++ b/EzTg/types/message/giveaway.py @@ -0,0 +1,34 @@ +from ..chat import Chat + +class Giveaway: + """This object represents a message about a scheduled giveaway. + + Attributes + ---------- + chats: `array of Chat` + The list of chats which the user must join to participate in the giveaway. + winners_selection_date: `int` + Point in time (Unix timestamp) when winners of the giveaway will be selected. + winner_count: `int` + The number of users which are supposed to be selected as winners of the giveaway. + only_new_members: `bool` + Optional. True, if only users who join the chats after the giveaway started should be eligible to win. + has_public_winners: `bool` + Optional. True, if the list of giveaway winners will be visible to everyone. + prize_description: `str` + Optional. Description of additional giveaway prize. + country_codes: `array of str` + Optional. A list of two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which eligible users for the giveaway must come. If empty, then all users can participate in the giveaway. Users with a phone number that was bought on Fragment can always participate in giveaways. + premium_subscription_month_count: `int` + Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for. + """ + + def __init__(self, data): + self.chats = [Chat(chat) for chat in data["chats"]] + self.winners_selection_date = data["winners_selection_date"] + self.winner_count = data["winner_count"] + self.only_new_members = data.get("only_new_members") + self.has_public_winners = data.get("has_public_winners") + self.prize_description = data.get("prize_description") + self.country_codes = data.get("country_codes") + self.premium_subscription_month_count = data.get("premium_subscription_month_count") \ No newline at end of file diff --git a/EzTg/types/message/invoice.py b/EzTg/types/message/invoice.py new file mode 100644 index 0000000..65bb256 --- /dev/null +++ b/EzTg/types/message/invoice.py @@ -0,0 +1,24 @@ +class Invoice: + """ + This object contains basic information about an invoice. + + Attributes: + ----------- + title: `str` + Product name + description: `str` + Product description + start_parameter: `str` + Unique bot deep-linking parameter that can be used to generate this invoice + currency: `str` + Three-letter ISO 4217 currency code + total_amount: `int` + Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). + """ + + def __init__(self, data): + self.title = data["title"] + self.description = data["description"] + self.start_parameter = data["start_parameter"] + self.currency = data["currency"] + self.total_amount = data["total_amount"] \ No newline at end of file diff --git a/EzTg/types/message/link_preview_options.py b/EzTg/types/message/link_preview_options.py new file mode 100644 index 0000000..6f40e0b --- /dev/null +++ b/EzTg/types/message/link_preview_options.py @@ -0,0 +1,22 @@ +class LinkPreviewOptions: + """Describes the options used for link preview generation. + + Attributes: + ----------- + is_disabled: `bool` + Optional. True, if the link preview is disabled. + url: `str` + Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used. + prefer_small_media: `bool` + Optional. True, if the media in the link preview is suppposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview. + prefer_large_media: `bool` + Optional. True, if the media in the link preview is suppposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview. + show_above_text: `bool` + Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text.""" + + def __init__(self, data): + self.is_disabled = data.get("is_disabled") + self.url = data.get("url") + self.prefer_small_media = data.get("prefer_small_media") + self.prefer_large_media = data.get("prefer_large_media") + self.show_above_text = data.get("show_above_text") \ No newline at end of file diff --git a/EzTg/types/message/maybe_inaccessible_message.py b/EzTg/types/message/maybe_inaccessible_message.py new file mode 100644 index 0000000..9218ca6 --- /dev/null +++ b/EzTg/types/message/maybe_inaccessible_message.py @@ -0,0 +1,34 @@ +from ..chat import Chat + +class MaybeInaccessibleMessage: + """This object describes a message that can be inaccessible to the bot. It can be one of + + - `Message` + - `InaccessibleMessage`""" + + def __init__(self, data: dict): + self.type = data["type"] + if self.type == "message": + from .message import Message # Lazy import to avoid circular imports until finding a better solution + return Message(data) + elif self.type == "inaccessible_message": + return InaccessibleMessage(data) + else: + raise ValueError(f"Unknown message type: {self.type}") + +class InaccessibleMessage: + """This object describes a message that was deleted or is otherwise inaccessible to the bot. + + Attributes: + ----------- + chat: `Chat` + Chat the message belonged to. + message_id: `int` + Unique message identifier inside the chat. + date: `int` + Always 0. The field can be used to differentiate regular and inaccessible messages.""" + + def __init__(self, data: dict): + self.chat = Chat(data["chat"]) + self.message_id = data["message_id"] + self.date = data["date"] \ No newline at end of file diff --git a/EzTg/types/message/message.py b/EzTg/types/message/message.py index cb76784..b1ffbde 100644 --- a/EzTg/types/message/message.py +++ b/EzTg/types/message/message.py @@ -4,18 +4,31 @@ from ..user.user import User from .animation import Animation from .audio import Audio +from .chat_shared import ChatShared from .contact import Contact from .dice import Dice from .document import Document +from .external_reply_info import ExternalReplyInfo from .game import Game +from .giveaway import Giveaway +from .invoice import Invoice +from .link_preview_options import LinkPreviewOptions +from .maybe_inaccessible_message import MaybeInaccessibleMessage from .message_auto_delete_timer_changed import MessageAutoDeleteTimerChanged +from .message_origin import MessageOrigin from .messageentity import MessageEntity from .photosize import PhotoSize from .poll import Poll from .sticker import Sticker +from .story import Story +from .successful_payment import SuccessfulPayment +from .text_quote import TextQuote +from .users_shared import UsersShared from .venue import Venue +from .video import Video from .videonote import VideoNote from .voice import Voice +from .write_access_allowed import WriteAccessAllowed class Message: @@ -27,7 +40,7 @@ class Message: Unique message identifier inside this chat. message_thread_id: `int` Optional. Unique identifier of a message thread to which the message belongs; for supergroups only - from_user: `User` + from: `User` Optional. Sender, empty for messages sent to channels. sender_chat: `Chat` Optional. Sender of the message, sent on behalf of a chat. The channel itself for channel messages. The supergroup itself for messages from anonymous group administrators. The linked channel for messages automatically forwarded to the discussion group. @@ -35,46 +48,42 @@ class Message: Date the message was sent in Unix time. chat: `Chat` Conversation the message belongs to. - forward_from: `User` + forward_origin: `MessageOrigin` Optional. For forwarded messages, sender of the original message. - forward_from_chat: `Chat` - Optional. For messages forwarded from channels, information about the original channel. - forward_from_message_id: `int` - Optional. For messages forwarded from channels, identifier of the original message in the channel. - forward_signature: `str` - Optional. For messages forwarded from channels, signature of the post author if present. - forward_sender_name: `str` - Optional. For messages forwarded from channels, sender's name for messages forwarded to the discussion group. - forward_date: `int` - Optional. For forwarded messages, date the original message was sent in Unix time. is_topic_message: `bool` - Optional. True, if the message is sent to a forum topic - is_automatic_forward: `bool` - Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group + Optional. True, if message is sent to a forum topic. + is_automaitc_forward: `bool` + Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group. reply_to_message: `Message` Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. - via_bot: `User` - Optional. Bot through which the message was sent. + external_reply: `ExternalReplyInfo` + Optional. Information about the message that is being replied to, which may come from another chat or forum topic. + quote: `TextQuote` + Optional. For replies that quote part of the original message, the quoted part of the message edit_date: `int` - Optional. Date the message was last edited in Unix time. - has_protected_content: `bool` - Optional. True, if the message can't be forwarded. + Optional. Date the message was last edited in Unix time media_group_id: `str` Optional. The unique identifier of a media message group this message belongs to. author_signature: `str` - Optional. Signature of the post author for messages in channels. + Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator. text: `str` Optional. For text messages, the actual UTF-8 text of the message. + entities: `Array of MessageEntity` + Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text + link_preview_options: `LinkPreviewOptions` + Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed. animation: `Animation` Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set. audio: `Audio` Optional. Message is an audio file, information about the file. document: `Document` Optional. Message is a general file, information about the file. - photo: `list[PhotoSize]` + photo: `Array of PhotoSize` Optional. Message is a photo, available sizes of the photo. sticker: `Sticker` Optional. Message is a sticker, information about the sticker. + story: `Story` + Optional. Message is a forwarded story. video: `Video` Optional. Message is a video, information about the video. video_note: `VideoNote` @@ -82,41 +91,93 @@ class Message: voice: `Voice` Optional. Message is a voice message, information about the file. caption: `str` - Optional. Caption for the animation, audio, document, photo, video or voice, 0-1024 characters. - caption_entities: `list[MessageEntity]` + Optional. Caption for the animation, audio, document, photo, video or voice + caption_entities: `Array of MessageEntity` Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption. has_media_spoiler: `bool` - Optional. True, if the message media is covered by a spoiler animation + Optional. True, if the message media is covered by a spoiler animation. contact: `Contact` Optional. Message is a shared contact, information about the contact. dice: `Dice` - Optional. Message is a dice with random value from 1 to 6. + Optional. Message is a dice with random value. game: `Game` Optional. Message is a game, information about the game. poll: `Poll` Optional. Message is a native poll, information about the poll. venue: `Venue` - Optional. Message is a venue, information about the venue. + Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set location: `Location` Optional. Message is a shared location, information about the location. - new_chat_members: `list[User]` + new_chat_members: `Array of User` Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members). left_chat_member: `User` Optional. A member was removed from the group, information about them (this member may be the bot itself). new_chat_title: `str` Optional. A chat title was changed to this value. - new_chat_photo: `list[PhotoSize]` + new_chat_photo: `Array of PhotoSize` Optional. A chat photo was change to this value. delete_chat_photo: `bool` Optional. Service message: the chat photo was deleted. group_chat_created: `bool` Optional. Service message: the group has been created. supergroup_chat_created: `bool` - Optional. Service message: the supergroup has been created. - channgel_chat_created: `bool` - Optional. Service message: the channel has been created. + Optional. Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can't be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. + channel_chat_created: `bool` + Optional. Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can't be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel. message_auto_delete_timer_changed: `MessageAutoDeleteTimerChanged` Optional. Service message: auto-delete timer settings changed in the chat. + migrate_to_chat_id: `int` + Optional. The group has been migrated to a supergroup with the specified identifier. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. + migrate_from_chat_id: `int` + Optional. The supergroup has been migrated from a group with the specified identifier. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. + pinned_message: `MaybeInaccessibleMessage` + Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. + invoice: `Invoice` + Optional. Message is an invoice for a payment, information about the invoice. For backward compatibility, when this field is set, the document field will also be set. + successful_payment: `SuccessfulPayment` + Optional. Message is a service message about a successful payment, information about the payment. For backward compatibility, when this field is set, the invoice field will also be set. + users_shared `UsersShared` + Optional. Service message: users were shared with the bot. + chat_shared `ChatShared` + Optional. Service message: a chat was shared with the bot. + connected_website `str` + Optional. The domain name of the website on which the user has logged in. + write_access_allowed `WriteAccessAllowed` + Optional. Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess + passport_data `PassportData` + Optional. Telegram Passport data + proximity_alert_triggered `ProximityAlertTriggered` + Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location. + forum_topic_created: `ForumTopicCreated` + Optional. Service message: forum topic created. + forum_topic_edited: `ForumTopicEdited` + Optional. Service message: forum topic edited. + forum_topic_closed: `ForumTopicClosed` + Optional. Service message: forum topic closed. + forum_topic_reopened: `ForumTopicReopened` + Optional. Service message: forum topic reopened. + general_forum_topic_hidden `GeneralForumTopicHidden` + Optional. Service message: the 'General' forum topic hidden. + general_forum_topic_unhidden `GeneralForumTopicUnhidden` + Optional. Service message: the 'General' forum topic unhidden. + giveaway_created: `GiveawayCreated` + Optional. Service message: a scheduled giveaway was created. + giveaway: `Giveaway` + Optional. The message is a scheduled giveaway message. + giveaway_winners: `GiveawayWinners` + Optional. A giveaway with public winners was completed. + giveaway_completed: `GiveawayCompleted` + Optional. Service message: a giveaway without public winners was completed. + video_chat_scheduled: `VideoChatScheduled` + Optional. Service message: video chat scheduled. + video_chat_started: `VideoChatStarted` + Optional. Service message: video chat started. + video_chat_ended: `VideoChatEnded` + Optional. Service message: video chat ended. + video_chat_participants_invited: `VideoChatParticipantsInvited` + Optional. Service message: new participants invited to a video chat. + web_app_data: `WebAppData` + Optional. Service message: data sent by a Web App. reply_markup: `InlineKeyboard` Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. """ @@ -124,27 +185,39 @@ class Message: def __init__(self, data): self.message_id = data["message_id"] self.message_thread_id = data.get("message_thread_id") - self.from_user = User(data.get("from")) - self.sender_chat = Chat(data.get("sender_chat")) + self.from_ = data.get("from") + if self.from_: + self.from_ = User(self.from_) + self.sender_chat = data.get("sender_chat") + if self.sender_chat: + self.sender_chat = Chat(self.sender_chat) self.date = data["date"] self.chat = Chat(data["chat"]) - self.forward_from = User(data.get("forward_from")) - self.forward_from_chat = Chat(data.get("forward_from_chat")) - self.forward_from_message_id = data.get("forward_from_message_id") - self.forward_signature = data.get("forward_signature") - self.forward_sender_name = data.get("forward_sender_name") - self.forward_date = data.get("forward_date") + self.forward_origin = data.get("forward_origin") + if self.forward_origin: + self.forward_origin = MessageOrigin(self.forward_origin) self.is_topic_message = data.get("is_topic_message") - self.is_automatic_forward = data.get("is_automatic_forward") + self.is_automaitc_forward = data.get("is_automaitc_forward") self.reply_to_message = data.get("reply_to_message") if self.reply_to_message: self.reply_to_message = Message(self.reply_to_message) - self.via_bot = User(data.get("via_bot")) + self.external_reply = data.get("external_reply") + if self.external_reply: + self.external_reply = ExternalReplyInfo(self.external_reply) + self.quote = data.get("quote") + if self.quote: + self.quote = TextQuote(self.quote) self.edit_date = data.get("edit_date") - self.has_protected_content = data.get("has_protected_content") self.media_group_id = data.get("media_group_id") self.author_signature = data.get("author_signature") self.text = data.get("text") + self.entities = data.get("entities") + if self.entities: + self.entities = [MessageEntity(i) for i in self.entities] + self.link_preview_options = data.get("link_preview_options") + if self.link_preview_options: + self.link_preview_options = LinkPreviewOptions( + self.link_preview_options) self.animation = data.get("animation") if self.animation: self.animation = Animation(self.animation) @@ -156,11 +229,16 @@ def __init__(self, data): self.document = Document(self.document) self.photo = data.get("photo") if self.photo: - self.photo = [PhotoSize(p) for p in self.photo] + self.photo = [PhotoSize(i) for i in self.photo] self.sticker = data.get("sticker") if self.sticker: self.sticker = Sticker(self.sticker) + self.story = data.get("story") + if self.story: + self.story = Story(self.story) self.video = data.get("video") + if self.video: + self.video = Video(self.video) self.video_note = data.get("video_note") if self.video_note: self.video_note = VideoNote(self.video_note) @@ -171,8 +249,7 @@ def __init__(self, data): self.caption_entities = data.get("caption_entities") if self.caption_entities: self.caption_entities = [ - MessageEntity(e) for e in self.caption_entities - ] + MessageEntity(i) for i in self.caption_entities] self.has_media_spoiler = data.get("has_media_spoiler") self.contact = data.get("contact") if self.contact: @@ -194,21 +271,93 @@ def __init__(self, data): self.location = Location(self.location) self.new_chat_members = data.get("new_chat_members") if self.new_chat_members: - self.new_chat_members = [User(x) for x in self.new_chat_members] + self.new_chat_members = [User(i) for i in self.new_chat_members] self.left_chat_member = data.get("left_chat_member") if self.left_chat_member: self.left_chat_member = User(self.left_chat_member) self.new_chat_title = data.get("new_chat_title") self.new_chat_photo = data.get("new_chat_photo") if self.new_chat_photo: - self.new_chat_photo = [PhotoSize(p) for p in self.new_chat_photo] + self.new_chat_photo = [PhotoSize(i) for i in self.new_chat_photo] self.delete_chat_photo = data.get("delete_chat_photo") self.group_chat_created = data.get("group_chat_created") self.supergroup_chat_created = data.get("supergroup_chat_created") - self.channel_chat_created = data.get("channgel_chat_created") + self.channel_chat_created = data.get("channel_chat_created") self.message_auto_delete_timer_changed = data.get("message_auto_delete_timer_changed") if self.message_auto_delete_timer_changed: self.message_auto_delete_timer_changed = MessageAutoDeleteTimerChanged(self.message_auto_delete_timer_changed) + self.migrate_to_chat_id = data.get("migrate_to_chat_id") + self.migrate_from_chat_id = data.get("migrate_from_chat_id") + self.pinned_message = data.get("pinned_message") + if self.pinned_message: + self.pinned_message = MaybeInaccessibleMessage(self.pinned_message) + self.invoice = data.get("invoice") + if self.invoice: + self.invoice = Invoice(self.invoice) + self.successful_payment = data.get("successful_payment") + if self.successful_payment: + self.successful_payment = SuccessfulPayment(self.successful_payment) + self.users_shared = data.get("users_shared") + if self.users_shared: + self.users_shared = UsersShared(self.users_shared) + self.chat_shared = data.get("chat_shared") + if self.chat_shared: + self.chat_shared = ChatShared(self.chat_shared) + self.connected_website = data.get("connected_website") + self.write_access_allowed = data.get("write_access_allowed") + if self.write_access_allowed: + self.write_access_allowed = WriteAccessAllowed(self.write_access_allowed) + self.passport_data = data.get("passport_data") + if self.passport_data: + self.passport_data = PassportData(self.passport_data) + self.proximity_alert_triggered = data.get("proximity_alert_triggered") + if self.proximity_alert_triggered: + self.proximity_alert_triggered = ProximityAlertTriggered(self.proximity_alert_triggered) + self.forum_topic_created = data.get("forum_topic_created") + if self.forum_topic_created: + self.forum_topic_created = ForumTopicCreated(self.forum_topic_created) + self.forum_topic_edited = data.get("forum_topic_edited") + if self.forum_topic_edited: + self.forum_topic_edited = ForumTopicEdited(self.forum_topic_edited) + self.forum_topic_closed = data.get("forum_topic_closed") + if self.forum_topic_closed: + self.forum_topic_closed = ForumTopicClosed(self.forum_topic_closed) + self.forum_topic_reopened = data.get("forum_topic_reopened") + if self.forum_topic_reopened: + self.forum_topic_reopened = ForumTopicReopened(self.forum_topic_reopened) + self.general_forum_topic_hidden = data.get("general_forum_topic_hidden") + if self.general_forum_topic_hidden: + self.general_forum_topic_hidden = GeneralForumTopicHidden(self.general_forum_topic_hidden) + self.general_forum_topic_unhidden = data.get("general_forum_topic_unhidden") + if self.general_forum_topic_unhidden: + self.general_forum_topic_unhidden = GeneralForumTopicUnhidden(self.general_forum_topic_unhidden) + self.giveaway_created = data.get("giveaway_created") + if self.giveaway_created: + self.giveaway_created = GiveawayCreated(self.giveaway_created) + self.giveaway = data.get("giveaway") + if self.giveaway: + self.giveaway = Giveaway(self.giveaway) + self.giveaway_winners = data.get("giveaway_winners") + if self.giveaway_winners: + self.giveaway_winners = GiveawayWinners(self.giveaway_winners) + self.giveaway_completed = data.get("giveaway_completed") + if self.giveaway_completed: + self.giveaway_completed = GiveawayCompleted(self.giveaway_completed) + self.video_chat_scheduled = data.get("video_chat_scheduled") + if self.video_chat_scheduled: + self.video_chat_scheduled = VideoChatScheduled(self.video_chat_scheduled) + self.video_chat_started = data.get("video_chat_started") + if self.video_chat_started: + self.video_chat_started = VideoChatStarted(self.video_chat_started) + self.video_chat_ended = data.get("video_chat_ended") + if self.video_chat_ended: + self.video_chat_ended = VideoChatEnded(self.video_chat_ended) + self.video_chat_participants_invited = data.get("video_chat_participants_invited") + if self.video_chat_participants_invited: + self.video_chat_participants_invited = VideoChatParticipantsInvited(self.video_chat_participants_invited) + self.web_app_data = data.get("web_app_data") + if self.web_app_data: + self.web_app_data = WebAppData(self.web_app_data) self.reply_markup = data.get("reply_markup") if self.reply_markup: - self.reply_markup = InlineKeyboard(self.reply_markup) + self.reply_markup = InlineKeyboard(self.reply_markup) \ No newline at end of file diff --git a/EzTg/types/message/message_origin.py b/EzTg/types/message/message_origin.py new file mode 100644 index 0000000..a3bfcd9 --- /dev/null +++ b/EzTg/types/message/message_origin.py @@ -0,0 +1,100 @@ +from ..chat import Chat +from ..user import User + +class MessageOrigin: + """This object describes the origin of a message. It can be one of + + - `MessageOriginUser` + - `MessageOriginHiddenUser` + - `MessageOriginChat` + - `MessageOriginChannel`""" + + def __init__(self, data: dict): + self.type = data["type"] + if self.type == "user": + return MessageOriginUser(data) + elif self.type == "hidden_user": + return MessageOriginHiddenUser(data) + elif self.type == "chat": + return MessageOriginChat(data) + elif self.type == "channel": + return MessageOriginChannel(data) + else: + raise ValueError(f"Unknown message origin type: {self.type}") + +class MessageOriginUser: + """The message was originally sent by a known user. + + Attributes: + ----------- + type: `str` + Type of the message origin, always user + date: `int` + Date the message was sent originally in Unix time. + sender_user: `User` + User that sent the message originally.""" + + def __init__(self, data: dict): + self.type = data["type"] + self.date = data["date"] + self.sender_user = User(data["sender_user"]) + +class MessageOriginHiddenUser: + """The message was originally sent by an anonymous user. + + Attributes: + ----------- + type: `str` + Type of the message origin, always hidden_user + date: `int` + Date the message was sent originally in Unix time. + sender_user_name: `str` + Name of the user that sent the message originally.""" + + def __init__(self, data: dict): + self.type = data["type"] + self.date = data["date"] + self.sender_user_name = data["sender_user_name"] + +class MessageOriginChat: + """The message was originally sent in a chat. + + Attributes: + ----------- + type: `str` + Type of the message origin, always chat + date: `int` + Date the message was sent originally in Unix time. + sender_chat: `Chat` + Chat that sent the message originally. + author_signature: `str` + Optional. For messages originally sent by an anonymous chat administrator, original message author signature.""" + + def __init__(self, data: dict): + self.type = data["type"] + self.date = data["date"] + self.sender_chat = Chat(data["sender_chat"]) + self.author_signature = data.get("author_signature") + +class MessageOriginChannel: + """The message was originally sent in a channel. + + Attributes: + ----------- + type: `str` + Type of the message origin, always channel + date: `int` + Date the message was sent originally in Unix time. + chat: `Chat` + Channel chat to which the message was originally sent. + message_id: `int` + Unique message identifier inside the chat. + author_signature: `str` + Optional. Signature of the original post author.""" + + def __init__(self, data: dict): + self.type = data["type"] + self.date = data["date"] + self.chat = Chat(data["chat"]) + self.message_id = data["message_id"] + self.author_signature = data.get("author_signature") \ No newline at end of file diff --git a/EzTg/types/message/order_info.py b/EzTg/types/message/order_info.py new file mode 100644 index 0000000..4953d1e --- /dev/null +++ b/EzTg/types/message/order_info.py @@ -0,0 +1,24 @@ +from .shipping_address import ShippingAddress + +class OrderInfo: + """This object represents information about an order. + + Attributes + ---------- + name: `str` + Optional. User name. + phone_number: `str` + Optional. User's phone number. + email: `str` + Optional. User email. + shipping_address: `ShippingAddress` + Optional. User shipping address. + """ + + def __init__(self, data): + self.name = data.get("name") + self.phone_number = data.get("phone_number") + self.email = data.get("email") + self.shipping_address = data.get("shipping_address") + if self.shipping_address: + self.shipping_address = ShippingAddress(self.shipping_address) \ No newline at end of file diff --git a/EzTg/types/message/shipping_address.py b/EzTg/types/message/shipping_address.py new file mode 100644 index 0000000..8f78f43 --- /dev/null +++ b/EzTg/types/message/shipping_address.py @@ -0,0 +1,26 @@ +class ShippingAddress: + """This object represents a shipping address. + + Attributes + ---------- + country_code: `str` + ISO 3166-1 alpha-2 country code. + state: `str` + State, if applicable. + city: `str` + City. + street_line1: `str` + First line for the address. + street_line2: `str` + Second line for the address. + post_code: `str` + Address post code. + """ + + def __init__(self, data): + self.country_code = data["country_code"] + self.state = data["state"] + self.city = data["city"] + self.street_line1 = data["street_line1"] + self.street_line2 = data["street_line2"] + self.post_code = data["post_code"] \ No newline at end of file diff --git a/EzTg/types/message/story.py b/EzTg/types/message/story.py new file mode 100644 index 0000000..d1b6a64 --- /dev/null +++ b/EzTg/types/message/story.py @@ -0,0 +1,5 @@ +class Story: + """This object represents a message about a forwarded story in the chat. Currently holds no information.""" + + def __init__(self, data): + pass \ No newline at end of file diff --git a/EzTg/types/message/successful_payment.py b/EzTg/types/message/successful_payment.py new file mode 100644 index 0000000..e924eca --- /dev/null +++ b/EzTg/types/message/successful_payment.py @@ -0,0 +1,33 @@ +from .order_info import OrderInfo + +class SuccessfulPayment: + """This object contains basic information about a successful payment. + + Attributes + ---------- + currency: `str` + Three-letter ISO 4217 currency code. + total_amount: `int` + Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). + invoice_payload: `str` + Bot specified invoice payload. + shipping_option_id: `str` + Optional. Identifier of the shipping option chosen by the user. + order_info: `OrderInfo` + Optional. Order info provided by the user. + telegram_payment_charge_id: `str` + Telegram payment identifier. + provider_payment_charge_id: `str` + Provider payment identifier. + """ + + def __init__(self, data): + self.currency = data["currency"] + self.total_amount = data["total_amount"] + self.invoice_payload = data["invoice_payload"] + self.shipping_option_id = data.get("shipping_option_id") + self.order_info = data.get("order_info") + if self.order_info: + self.order_info = OrderInfo(self.order_info) + self.telegram_payment_charge_id = data["telegram_payment_charge_id"] + self.provider_payment_charge_id = data["provider_payment_charge_id"] \ No newline at end of file diff --git a/EzTg/types/message/text_quote.py b/EzTg/types/message/text_quote.py new file mode 100644 index 0000000..d4242e0 --- /dev/null +++ b/EzTg/types/message/text_quote.py @@ -0,0 +1,19 @@ +class TextQuote: + """This object contains information about the quoted part of a message that is replied to by the given message. + + Attributes: + ----------- + text: `str` + Text of the quoted part of a message that is replied to by the given message. + entities: `array of MessageEntity` + Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are kept in quotes. + position: `Integer` + Approximate quote position in the original message in UTF-16 code units as specified by the sender + is_manual: `bool` + Optional. True, if the quote was chosen manually by the message sender. Otherwise, the quote was added automatically by the server.""" + + def __init__(self, data: dict): + self.text = data["text"] + self.entities = data.get("entities") + self.position = data["position"] + self.is_manual = data.get("is_manual") \ No newline at end of file diff --git a/EzTg/types/message/users_shared.py b/EzTg/types/message/users_shared.py new file mode 100644 index 0000000..9128b59 --- /dev/null +++ b/EzTg/types/message/users_shared.py @@ -0,0 +1,14 @@ +class UsersShared: + """This object contains information about the users whose identifiers were shared with the bot using a KeyboardButtonRequestUsers button. + + Attributes + ---------- + request_id: `int` + Identifier of the request. + user_ids: `array of int` + Identifiers of the shared users. These numbers may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting them. But they have at most 52 significant bits, so 64-bit integers or double-precision float types are safe for storing these identifiers. The bot may not have access to the users and could be unable to use these identifiers, unless the users are already known to the bot by some other means. + """ + + def __init__(self, data): + self.request_id = data["request_id"] + self.user_ids = data["user_ids"] \ No newline at end of file diff --git a/EzTg/types/message/write_access_allowed.py b/EzTg/types/message/write_access_allowed.py new file mode 100644 index 0000000..c1770c3 --- /dev/null +++ b/EzTg/types/message/write_access_allowed.py @@ -0,0 +1,17 @@ +class WriteAccessAllowed: + """This object represents a service message about a user allowing a bot to write messages after adding it to the attachment menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess. + + Attributes: + ----------- + from_request: `bool` + Optional. True, if the access was granted after the user accepted an explicit request from a Web App sent by the method requestWriteAccess. + web_app_name: `str` + Optional. Name of the Web App, if the access was granted when the Web App was launched from a link. + from_attachment_menu: `bool` + Optional. True, if the access was granted when the bot was added to the attachment or side menu. + """ + + def __init__(self, data): + self.from_request = data.get("from_request") + self.web_app_name = data.get("web_app_name") + self.from_attachment_menu = data.get("from_attachment_menu") \ No newline at end of file