Spaces:
Runtime error
Runtime error
File size: 8,547 Bytes
54b4aee 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a 9f98563 fbf7111 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a 11bbd75 9f98563 edf6e6c fbf7111 38181e7 fbf7111 9a1c52a 0e29bd9 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a fbf7111 9a1c52a 38181e7 f7f926a 11bbd75 f7f926a 38181e7 9a1c52a ed0a47f |
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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
import os, asyncio, humanize
from pyrogram import Client, filters, __version__
from pyrogram.enums import ParseMode
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated
from bot import Bot
from config import ADMINS, FORCE_MSG, START_MSG, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON, PROTECT_CONTENT, FILE_AUTO_DELETE
from helper_func import subscribed, encode, decode, get_messages
from database.database import add_user, del_user, full_userbase, present_user
madflixofficials = FILE_AUTO_DELETE
jishudeveloper = madflixofficials
file_auto_delete = humanize.naturaldelta(jishudeveloper)
@Bot.on_message(filters.command('start') & filters.private & subscribed)
async def start_command(client: Client, message: Message):
id = message.from_user.id
if not await present_user(id):
try:
await add_user(id)
except:
pass
text = message.text
if len(text)>7:
try:
base64_string = text.split(" ", 1)[1]
except:
return
string = await decode(base64_string)
argument = string.split("-")
if len(argument) == 3:
try:
start = int(int(argument[1]) / abs(client.db_channel.id))
end = int(int(argument[2]) / abs(client.db_channel.id))
except:
return
if start <= end:
ids = range(start,end+1)
else:
ids = []
i = start
while True:
ids.append(i)
i -= 1
if i < end:
break
elif len(argument) == 2:
try:
ids = [int(int(argument[1]) / abs(client.db_channel.id))]
except:
return
temp_msg = await message.reply("Please Wait...")
try:
messages = await get_messages(client, ids)
except:
await message.reply_text("Something Went Wrong..!")
return
await temp_msg.delete()
madflix_msgs = [] # List to keep track of sent messages
for msg in messages:
if bool(CUSTOM_CAPTION) & bool(msg.document):
caption = CUSTOM_CAPTION.format(previouscaption = "" if not msg.caption else msg.caption.html, filename = msg.document.file_name)
else:
caption = "" if not msg.caption else msg.caption.html
if DISABLE_CHANNEL_BUTTON:
reply_markup = msg.reply_markup
else:
reply_markup = None
try:
madflix_msg = await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = ParseMode.HTML, reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
# await asyncio.sleep(0.5)
madflix_msgs.append(madflix_msg)
except FloodWait as e:
await asyncio.sleep(e.x)
madflix_msg = await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = ParseMode.HTML, reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
madflix_msgs.append(madflix_msg)
except:
pass
k = await client.send_message(chat_id = message.from_user.id, text=f"<b>βοΈ <u>IMPORTANT</u> βοΈ</b>\n\nThis Video / File Will Be Deleted In {file_auto_delete} (Due To Copyright Issues).\n\nπ Please Forward This Video / File To Somewhere Else And Start Downloading There.")
# Schedule the file deletion
asyncio.create_task(delete_files(madflix_msgs, client, k))
# for madflix_msg in madflix_msgs:
# try:
# await madflix_msg.delete()
# await k.edit_text("Your Video / File Is Successfully Deleted β
")
# except:
# pass
return
else:
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("π About Me", callback_data = "about"),
InlineKeyboardButton("π Close", callback_data = "close")
]
]
)
await message.reply_text(
text = START_MSG.format(
first = message.from_user.first_name,
last = message.from_user.last_name,
username = None if not message.from_user.username else '@' + message.from_user.username,
mention = message.from_user.mention,
id = message.from_user.id
),
reply_markup = reply_markup,
disable_web_page_preview = True,
quote = True
)
return
@Bot.on_message(filters.command('start') & filters.private)
async def not_joined(client: Client, message: Message):
buttons = [
[
InlineKeyboardButton(text="Join Channel", url=client.invitelink)
]
]
try:
buttons.append(
[
InlineKeyboardButton(
text = 'Try Again',
url = f"https://t.me/{client.username}?start={message.command[1]}"
)
]
)
except IndexError:
pass
await message.reply(
text = FORCE_MSG.format(
first = message.from_user.first_name,
last = message.from_user.last_name,
username = None if not message.from_user.username else '@' + message.from_user.username,
mention = message.from_user.mention,
id = message.from_user.id
),
reply_markup = InlineKeyboardMarkup(buttons),
quote = True,
disable_web_page_preview = True
)
@Bot.on_message(filters.command('users') & filters.private & filters.user(ADMINS))
async def get_users(client: Bot, message: Message):
msg = await client.send_message(chat_id=message.chat.id, text=f"Processing...")
users = await full_userbase()
await msg.edit(f"{len(users)} Users Are Using This Bot")
@Bot.on_message(filters.private & filters.command('broadcast') & filters.user(ADMINS))
async def send_text(client: Bot, message: Message):
if message.reply_to_message:
query = await full_userbase()
broadcast_msg = message.reply_to_message
total = 0
successful = 0
blocked = 0
deleted = 0
unsuccessful = 0
pls_wait = await message.reply("<i>Broadcasting Message.. This will Take Some Time</i>")
for chat_id in query:
try:
await broadcast_msg.copy(chat_id)
successful += 1
except FloodWait as e:
await asyncio.sleep(e.x)
await broadcast_msg.copy(chat_id)
successful += 1
except UserIsBlocked:
await del_user(chat_id)
blocked += 1
except InputUserDeactivated:
await del_user(chat_id)
deleted += 1
except:
unsuccessful += 1
pass
total += 1
status = f"""<b><u>Broadcast Completed</u></b>
<b>Total Users :</b> <code>{total}</code>
<b>Successful :</b> <code>{successful}</code>
<b>Blocked Users :</b> <code>{blocked}</code>
<b>Deleted Accounts :</b> <code>{deleted}</code>
<b>Unsuccessful :</b> <code>{unsuccessful}</code>"""
return await pls_wait.edit(status)
else:
msg = await message.reply(f"Use This Command As A Reply To Any Telegram Message With Out Any Spaces.")
await asyncio.sleep(8)
await msg.delete()
# Function to handle file deletion
async def delete_files(messages, client, k):
await asyncio.sleep(FILE_AUTO_DELETE) # Wait for the duration specified in config.py
for msg in messages:
try:
await client.delete_messages(chat_id=msg.chat.id, message_ids=[msg.id])
except Exception as e:
print(f"The attempt to delete the media {msg.id} was unsuccessful: {e}")
# await client.send_message(messages[0].chat.id, "Your Video / File Is Successfully Deleted β
")
await k.edit_text("Your Video / File Is Successfully Deleted β
")
# Jishu Developer
# Don't Remove Credit π₯Ί
# Telegram Channel @Madflix_Bots
# Backup Channel @JishuBotz
# Developer @JishuDeveloper
|