Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.2 #15

Open
wants to merge 143 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
c7f1528
add User class
HexyeDEV Jan 18, 2023
b775dc1
Restyled by autopep8
restyled-commits Jan 18, 2023
1cdf86a
Restyled by black
restyled-commits Jan 18, 2023
fa97fd9
Restyled by isort
restyled-commits Jan 18, 2023
c2e574c
Restyled by yapf
restyled-commits Jan 18, 2023
1ea736f
Merge pull request #16 from HexyeDEV/restyled/v0.3.2
HexyeDEV Jan 18, 2023
4c42eaf
add ReplyMarkupKeyboard
HexyeDEV Feb 4, 2023
c5b8999
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Feb 4, 2023
efdc88a
update getMe according to user class
HexyeDEV Feb 17, 2023
14f868d
Restyled by autopep8
restyled-commits Feb 17, 2023
0277867
Restyled by black
restyled-commits Feb 17, 2023
4221b6f
Restyled by yapf
restyled-commits Feb 17, 2023
35f377d
Merge pull request #17 from HexyeDEV/restyled/v0.3.2
HexyeDEV Feb 18, 2023
b269981
Create LICENSE
HexyeDEV Mar 1, 2023
6e4d5e6
Restyled by autopep8
restyled-commits Mar 1, 2023
3c441d4
Restyled by black
restyled-commits Mar 1, 2023
13648bb
Restyled by yapf
restyled-commits Mar 1, 2023
0d665b4
Merge pull request #18 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 1, 2023
7b40f05
fix ReplyKeyboardMarkup
HexyeDEV Mar 5, 2023
c5d21f6
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 5, 2023
74d0773
fix ReplyKeyboardMarkup (again)
HexyeDEV Mar 5, 2023
4cd1a27
Add Chat class and related methods
HexyeDEV Mar 5, 2023
761b008
.
HexyeDEV Mar 5, 2023
a9ebd20
Restyled by autopep8
restyled-commits Mar 5, 2023
0232303
Restyled by black
restyled-commits Mar 5, 2023
c5c4499
Restyled by isort
restyled-commits Mar 5, 2023
8a1d583
Restyled by yapf
restyled-commits Mar 5, 2023
06a5e4e
Merge pull request #19 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 5, 2023
931da9a
Add ChatPhoto class #20 and User class refactor
HexyeDEV Mar 5, 2023
0d51885
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 5, 2023
a384d6b
Restyled by autopep8
restyled-commits Mar 5, 2023
5ba44dd
Restyled by black
restyled-commits Mar 5, 2023
5fede70
Restyled by yapf
restyled-commits Mar 5, 2023
c64b30d
Merge pull request #21 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 5, 2023
c762b08
add Message class #20
HexyeDEV Mar 5, 2023
e134d61
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 5, 2023
541ee64
Restyled by autopep8
restyled-commits Mar 5, 2023
13de86f
Restyled by black
restyled-commits Mar 5, 2023
def94db
Restyled by isort
restyled-commits Mar 5, 2023
8034932
Restyled by yapf
restyled-commits Mar 5, 2023
aabb4a2
Merge pull request #22 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 5, 2023
12cb333
add ChatPermissions class
HexyeDEV Mar 5, 2023
24091c5
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 5, 2023
ddea2af
Restyled by autopep8
restyled-commits Mar 5, 2023
beb4c47
Restyled by black
restyled-commits Mar 5, 2023
009d9eb
Restyled by isort
restyled-commits Mar 5, 2023
7f93148
Restyled by yapf
restyled-commits Mar 5, 2023
d4c95a1
Merge pull request #23 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 5, 2023
05b3a5e
add ChatLocation and Location class #20
HexyeDEV Mar 5, 2023
ac0f627
implement ChatLocation in Chat class #20
HexyeDEV Mar 5, 2023
5dd6dae
changes for #20
HexyeDEV Mar 5, 2023
abb0135
Merge
HexyeDEV Mar 5, 2023
9197ab8
Restyled by autopep8
restyled-commits Mar 5, 2023
1a5453b
Restyled by black
restyled-commits Mar 5, 2023
7e7140a
Restyled by isort
restyled-commits Mar 5, 2023
21bb668
Restyled by yapf
restyled-commits Mar 5, 2023
31df411
Merge pull request #24 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 5, 2023
c770bd6
Message class update for Location #25 + small fix
HexyeDEV Mar 5, 2023
c47f003
Restyled by autopep8
restyled-commits Mar 5, 2023
8b81df9
Restyled by black
restyled-commits Mar 5, 2023
5b7abde
Restyled by isort
restyled-commits Mar 5, 2023
d5add39
Restyled by yapf
restyled-commits Mar 5, 2023
7f99dd7
Merge pull request #26 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 5, 2023
6cdf58e
add Animation class #25
HexyeDEV Mar 6, 2023
9ffb263
add PhotoSize for Animation class #25
HexyeDEV Mar 6, 2023
a5c6169
Restyled by autopep8
restyled-commits Mar 6, 2023
4bf9be5
Restyled by black
restyled-commits Mar 6, 2023
dc69650
Restyled by yapf
restyled-commits Mar 6, 2023
14fd365
Merge pull request #27 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 6, 2023
6df2ba3
fix photosize import
HexyeDEV Mar 6, 2023
e7e74db
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 6, 2023
cdf1051
add Audio class #25
HexyeDEV Mar 6, 2023
a457f16
Restyled by autopep8
restyled-commits Mar 6, 2023
153f14a
Restyled by black
restyled-commits Mar 6, 2023
06c80fa
Restyled by yapf
restyled-commits Mar 6, 2023
b77b1f8
Merge pull request #28 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 6, 2023
c32eded
add Document class #25
HexyeDEV Mar 6, 2023
91c0152
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 6, 2023
e03c366
Restyled by autopep8
restyled-commits Mar 6, 2023
dac4802
Restyled by black
restyled-commits Mar 6, 2023
a1ea4f0
Restyled by yapf
restyled-commits Mar 6, 2023
4884819
Merge pull request #29 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 6, 2023
99632c6
little message class fix #25
HexyeDEV Mar 6, 2023
560935b
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 6, 2023
31c9e83
add jetbrains contribuition
HexyeDEV Mar 7, 2023
587b1c5
Restyled by autopep8
restyled-commits Mar 7, 2023
bbe25d0
Restyled by black
restyled-commits Mar 7, 2023
a6f0fb3
Restyled by whitespace
restyled-commits Mar 7, 2023
3ba8f5f
Restyled by yapf
restyled-commits Mar 7, 2023
6c1f675
Merge pull request #30 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 7, 2023
6ef71cd
Update README.rst
HexyeDEV Mar 7, 2023
877ce98
solve ciruclar import + add Video class #25
HexyeDEV Mar 7, 2023
cfcb2da
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 7, 2023
39d3604
Restyled by autopep8
restyled-commits Mar 7, 2023
24f6325
Restyled by black
restyled-commits Mar 7, 2023
6a24a40
Restyled by yapf
restyled-commits Mar 7, 2023
d4a44e5
Merge pull request #31 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 7, 2023
52afdad
fix docs and add replymarkupkeyboard to setup
HexyeDEV Mar 7, 2023
a7c3214
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 7, 2023
4f91912
edit docs config
HexyeDEV Mar 7, 2023
e9265b8
testing shi
HexyeDEV Mar 24, 2023
e17b39e
trying other shi
HexyeDEV Mar 24, 2023
9dcc160
trying shi again
HexyeDEV Mar 24, 2023
def6151
add VideoNote class #25
HexyeDEV Mar 24, 2023
442bba3
Restyled by autopep8
restyled-commits Mar 24, 2023
b81e5d6
Restyled by black
restyled-commits Mar 24, 2023
f6806bd
Restyled by yapf
restyled-commits Mar 24, 2023
abee3bf
Merge pull request #32 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 24, 2023
a975f68
Update README.rst
HexyeDEV Mar 24, 2023
e89973a
Update SECURITY.md
HexyeDEV Mar 24, 2023
d7aeb84
Update README.rst
HexyeDEV Mar 24, 2023
fc4437d
Restyled by autopep8
restyled-commits Mar 24, 2023
7ff5be0
Restyled by black
restyled-commits Mar 24, 2023
13a19f7
Restyled by prettier-markdown
restyled-commits Mar 24, 2023
023f6dd
Restyled by yapf
restyled-commits Mar 24, 2023
ed60f48
Merge pull request #33 from HexyeDEV/restyled/v0.3.2
HexyeDEV Mar 24, 2023
8b47904
restyle (hope docs work)
HexyeDEV Mar 26, 2023
4c371d1
Merge branch 'v0.3.2' of https://github.com/HexyeDEV/EzTg into v0.3.2
HexyeDEV Mar 26, 2023
33dc957
maybe fix docs
HexyeDEV Mar 26, 2023
3223915
add missing docstrings
HexyeDEV Mar 27, 2023
f005e7b
add Voice class #25
HexyeDEV May 26, 2023
d619e46
add MessageEntity class #25
HexyeDEV May 26, 2023
b32db35
Restyled by autopep8
restyled-commits May 26, 2023
5f40a2c
Restyled by black
restyled-commits May 26, 2023
acad7f7
Restyled by isort
restyled-commits May 26, 2023
1072c79
Restyled by yapf
restyled-commits May 26, 2023
c1e7c2e
Merge pull request #34 from HexyeDEV/restyled/v0.3.2
HexyeDEV May 26, 2023
95959e0
add contact class
HexyeDEV Jun 29, 2023
ee3883e
add Dice class #25
HexyeDEV Jun 29, 2023
997a770
add Game class #25
HexyeDEV Jun 29, 2023
107a625
fix exceptions not handles
HexyeDEV Jun 29, 2023
71a02fa
add Poll Full message class implementation #25
HexyeDEV Jun 29, 2023
5080a0b
add Venue class #25
HexyeDEV Jun 29, 2023
02f9a42
add Sticker class #25
HexyeDEV Jun 29, 2023
68b850f
added inlinekeyboard to be added to message
HexyeDEV Jun 29, 2023
a80b659
update message init
HexyeDEV Jun 29, 2023
6040d05
Restyled by autopep8
restyled-commits Jun 29, 2023
d0b0d16
Restyled by black
restyled-commits Jun 29, 2023
4a8300c
Restyled by isort
restyled-commits Jun 29, 2023
6c58429
Restyled by yapf
restyled-commits Jun 29, 2023
f4b1e29
Merge pull request #35 from HexyeDEV/restyled/v0.3.2
HexyeDEV Jun 29, 2023
8bc730c
Add MessageAutoDeleteTimerChanged #25
HexyeDEV Aug 20, 2023
f24b216
added many classes #25
HexyeDEV Jan 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 117 additions & 37 deletions EzTg/main.py → EzTg/EzTg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import asyncio

import aiohttp
import requests

from .types.chat.chat import Chat
from .types.user.user import User


class Parse(dict):
Expand All @@ -21,14 +25,18 @@ class TokenError(Exception):


class TelegramClient:
"""A class that represents a telegram client."""

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{}/{}"
"""Initialize the client.

Parameters
----------
token: `str`
The token of your bot."""

self.token = token
self.api = "https://api.telegram.org/bot{}/{}"

async def send(self, method, **kwargs):
"""Send a request to the telegram api.
Expand All @@ -54,6 +62,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)
Expand All @@ -62,13 +72,22 @@ 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

async def sendMessage(
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,
chat_id,
text,
Expand All @@ -95,7 +114,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",
Expand All @@ -118,7 +138,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
Expand All @@ -131,7 +151,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,
Expand Down Expand Up @@ -161,7 +181,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",
Expand All @@ -186,11 +207,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 forward_message(self,
chat_id,
from_chat_id,
message_id,
disable_notification=False):
"""Foward a message.

Parameters
Expand All @@ -202,7 +223,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,
Expand All @@ -211,11 +233,25 @@ async def forwardMessage(self,
disable_notification=disable_notification,
)

async def getMe(self):
async def get_me(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(
async def copy_message(
self,
chat_id,
message_id,
Expand All @@ -242,7 +278,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",
Expand All @@ -265,7 +302,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
Expand All @@ -274,7 +311,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,
Expand Down Expand Up @@ -305,7 +342,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
Expand All @@ -316,10 +353,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 pin_chat_message(self,
chat_id,
message_id,
disable_notification=False):
"""Pin a message.

Parameters
Expand All @@ -329,15 +366,16 @@ 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,
message_id=message_id,
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
Expand All @@ -350,7 +388,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
Expand All @@ -376,3 +414,45 @@ async def get_chat_id(self, message):
message: `dict`
The message object.s"""
return message["chat"]["id"]

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)
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)
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)
17 changes: 15 additions & 2 deletions EzTg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
__title__ = "EzTg"
__author__ = "Hexye"

from .inlinekeyboard import InlineKeyboard
from .main import TelegramClient
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.inlinekeyboard import InlineKeyboard
from .types.location import Location
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
3 changes: 3 additions & 0 deletions EzTg/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .inlinekeyboard import InlineKeyboard
from .location import Location
from .replykeyboardmarkup import ReplyKeyboardMarkup
4 changes: 4 additions & 0 deletions EzTg/types/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .chat import Chat
from .location import ChatLocation
from .permissions import ChatPermissions
from .photo import ChatPhoto
Loading