Spaces:
Build error
Build error
# (c) Asm Safone | |
# A Part of MegaDL-Bot <https://github.com/AsmSafone/MegaDL-Bot> | |
import os | |
import math | |
import time | |
import shutil | |
import asyncio | |
import logging | |
from pyrogram import Client, filters | |
from pyrogram.errors import FloodWait, UserNotParticipant | |
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton | |
from megadl.forcesub import handle_force_subscribe | |
from config import Config, TEXT | |
async def help(bot, message, cb=False): | |
if Config.UPDATES_CHANNEL: | |
fsub = await handle_force_subscribe(bot, message) | |
if fsub == 400: | |
return | |
me = await bot.get_me() | |
button = [[ | |
InlineKeyboardButton(f'π HOME', callback_data='back'), | |
InlineKeyboardButton(f'ABOUT π¨', callback_data='about') | |
],[ | |
InlineKeyboardButton(f'π¦ SOURCE', url='https://github.com/imseldrith/MegaDL-Bot'), | |
InlineKeyboardButton(f'CLOSE π', callback_data='close') | |
]] | |
reply_markup = InlineKeyboardMarkup(button) | |
if cb: | |
await message.message.edit( | |
text=TEXT.HELP_USER.format(bot_name=me.mention(style='md')), | |
disable_web_page_preview=True, | |
reply_markup=reply_markup | |
) | |
else: | |
await message.reply_text( | |
text=TEXT.HELP_USER.format(bot_name=me.mention(style='md')), | |
disable_web_page_preview=True, | |
reply_markup=reply_markup, | |
quote=True | |
) | |
async def start(bot, message, cb=False): | |
if Config.UPDATES_CHANNEL: | |
fsub = await handle_force_subscribe(bot, message) | |
if fsub == 400: | |
return | |
me = await bot.get_me() | |
owner = await bot.get_users(Config.OWNER_ID) | |
owner_username = owner.username if owner.username else 'AsmSafone' | |
button = [[ | |
InlineKeyboardButton(f'π‘ HELP', callback_data='help'), | |
InlineKeyboardButton(f'ABOUT π¨', callback_data="about") | |
],[ | |
InlineKeyboardButton(f'π¦ SOURCE', url='https://github.com/imseldrith/MegaDL-Bot'), | |
InlineKeyboardButton(f'CLOSE π', callback_data="close") | |
]] | |
reply_markup = InlineKeyboardMarkup(button) | |
if cb: | |
await message.message.edit( | |
text=TEXT.START_TEXT.format(user_mention=message.from_user.mention, bot_name=me.mention(style='md'), bot_owner=owner.mention(style="md")), | |
disable_web_page_preview=True, | |
reply_markup=reply_markup | |
) | |
else: | |
await message.reply_text( | |
text=TEXT.START_TEXT.format(user_mention=message.from_user.mention, bot_name=me.mention(style='md'), bot_owner=owner.mention(style="md")), | |
disable_web_page_preview=True, | |
reply_markup=reply_markup, | |
quote=True | |
) | |
async def about(bot, message, cb=False): | |
if Config.UPDATES_CHANNEL: | |
fsub = await handle_force_subscribe(bot, message) | |
if fsub == 400: | |
return | |
me = await bot.get_me() | |
button = [[ | |
InlineKeyboardButton(f'π HOME', callback_data='back'), | |
InlineKeyboardButton(f'HELP π‘', callback_data='help') | |
],[ | |
InlineKeyboardButton(f'π¦ SOURCE', url='https://github.com/imseldrith/MegaDL-Bot'), | |
InlineKeyboardButton(f'CLOSE π', callback_data="close") | |
]] | |
reply_markup = InlineKeyboardMarkup(button) | |
if cb: | |
await message.message.edit( | |
text=TEXT.ABOUT.format(bot_name=me.mention(style='md')), | |
disable_web_page_preview=True, | |
reply_markup=reply_markup | |
) | |
else: | |
await message.reply_text( | |
text=TEXT.ABOUT.format(bot_name=me.mention(style='md')), | |
disable_web_page_preview=True, | |
reply_markup=reply_markup, | |
quote=True | |
) | |
async def help_cb(bot, message): | |
await message.answer() | |
await help(bot, message, True) | |
async def close_cb(bot, message): | |
await message.message.delete() | |
await message.message.reply_to_message.delete() | |
async def back_cb(bot, message): | |
await message.answer() | |
await start(bot, message, True) | |
async def about_cb(bot, message): | |
await message.answer() | |
await about(bot, message, True) | |
async def refreshmeh_cb(bot, message): | |
if Config.UPDATES_CHANNEL: | |
invite_link = await bot.create_chat_invite_link(int(Config.UPDATES_CHANNEL)) | |
try: | |
user = await bot.get_chat_member(int(Config.UPDATES_CHANNEL), message.from_user.id) | |
if user.status == "kicked": | |
await message.message.edit( | |
text="Sorry Sir, You are Banned. Contact My [Support Group](https://t.me/url_upload_bots).", | |
parse_mode="markdown", | |
disable_web_page_preview=True | |
) | |
return | |
except UserNotParticipant: | |
await message.message.edit( | |
text="**You Still Didn't Join βΉοΈ, Please Join My Updates Channel To Use Me!**\n\nDue to Overload, Only Channel Subscribers Can Use Me!", | |
reply_markup=InlineKeyboardMarkup( | |
[ | |
[ | |
InlineKeyboardButton("π€ Join Updates Channel π€", url=invite_link.invite_link) | |
], | |
[ | |
InlineKeyboardButton("π Refresh π", callback_data="refreshmeh") | |
] | |
] | |
), | |
parse_mode="markdown" | |
) | |
return | |
except Exception: | |
await message.message.edit( | |
text="Something Went Wrong. Contact My [Support Group](https://t.me/url_upload_bots).", | |
parse_mode="markdown", | |
disable_web_page_preview=True | |
) | |
return | |
await message.answer() | |
await start(bot, message, True) | |
async def cancel_cb(bot, message): | |
basedir = Config.DOWNLOAD_LOCATION | |
userpath = str(message.from_user.id) | |
try: | |
await message.answer( | |
"Trying To Cancel... π€", | |
show_alert=True | |
) | |
await asyncio.sleep(5) | |
shutil.rmtree(basedir + "/" + userpath) | |
await message.message.delete() | |
await message.message.reply_text("**Process Cancelled By User π‘!**", reply_to_message_id=message.message_id) | |
except Exception as e: | |
await print(e) | |
await message.answer( | |
"Can't Cancel Right Now! π‘", | |
show_alert=True | |
) | |