Skip to content

Commit

Permalink
added Broadcast canceling button while Broadcast in Process
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamBasava committed Jul 16, 2024
1 parent 47559bd commit 11ce616
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 46 deletions.
Binary file modified Bot.session
Binary file not shown.
56 changes: 56 additions & 0 deletions filesharingbot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,59 @@ https://t.me/codeflix_bots

[08-Jul-24 14:16:35 - INFO] - root - Stop signal received (SIGINT). Exiting...
[08-Jul-24 14:16:35 - INFO] - bot - Bot stopped.
[16-Jul-24 10:35:45 - INFO] - bot - Bot Running..!

Created by
https://t.me/codeflix_bots
[16-Jul-24 10:35:45 - INFO] - bot -


___ ___ ___ ___ ___ _ _____ _____ ___ _____ ___
/ __/ _ \| \| __| __| | |_ _\ \/ / _ )/ _ \_ _/ __|
| (_| (_) | |) | _|| _|| |__ | | > <| _ \ (_) || | \__ \___\___/|___/|___|_| |____|___/_/\_\___/\___/ |_| |___/



[16-Jul-24 10:37:55 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:37:55 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:37:55 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:37:55 - WARNING] - pyrogram.session.session - [Bot] Waiting for 4 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:37:59 - WARNING] - pyrogram.session.session - [Bot] Waiting for 3 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:38:01 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:38:01 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:38:02 - WARNING] - pyrogram.session.session - [Bot] Waiting for 3 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:39:26 - ERROR] - pyrogram.dispatcher - object async_generator can't be used in 'await' expression
Traceback (most recent call last):
File "C:\Users\Shubham_Basava\anaconda3\lib\site-packages\pyrogram\dispatcher.py", line 440, in handler_worker
await handler.callback(self.client, *args)
File "C:\Users\Shubham_Basava\anaconda3\lib\site-packages\pyrogram\handlers\message_handler.py", line 154, in resolve_future_or_callback
await self.original_callback(client, message, *args)
File "C:\Users\Shubham_Basava\Telegram\TestBot\plugins\link_generator.py", line 41, in batch
last_msg_id = await client.get_chat_history(db_channel_id, limit=1)
TypeError: object async_generator can't be used in 'await' expression
[16-Jul-24 10:40:15 - INFO] - root - Stop signal received (SIGINT). Exiting...
[16-Jul-24 10:40:15 - INFO] - bot - Bot stopped.
[16-Jul-24 10:41:14 - INFO] - bot - Bot Running..!

Created by
https://t.me/codeflix_bots
[16-Jul-24 10:41:14 - INFO] - bot -


___ ___ ___ ___ ___ _ _____ _____ ___ _____ ___
/ __/ _ \| \| __| __| | |_ _\ \/ / _ )/ _ \_ _/ __|
| (_| (_) | |) | _|| _|| |__ | | > <| _ \ (_) || | \__ \___\___/|___/|___|_| |____|___/_/\_\___/\___/ |_| |___/



[16-Jul-24 10:41:35 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:41:35 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:41:35 - WARNING] - pyrogram.session.session - [Bot] Waiting for 5 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:41:41 - WARNING] - pyrogram.session.session - [Bot] Waiting for 4 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:41:41 - WARNING] - pyrogram.session.session - [Bot] Waiting for 4 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:41:41 - WARNING] - pyrogram.session.session - [Bot] Waiting for 4 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:41:45 - WARNING] - pyrogram.session.session - [Bot] Waiting for 3 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:41:45 - WARNING] - pyrogram.session.session - [Bot] Waiting for 3 seconds before continuing (required by "messages.EditMessage")
[16-Jul-24 10:41:45 - WARNING] - pyrogram.session.session - [Bot] Waiting for 3 seconds before continuing (required by "messages.SendMedia")
[16-Jul-24 10:45:13 - INFO] - root - Stop signal received (SIGINT). Exiting...
[16-Jul-24 10:45:13 - INFO] - bot - Bot stopped.
2 changes: 1 addition & 1 deletion plugins/channel_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from config import ADMINS, CHANNEL_ID, DISABLE_CHANNEL_BUTTON
from helper_func import encode

@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','users','broadcast','batch','genlink','stats']))
@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','users','broadcast','batch','genlink','stats','custom_batch']))
async def channel_post(client: Client, message: Message):
reply_text = await message.reply_text("Please Wait...!", quote = True)
try:
Expand Down
122 changes: 77 additions & 45 deletions plugins/start.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#(©)Codeflix_Bots



# (©)Codeflix_Bots

import os
import asyncio
Expand All @@ -15,8 +12,8 @@
from helper_func import subscribed, encode, decode, get_messages
from database.database import add_user, del_user, full_userbase, present_user



broadcast_in_progress = False
cancel_broadcast = False

@Bot.on_message(filters.command('start') & filters.private & subscribed)
async def start_command(client: Client, message: Message):
Expand All @@ -27,7 +24,7 @@ async def start_command(client: Client, message: Message):
except:
pass
text = message.text
if len(text)>7:
if len(text) > 7:
try:
base64_string = text.split(" ", 1)[1]
except:
Expand All @@ -41,7 +38,7 @@ async def start_command(client: Client, message: Message):
except:
return
if start <= end:
ids = range(start,end+1)
ids = range(start, end + 1)
else:
ids = []
i = start
Expand All @@ -64,9 +61,13 @@ async def start_command(client: Client, message: Message):
await temp_msg.delete()

for msg in messages:
if cancel_broadcast:
await message.reply("Broadcast has been canceled.")
return

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)
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

Expand All @@ -76,48 +77,48 @@ async def start_command(client: Client, message: Message):
reply_markup = None

try:
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = ParseMode.HTML, reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
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)
except FloodWait as e:
await asyncio.sleep(e.x)
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = ParseMode.HTML, reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
await msg.copy(chat_id=message.from_user.id, caption=caption, parse_mode=ParseMode.HTML,
reply_markup=reply_markup, protect_content=PROTECT_CONTENT)
except:
pass
return
else:
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("⚡️ ᴀʙᴏᴜᴛ", callback_data = "about"),
InlineKeyboardButton("⚡️ ᴀʙᴏᴜᴛ", callback_data="about"),
InlineKeyboardButton('🍁 sᴇʀɪᴇsғʟɪx', url='https://t.me/Team_Netflix/40')
]
]
)
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
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
reply_markup=reply_markup,
disable_web_page_preview=True,
quote=True
)
return


#=====================================================================================##
# =====================================================================================##

WAIT_MSG = """"<b>Processing ...</b>"""
WAIT_MSG = """<b>Processing ...</b>"""

REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>"""
REPLY_ERROR = """<code>Use this command as a replay to any telegram message without any spaces.</code>"""

# =====================================================================================##

#=====================================================================================##



@Bot.on_message(filters.command('start') & filters.private)
async def not_joined(client: Client, message: Message):
buttons = [
Expand All @@ -134,46 +135,68 @@ async def not_joined(client: Client, message: Message):
buttons.append(
[
InlineKeyboardButton(
text = '• ɴᴏᴡ ᴄʟɪᴄᴋ ʜᴇʀᴇ •',
url = f"https://t.me/{client.username}?start={message.command[1]}"
text='• ɴᴏᴡ ᴄʟɪᴄᴋ ʜᴇʀᴇ •',
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
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=WAIT_MSG)
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):
global broadcast_in_progress, cancel_broadcast

if message.reply_to_message:
if broadcast_in_progress:
await message.reply("A broadcast is already in progress. Please wait until it is finished.")
return

broadcast_in_progress = True
cancel_broadcast = False

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>")

pls_wait = await message.reply(
"<i>Broadcasting Message.. This will Take Some Time</i>",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Cancel Broadcast", callback_data="cancel_broadcast")]]
)
)

for chat_id in query:
if cancel_broadcast:
await pls_wait.edit("Broadcast has been canceled.")
broadcast_in_progress = False
return

try:
await broadcast_msg.copy(chat_id)
successful += 1
Expand All @@ -191,18 +214,27 @@ async def send_text(client: Bot, message: Message):
unsuccessful += 1
pass
total += 1

status = f"""<b><u>Broadcast Completed</u>
Total Users: <code>{total}</code>
Successful: <code>{successful}</code>
Blocked Users: <code>{blocked}</code>
Deleted Accounts: <code>{deleted}</code>
Unsuccessful: <code>{unsuccessful}</code></b>"""

return await pls_wait.edit(status)

await pls_wait.edit(status)
broadcast_in_progress = False

else:
msg = await message.reply(REPLY_ERROR)
await asyncio.sleep(8)
await msg.delete()


@Bot.on_callback_query(filters.regex("cancel_broadcast") & filters.user(ADMINS))
async def cancel_broadcast_callback(client: Bot, callback_query: CallbackQuery):
global cancel_broadcast
cancel_broadcast = True
await callback_query.answer("Broadcast canceling...")

0 comments on commit 11ce616

Please sign in to comment.