Skip to content

Commit

Permalink
Restyled by yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Feb 17, 2023
1 parent 0277867 commit 4221b6f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
49 changes: 25 additions & 24 deletions EzTg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

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

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

def __init__(
self,
is_persistent=False,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
version="0.3.2",
author="Hexye",
author_email="[email protected]",
description="An api wrapper for telegram easy to use. Coerent according to telegram core.",
description=
"An api wrapper for telegram easy to use. Coerent according to telegram core.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/HexyeDEV/EzTg/",
Expand Down

0 comments on commit 4221b6f

Please sign in to comment.