Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Update codes to v2 of Pyrogram
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantkageri committed Apr 25, 2022
1 parent 9312897 commit 4d9c7b1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ env/
venv/
ENV/
env.bak/
venv.bak/
venv.bak/

# Session Files
*.session
5 changes: 3 additions & 2 deletions tgEasy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .helpers import *
from .scaffold import Scaffold

__version__ = "1.3.2"
__version__ = "1.3.3"
__copyright__ = f"Copyright 2021 - {datetime.now().year} Jayant Hegde Kageri <github.com/jayantkageri>"
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
logging = logger.getLogger("tgEasy")
Expand Down Expand Up @@ -92,7 +92,8 @@ def run(self):
logging.info("Starting the pyrogram.Client")
try:
self.__client__.start()
self.__client__.send_message(Config.LOGS, "pyrogram.Client Started")
self.__client__.send_message(
Config.LOGS, "pyrogram.Client Started")
except pyrogram.errors.exceptions.bad_request_400.PeerIdInvalid:
logging.warning("Interact the Bot to your Log Chat Now")
pass
Expand Down
11 changes: 6 additions & 5 deletions tgEasy/decorater/adminsOnly.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def anonymous_admin(m: pyrogram.types.Message):
[
pyrogram.types.InlineKeyboardButton(
text="Verify!",
callback_data=f"anon.{m.message_id}",
callback_data=f"anon.{m.id}",
),
]
]
Expand All @@ -64,10 +64,11 @@ async def anonymous_admin_verification(
pass
return
cb = ANON.pop(
int(f"{CallbackQuery.message.chat.id}{CallbackQuery.data.split('.')[1]}")
int(
f"{CallbackQuery.message.chat.id}{CallbackQuery.data.split('.')[1]}")
)
member = await CallbackQuery.message.chat.get_member(CallbackQuery.from_user.id)
if bool(member.status not in ("creator", "administrator")):
if bool(member.status not in (pyrogram.enums.ChatMemberStatus.OWNER, pyrogram.enums.ChatMemberStatus.ADMINISTRATOR)):
return await CallbackQuery.answer("You need to be an admin to do this.")
permission = cb[2]

Expand Down Expand Up @@ -137,12 +138,12 @@ async def start(client, message):
def wrapper(func):
async def decorator(client, message):
permissions = ""
if not message.chat.type == "supergroup":
if not message.chat.type == pyrogram.enums.ChatType.SUPERGROUP:
return await message.reply_text(
"This command can be used in supergroups only.",
)
if message.sender_chat and not TRUST_ANON_ADMINS:
ANON[int(f"{message.chat.id}{message.message_id}")] = (
ANON[int(f"{message.chat.id}{message.id}")] = (
message,
func,
permission,
Expand Down
5 changes: 3 additions & 2 deletions tgEasy/decorater/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def callback(
self,
data: typing.Union[str, list],
self_admin: typing.Union[bool, bool] = False,
filter: typing.Union[pyrogram.filters.Filter, pyrogram.filters.Filter] = None,
filter: typing.Union[pyrogram.filters.Filter,
pyrogram.filters.Filter] = None,
*args,
**kwargs,
):
Expand Down Expand Up @@ -82,7 +83,7 @@ async def decorator(client, CallbackQuery: pyrogram.types.CallbackQuery):
me = await client.get_chat_member(
CallbackQuery.message.chat.id, (await client.get_me()).id
)
if not me.status in ("creator", "administrator"):
if not me.status in (pyrogram.enums.ChatMemberStatus.OWNER, pyrogram.enums.ChatMemberStatus.ADMINISTRATOR):
return await CallbackQuery.message.edit_text(
"I must be admin to execute this Command"
)
Expand Down
16 changes: 9 additions & 7 deletions tgEasy/decorater/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def command(
self_admin: typing.Union[bool, bool] = False,
self_only: typing.Union[bool, bool] = False,
handler: typing.Optional[list] = Config.HANDLERS,
filter: typing.Union[pyrogram.filters.Filter, pyrogram.filters.Filter] = None,
filter: typing.Union[pyrogram.filters.Filter,
pyrogram.filters.Filter] = None,
*args,
**kwargs
):
Expand All @@ -62,7 +63,7 @@ def command(
- If True, the command will only executeed if the Bot is Admin in the Chat, By Default False
- filter (`~pyrogram.filters`) **optional**:
- Pyrogram Filters, hope you know about this, for Advaced usage. By Default `~pyrogram.filters.edited` and this can't be changed. Use `and` for seaperating filters.
- Pyrogram Filters, hope you know about this, for Advaced usage. Use `and` for seaperating filters.
#### Example
.. code-block:: python
Expand Down Expand Up @@ -99,24 +100,24 @@ async def start(client, message):

def wrapper(func):
async def decorator(client, message: pyrogram.types.Message):
if self_admin and message.chat.type != "supergroup":
if self_admin and message.chat.type != pyrogram.enums.ChatType.SUPERGROUP:
return await message.reply_text(
"This command can be used in supergroups only."
)
if self_admin:
me = await client.get_chat_member(
message.chat.id, (await client.get_me()).id
)
if not me.status in ("creator", "administrator"):
if not me.status in (pyrogram.enums.ChatMemberStatus.OWNER, pyrogram.enums.ChatMemberStatus.ADMINISTRATOR):
return await message.reply_text(
"I must be admin to execute this Command"
)
pass
if group_only and message.chat.type != "supergroup":
if group_only and message.chat.type != pyrogram.enums.ChatType.SUPERGROUP:
return await message.reply_text(
"This command can be used in supergroups only."
)
if pm_only and message.chat.type != "private":
if pm_only and message.chat.type != pyrogram.enums.ChatType.PRIVATE:
return await message.reply_text(
"This command can be used in PMs only."
)
Expand All @@ -128,7 +129,8 @@ async def decorator(client, message: pyrogram.types.Message):
return await handle_error(exception, message)

self.__client__.add_handler(
pyrogram.handlers.MessageHandler(callback=decorator, filters=filter)
pyrogram.handlers.MessageHandler(
callback=decorator, filters=filter)
)
return decorator

Expand Down
40 changes: 29 additions & 11 deletions tgEasy/helpers/admin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with tgEasy. If not, see <http://www.gnu.org/licenses/>.

import typing
import pyrogram


async def check_rights(
Expand Down Expand Up @@ -67,24 +68,41 @@ async def ban(client, message):
return False
if user.status == "user":
return False
if user.status in ("administrator", "creator"):
if user.status in (pyrogram.enums.ChatMemberStatus.OWNER, pyrogram.enums.ChatMemberStatus.ADMINISTRATOR):
permission = []
if user.can_delete_messages:
if user.privileges.can_manage_chat:
permission.append("can_manage_chat")

if user.privileges.can_delete_messages:
permission.append("can_delete_messages")
if user.can_restrict_members:

if user.privileges.can_manage_video_chats:
permission.append("can_manage_video_chats")

if user.privileges.can_restrict_members:
permission.append("can_restrict_members")
if user.can_promote_members:

if user.privileges.can_promote_members:
permission.append("can_promote_members")
if user.can_change_info:

if user.privileges.can_change_info:
permission.append("can_change_info")
if user.can_invite_users:

if user.privileges.can_post_messages:
permission.append("can_post_messages")

if user.privileges.can_edit_messages:
permission.append("can_edit_messages")

if user.privileges.can_invite_users:
permission.append("can_invite_users")
if user.can_pin_messages:

if user.privileges.can_pin_messages:
permission.append("can_pin_messages")
if user.can_manage_voice_chats:
permission.append("can_manage_voice_chats")
if user.is_anonymous:

if user.privileges.is_anonymous:
permission.append("is_anonymous")

if isinstance(rights, str):
if rights in permission:
return True
Expand Down Expand Up @@ -136,6 +154,6 @@ async def ban(client, message):
user = await client.get_chat_member(chat_id, user_id)
except:
return False
if user.status in ("administrator", "creator"):
if user.status in (pyrogram.enums.ChatMemberStatus.OWNER, pyrogram.enums.ChatMemberStatus.ADMINISTRATOR):
return True
return False

0 comments on commit 4d9c7b1

Please sign in to comment.