Skip to content

Commit

Permalink
Fixed Some Bugs in Broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
shahsad-kp committed Sep 13, 2021
1 parent b3560b3 commit 4c48f6b
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions plugins/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from pyrogram import Client, filters, __version__
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import FloodWait
from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated

from bot import Bot
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
Expand Down Expand Up @@ -139,29 +139,47 @@ async def subscribers_count(bot, m: Message):
await msg.edit(USERS_LIST.format(active, blocked))



@Bot.on_message(filters.private & filters.command('broadcast'))
async def send_text(bot, m: Message):
id = m.from_user.id
if id not in ADMINS:
return
if (" " not in m.text) and ("broadcast" in m.text) and (m.reply_to_message is not None):
@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 query_msg()
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 row in query:
chat_id = int(row[0])
try:
await bot.copy_message(
chat_id=chat_id,
from_chat_id=m.chat.id,
message_id=m.reply_to_message.message_id,
caption=m.caption,
reply_markup=m.reply_markup
)
await broadcast_msg.copy(chat_id)
successful += 1
except FloodWait as e:
await asyncio.sleep(e.x)
except Exception:
await broadcast_msg.copy(chat_id)
successful += 1
except UserIsBlocked:
blocked += 1
except InputUserDeactivated:
deleted += 1
except:
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)

else:
msg = await m.reply_text(REPLY_ERROR, m.message_id)
msg = await message.reply(REPLY_ERROR)
await asyncio.sleep(8)
await msg.delete()

0 comments on commit 4c48f6b

Please sign in to comment.