-
-
Notifications
You must be signed in to change notification settings - Fork 8
Documentation
tgEasy.tgClient
tgEasy.tgClient.command
tgEasy.tgClient.callback
tgEasy.tgClient.adminsOnly
tgEasy.tgClient.run
tgEasy.tgClient.runClients
tgEasy.get_user
tgEasy.get_user_adv
tgEasy.check_rights
tgEasy.is_admin
tgEasy.handle_error
tgEasy.send_typing
tgEasy.tgClient.__client__
- A Class for Initialising the tgEasy and it's Methods, Types and Functions
- Parameters:
- client (
pyrogram.Client
):- The Pyrogram Client
- client (
from tgEasy import tgClient
from pyrogram import Client
app = tgClient(Client("my_account"))
- A decorater to Register Commands in simple way and manage errors in that Function itself, alternative for
@pyrogram.Client.on_message(pyrogram.filters.command('command'))
- Parameters:
-
command (str || list):
- The command to be handled for a function
-
group_only (bool) optional:
- If True, the command will only be executed in Groups, By Default False.
-
pm_only (bool) optional:
- If True, the command will only be executed in Private Messages, By Default False.
-
self_admin (bool) optional:
- If True, the command will only be executed if the Bot is Admin in the Chat, By Default False
-
self_only (bool) optional:
- If True, the command will only be executed if the Bot is Admin in the Chat, By Default False
-
handler (list) optional:
- If set, the command will be handled by the specified Handler, By Default
Config.HANDLERS
.
- If set, the command will be handled by the specified Handler, By Default
-
filter (
~pyrogram.filters
) optional:- Pyrogram Filters, hope you know about this, for Advanced usage. By Default
~pyrogram.filters.edited
and this can't be changed. Useand
for separating filters.
- Pyrogram Filters, hope you know about this, for Advanced usage. By Default
-
import pyrogram
from tgEasy import tgClient
app = tgClient(pyrogram.Client())
@app.command("start", group_only=False, pm_only=False, self_admin=False, self_only=False, pyrogram.filters.chat("777000") and pyrogram.filters.text)
async def start(client, message):
await message.reply_text(f"Hello {message.from_user.mention}")
- A decorater to Register Callback Quiries in simple way and manage errors in that Function itself, alternative for
@pyrogram.Client.on_callback_query(pyrogram.filters.regex('^data.*'))
- Parameters:
-
data (str || list):
- The callback query to be handled for a function
-
self_admin (bool) optional:
- If True, the command will only be executed if the Bot is Admin in the Chat, By Default False
-
filter (
~pyrogram.filters
) optional:- Pyrogram Filters, hope you know about this, for Advanced usage. Use
and
for separating filters.
- Pyrogram Filters, hope you know about this, for Advanced usage. Use
-
import pyrogram
from tgEasy import tgClient
app = tgClient(pyrogram.Client())
@app.command("start")
async def start(client, message):
await message.reply_text(
f"Hello {message.from_user.mention}",
reply_markup=pyrogram.types.InlineKeyboardMarkup([[
pyrogram.types.InlineKeyboardButton(
"Click Here",
"data"
)
]])
)
@app.callback("data")
async def data(client, CallbackQuery):
await CallbackQuery.answer("Hello :)", show_alert=True)
- A decorator for running the function only if the admin has the specified Rights.
- If the admin is Anonymous Admin, it also checks his rights by making a Callback.
- Parameters:
- permission (str):
- Permission which the User must have to use the Functions
- permission (str):
-
- TRUST_ANON_ADMIN (bool) optional:
- If the user is an Anonymous Admin, then it bypasses his right check.
- TRUST_ANON_ADMIN (bool) optional:
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}")
-
Runs the
pyrogram.Client
by addingtgEasy.tgClient.run()
in your main file and run. -
This calls
pyrogram.Client.start()
,pyrogram.idle()
andpyrogram.Client.stop()
import pyrogram
from tgEasy import tgClient
app = tgClient(pyrogram.Client())
app.run()
-
Runs the Multiple
pyrogram.Client
of tgEasy by addingtgEasy.tgClient.run()
in your main file and run. -
This calls
pyrogram.Client.start()
,pyrogram.idle()
andpyrogram.Client.stop()
-
Pass the tgEasy Clients in it.
from tgEasy import tgClient
import pyrogram
app = tgClient(pyrogram.Client())
app1 = tgClient(pyrogram.Client())
tgClient.runClients(app, app1)
- Gets a User from Message/RepliedMessageFromUser
- Parameters:
- m (
~pyrogram.types.Message
||~pyrogram.types.CallbackQuery
)
- m (
- Returns:
-
pyrogram.types.User
on Success -
False
on Error
-
from tgEasy import get_user, tgClient
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("ban", group_only=True, self_admin=True)
@app.adminsOnly("can_restrict_members")
async def ban(client, message):
user = await get_user(message)
await message.chat.kick_member(user.id)
- A Function to Get the User from the Message/CallbackQuery, If there is None arguments, returns the From User.
- Parameters:
- m (
pyrogram.types.Message
||pyrogram.types.CallbackQuery
):- Message or Callbackquery.
- m (
- Returns:
-
pyrogram.types.User
on Success -
False
on Error
-
from tgEasy import get_user_adv
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("id")
async def id(client, message):
user = await get_user_adv(message)
await message.reply_text(f"Your ID is `{user.id}`")
-
Checks the Rights of a User
-
This is a Helper Function for
adminsOnly
-
Parameters:
-
chat_id (int):
- The Chat ID of Which Chat has to check the Rights.
-
user_id (int):
- The User ID of Whose Rights have to Check.
-
rights (str):
- The Rights have to be Checked.
-
client (
pyrogram.Client
):- From which Client to Check the Rights.
-
-
Returns:
-
True
if the User has the Right. -
False
if the User doesn't have the Right.
-
from tgEasy import tgClient, check_rights, get_user
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("ban", group_only=True, self_admin=True)
async def ban(client, message):
if not await check_rights(message.chat.id, message.from_user.id, "can_restrict_members"):
return await message.reply_text("You don't have necessary rights to use this Command.")
user = await get_user(message)
await message.chat.kick_member(user.id)
-
A Functions to Check if the User is Admin or not
-
Parameters:
-
chat_id (int):
- The Chat ID of Which Chat has to check the Admin Status.
-
user_id (int):
- The User ID of Whose Admin Status have to Check.
-
client (
pyrogram.Client
):- From which Client to Check the Admin Status.
-
-
Returns:
-
True
if the User is Admin. -
False
if the User is't Admin.
-
from tgEasy import tgClient, is_admin, adminsOnly
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("ban", group_only=True, self_admin=True)
@app.adminsOnly("can_restrict_members")
async def ban(client, message):
if await is_admin(message.chat.id, (await get_user(mesasge)).id):
return await message.reply_text("You can't Ban Admins.")
await message.chat.kick_member((await get_user(message)).id)
await message.reply_text("User has been Banned.")
-
A Function to Handle the Errors in Functions.
-
This Sends the Error Log to the Log Group and Replies Sorry Message for the Users.
-
This is a Helper for all of the functions for handling Errors.
-
Parameters:
-
error:
- The Exceptation.
-
m (
pyrogram.types.Message
orpyrogram.types.CallbackQuery
):- The Message or Callback Query where the Error occurred.
-
from tgEasy import tgClient, handle_error
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("start")
async def start(client, message):
try:
await message.reply_text("Hi :D') # I intentionally made an bug for Example :/
except Exceptation as e:
return await handle_error(e, message)
-
A Function to Send the Typing Status to the Chat.
-
Parameters:
- m (
pyrogram.types.Message
||pyrogram.types.CallbackQuery
):- Message or Callbackquery.
- m (
from tgEasy import tgClinet, send_typing
import pyrogram
app = tgClient(pyrogram.Client())
@app.command("start")
async def start(client, message):
await send_typing(message)
await message.reply_text("Hello")
- To access
pyrogram.Client
of thetgClient
. - Returns:
- pyrogram.Client
print(tgClient.__client__) -> Client()
tgEasy - Easy for a brighter Shine. A monkey pather add-on for Pyrogram
Copyright (C) 2021 Jayant Hegde Kageri <https://github.com/jayantkageri>
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/>.