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

Commit

Permalink
Release Bug Fix Update: v1.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantkageri committed Nov 19, 2021
1 parent 18a9a74 commit 7dafbb1
Show file tree
Hide file tree
Showing 14 changed files with 674 additions and 559 deletions.
5 changes: 2 additions & 3 deletions tgEasy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import asyncio
import logging as logger
import os
import typing

import pyrogram
from pyrogram import client
Expand All @@ -31,8 +29,9 @@
from .config import Config
from .decorater import *
from .helpers import *
from .scaffold import Scaffold

__version__ = "1.2.6"
__version__ = "1.2.7"
__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
4 changes: 2 additions & 2 deletions tgEasy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from prettyconf import Configuration
from prettyconf.loaders import EnvFile, Environment

env_file = f"{os.getcwd()}/.env"
config = Configuration(loaders=[Environment(), EnvFile(filename=env_file)])
config = Configuration(
loaders=[Environment(), EnvFile(filename=f"{os.getcwd()}/.env")])


class Config:
Expand Down
215 changes: 0 additions & 215 deletions tgEasy/decorater.py

This file was deleted.

3 changes: 3 additions & 0 deletions tgEasy/decorater/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .adminsOnly import AdminsOnly
from .callback import Callback
from .command import Command
79 changes: 79 additions & 0 deletions tgEasy/decorater/adminsOnly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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/>.

import typing

import pyrogram
from tgEasy.scaffold import Scaffold

from ..helpers import check_rights, handle_error, is_admin


class AdminsOnly(Scaffold):
def adminsOnly(self, permission: typing.Union[str, list], TRUST_ANON_ADMINS: typing.Union[bool, bool] = False):
"""
### `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:
- permission (str):
- Permission which the User must have to use the Functions
- TRUST_ANON_ADMIN (bool) **optional**:
- If User is Anonymous Admin also, It Runs the Function, By Default False
### Example
.. code-block:: python
from tgEasy import tgClient
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("start")
@app.adminsOnly("can_change_info")
async def start(client, message):
await message.reply_text(f"Hello Admin {message.from_user.mention}")
"""
def wrapper(func):
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.")
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."
)
if not await is_admin(message.chat.id, message.from_user.id, client=client):
return await message.reply_text("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):
return await message.reply_text(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):
permissions += f"\n{perm}"
if not permissions == "":
return await message.reply_text(f"You are Missing the following Rights to use this Command:{permissions}")
try:
await func(client, message)
except pyrogram.errors.exceptions.forbidden_403.ChatWriteForbidden:
await client.leave_chat(message.chat.id)
except BaseException as exception:
await handle_error(exception, message)
return decorator
return wrapper
Loading

0 comments on commit 7dafbb1

Please sign in to comment.