Spaces:
Build error
Build error
File size: 7,044 Bytes
9725bda |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# (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
@Client.on_message(filters.command("help") & filters.private & filters.incoming)
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/AsmSafone/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
)
@Client.on_message(filters.command("start") & filters.private & filters.incoming)
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/AsmSafone/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
)
@Client.on_message(filters.command("about") & filters.private & filters.incoming)
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/AsmSafone/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
)
@Client.on_callback_query(filters.regex('^help$'))
async def help_cb(bot, message):
await message.answer()
await help(bot, message, True)
@Client.on_callback_query(filters.regex('^close$'))
async def close_cb(bot, message):
await message.message.delete()
await message.message.reply_to_message.delete()
@Client.on_callback_query(filters.regex('^back$'))
async def back_cb(bot, message):
await message.answer()
await start(bot, message, True)
@Client.on_callback_query(filters.regex('^about$'))
async def about_cb(bot, message):
await message.answer()
await about(bot, message, True)
@Client.on_callback_query(filters.regex('^refreshmeh$'))
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/AsmSupport).",
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/AsmSupport).",
parse_mode="markdown",
disable_web_page_preview=True
)
return
await message.answer()
await start(bot, message, True)
@Client.on_callback_query(filters.regex('^cancel_mega$'))
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
)
|