Skip to content

Commit

Permalink
Restyled by black
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Mar 5, 2023
1 parent a9ebd20 commit 0232303
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 50 deletions.
12 changes: 7 additions & 5 deletions EzTg/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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")
Expand All @@ -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")
Expand Down
52 changes: 26 additions & 26 deletions EzTg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
41 changes: 22 additions & 19 deletions EzTg/replykeyboardmarkup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ReplyKeyboardMarkup:

def __init__(
self,
is_persistent=False,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 0232303

Please sign in to comment.