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

Commit

Permalink
Release tgEasy v1.3.0
Browse files Browse the repository at this point in the history
For changelog: For changelog: https://github.com/jayantkageri/tgEasy/releases/tag/v1.3.0

Co-Authored-By: ÁÑÑÍHÌLÅTØR SPÄRK <[email protected]>
  • Loading branch information
jayantkageri and annihilatorrrr committed Jan 5, 2022
1 parent 5296a54 commit fca3c0e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 32 deletions.
21 changes: 2 additions & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# tgEasy - Easy for a brighter Shine. A monkey pather add-on for Pyrogram
# Copyright (C) 2021 Jayant Hegde Kageri <https://github.com/jayantkageri>

# This file is part of tgEasy.

# tgEasy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# tgEasy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with tgEasy. If not, see <http://www.gnu.org/licenses/>.

pyrogram
TgCrypto
pyromod
prettyconf
prettyconf
cachetools
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
with open("README.md", encoding="utf-8") as f:
readme = f.read()

with open("requirements.txt", encoding="utf-8") as f:
requirements = f.read().splitlines()

setup(
name="tgEasy",
version=version,
Expand Down Expand Up @@ -71,5 +74,5 @@
python_requires="~=3.6",
packages=find_packages(),
zip_safe=False,
install_requires=["pyrogram", "tgcrypto", "pyromod", "prettyconf"],
install_requires=requirements,
)
2 changes: 1 addition & 1 deletion tgEasy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .helpers import *
from .scaffold import Scaffold

__version__ = "1.2.7"
__version__ = "1.3.0"
__copyright__ = "Copyright 2021 Jayant Hegde Kageri <github.com/jayantkageri>"
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
logging = logger.getLogger("tgEasy")
Expand Down
123 changes: 112 additions & 11 deletions tgEasy/decorater/adminsOnly.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,100 @@
import typing

import pyrogram
from cachetools import TTLCache
from pyrogram.types.messages_and_media import message

from tgEasy.scaffold import Scaffold

from ..helpers import check_rights, handle_error, is_admin

ANON = TTLCache(maxsize=250, ttl=30)


async def anonymous_admin(m: pyrogram.types.Message):
"""
Helper function for Anonymous Admin Verification
"""
keyboard = pyrogram.types.InlineKeyboardMarkup(
[
[
pyrogram.types.InlineKeyboardButton(
text="Verify!",
callback_data=f"anon.{m.message_id}",
),
]
]
)
return await m.reply_text(
"Click here to prove you are admin with the required rights to perform this action!",
reply_markup=keyboard,
)


class AdminsOnly(Scaffold):
async def anonymous_admin_verification(
client, CallbackQuery: pyrogram.types.CallbackQuery
):
if int(
f"{CallbackQuery.message.chat.id}{CallbackQuery.data.split('.')[1]}"
) not in set(ANON.keys()):
try:
await CallbackQuery.message.edit_text("Button has been Expired.")
except pyrogram.types.RPCError:
try:
await CallbackQuery.message.delete()
except pyrogram.types.RPCError:
pass
return
cb = ANON.pop(
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")):
return await CallbackQuery.answer("You need to be an admin to do this.")
permission = cb[2]

if isinstance(permission, str):
if not await check_rights(
CallbackQuery.message.chat.id,
CallbackQuery.from_user.id,
permission,
client=client,
):
return await CallbackQuery.message.edit_text(
f"You are Missing the following Rights to use this Command:\n{permission}",
)
if isinstance(permission, list):
permissions = ""
for perm in permission:
if not await check_rights(
CallbackQuery.message.chat.id,
CallbackQuery.from_user.id,
perm,
client=client,
):
permissions += f"\n{perm}"
if not permissions == "":
return await CallbackQuery.message.edit_text(
f"You are Missing the following Rights to use this Command:{permissions}",
)
try:
await CallbackQuery.message.delete()
await cb[1](client, cb[0])
except pyrogram.errors.exceptions.forbidden_403.ChatAdminRequired:
return await CallbackQuery.message.edit_text(
"I must be admin to execute this Command",
)
except BaseException as e:
return await handle_error(e, CallbackQuery)

def adminsOnly(
self,
permission: typing.Union[str, list],
TRUST_ANON_ADMINS: typing.Union[bool, bool] = False,
):
"""
### `tgEasy.tgClient.adminsOnly`
# `tgEasy.tgClient.adminsOnly`
- A decorater for running the function only if the admin have the specified Rights.
- We are still Working on this to make it to check Rights for Anonoymous Admins, Stay Tuned.
- Parameters:
Expand All @@ -41,7 +122,7 @@ def adminsOnly(
- TRUST_ANON_ADMIN (bool) **optional**:
- If User is Anonymous Admin also, It Runs the Function, By Default False
### Example
# Example
.. code-block:: python
from tgEasy import tgClient
import pyrogram
Expand All @@ -59,34 +140,48 @@ async def decorator(client, message):
permissions = ""
if not message.chat.type == "supergroup":
return await message.reply_text(
"This command can be used in supergroups only."
"This command can be used in supergroups only.",
)
if message.sender_chat and not TRUST_ANON_ADMINS:
return await message.reply_text(
"The Right Check for Anonymous Admins is in Development. So you cannot perform this Action for Now, If you don't want this and want to Allow Anonymous Admins for performing Actions in this time Please Contact Bot Owner."
# return await message.reply_text(
# "The Right Check for Anonymous Admins is in Development. So you cannot perform this Action for Now, If you don't want this and want to Allow Anonymous Admins for performing Actions in this time Please Contact Bot Owner.",
# )
ANON[int(f"{message.chat.id}{message.message_id}")] = (
message,
func,
permission,
)
return await anonymous_admin(message)
if not await is_admin(
message.chat.id, message.from_user.id, client=client
message.chat.id,
message.from_user.id,
client=client,
):
return await message.reply_text(
"Only admins can execute this Command!"
"Only admins can execute this Command!",
)
if isinstance(permission, str):
if not await check_rights(
message.chat.id, message.from_user.id, permission, client=client
message.chat.id,
message.from_user.id,
permission,
client=client,
):
return await message.reply_text(
f"You are Missing the following Rights to use this Command:\n{permission}"
f"You are Missing the following Rights to use this Command:\n{permission}",
)
if isinstance(permission, list):
for perm in permission:
if not await check_rights(
message.chat.id, message.from_user.id, perm, client=client
message.chat.id,
message.from_user.id,
perm,
client=client,
):
permissions += f"\n{perm}"
if not permissions == "":
return await message.reply_text(
f"You are Missing the following Rights to use this Command:{permissions}"
f"You are Missing the following Rights to use this Command:{permissions}",
)
try:
await func(client, message)
Expand All @@ -95,6 +190,12 @@ async def decorator(client, message):
except BaseException as exception:
await handle_error(exception, message)

self.__client__.add_handler(
pyrogram.handlers.CallbackQueryHandler(
AdminsOnly.anonymous_admin_verification,
pyrogram.filters.regex("^anon."),
),
)
return decorator

return wrapper
1 change: 1 addition & 0 deletions tgEasy/decorater/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import typing

import pyrogram

from tgEasy.scaffold import Scaffold

from ..helpers import handle_error
Expand Down
1 change: 1 addition & 0 deletions tgEasy/decorater/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import typing

import pyrogram

from tgEasy.scaffold import Scaffold

from ..config import Config
Expand Down

0 comments on commit fca3c0e

Please sign in to comment.