Skip to content

Instantly share code, notes, and snippets.

@MukundSinghRajput
Last active June 27, 2024 15:37
Show Gist options
  • Save MukundSinghRajput/06ba421efa3e56d7b92f23f64a0e77a1 to your computer and use it in GitHub Desktop.
Save MukundSinghRajput/06ba421efa3e56d7b92f23f64a0e77a1 to your computer and use it in GitHub Desktop.
A class decorator for the python-telegram-bot library
"""
The code below is from my 1.x year old close sourced project so maybe there can be some minor errors that may occur due
to some changes made by the developers of the python-telegramb-bot
-------------------------------------------------------------
If you liked my work then to apreciate me can you use this
Mukund class directly with the name Mukund
-------------------------------------------------------------
"""
from telegram.constants import ParseMode
from telegram.ext import Application, CommandHandler, ContextTypes, PrefixHandler
from telegram import __version__, __bot_api_version__, Update, InlineKeyboardButton, InlineKeyboardMarkup
from functools import wraps
#from src.Functions.antisam import AntiSpam
from src.Database.banned_db import Banned
ban = Banned()
#SpamCheck = AntiSpam()
class Mukund:
def __init__(self, command, filters=None, block=False, has_args=None):
self.command = command
self.filters = filters
self.block = block
self.has_args = has_args
def __call__(self, callback):
@wraps(callback)
async def wrapper(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = update.effective_message.from_user.id
#ignore=SpamCheck.check_user(user=user_id)
#if ignore:
# return
# is_banned logic
try:
x = ban.check_banned(str(user_id))
if x:
await update.message.delete()
return
await update.message.reply_text(text="You are not banned")
except ValueError as ve:
print(f"Error in is_banned: {ve}")
# is_in_group logic
try:
x = await context.bot.get_chat_member(chat_id=-1001990996252, user_id=user_id)
stamst = [x.ADMINISTRATOR, x.MEMBER, x.BANNED, x.OWNER, x.RESTRICTED]
if x.status not in stamst:
await update.message.reply_text(text="Hᴇʏ ɪғ ᴜ ᴡᴀɴɴᴀ ᴜsᴇ ᴍᴇ ᴊᴏɪɴ ᴍʏ ɢʀᴏᴜᴘ ғɪʀsᴛ", parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔥 Gʀᴏᴜᴘ 🔥", url="https://t.me/MukundAI")]]))
return
except Exception as e:
print(f"Error in is_in_group: {e}")
# Your original callback logic
await callback(update, context)
#handler = CommandHandler(self.command, wrapper, filters=self.filters, block=self.block, has_args=self.has_args)
handler = PrefixHandler(prefix=["!", ".", "#", "$", "/"], command=self.command, callback=wrapper, filters=self.filters, block=self.block)
app.add_handler(handler)
return wrapper
start="""**──「Iᴛ's [{name}](http://t.me/{username}) 🥀」──
» Vᴇʀsɪᴏɴ : : `1.1`
» Lᴀɴɢᴜᴀɢᴇ : [ᴘʏᴛʜᴏɴ 3](https://www.python.org/)
» Sᴇʀᴠᴇʀ : [ʜᴇʀᴏᴋᴜ](https://heroku.com/)
» Bᴏᴛ Aᴘɪ Vᴇʀꜱɪᴏɴ : {bver}
» Lɪʙʀᴀʀʏ Vᴇʀꜱɪᴏɴ : {lver}
➬ Pᴏᴡᴇʀᴇᴅ Bʏ Cᴏɴᴛʀᴏʟʟᴇʀ [𝗠ᴇᴛᴀ 𝘅𝗗 🦁](https://t.me/META_CHATS) ✨**"""
# Automatically post a message on startup
async def post(app: Application) -> None:
await app.bot.send_photo(
-1001990996252,
"https://te.legra.ph/file/5aebe7307dc52f9999b02.jpg",
f"{start.format(name=app.bot.first_name, username=app.bot.username, bver=__bot_api_version__, lver=__version__)}",
parse_mode=ParseMode.MARKDOWN
)
app = Application.builder().token("5946041798:AAFJQtqZSoiTnXGB3wGC4xdjo0a3IQlCXhs").post_init(post).build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment