randydev's picture
fix revert back and update
21bc372
raw
history blame
3.55 kB
# credits original: yukki music
# kurigram versions: latest
# code by @xpushz
import time
import os
import asyncio
from datetime import datetime
from pyrogram import *
from pyrogram.types import *
from pyrogram.errors import *
from akn.utils.logger import LOGS
from akn.utils.database import db
@Client.on_message(
~filters.scheduled
& filters.command(["broadcast"])
& ~filters.forwarded
)
async def braodcast_message(client, message):
global IS_BROADCASTING
if message.reply_to_message:
x = message.reply_to_message.id
y = message.chat.id
else:
if len(message.command) < 2:
return await message.reply_text("**Usage**:\n/broadcast [MESSAGE] or [Reply to a Message]")
query = message.text.split(None, 1)[1]
if "-pin" in query:
query = query.replace("-pin", "")
if "-nobot" in query:
query = query.replace("-nobot", "")
if "-pinloud" in query:
query = query.replace("-pinloud", "")
if "-user" in query:
query = query.replace("-user", "")
if query == "":
return await message.reply_text("Please provide some text to broadcast.")
IS_BROADCASTING = True
if "-nobot" not in message.text:
sent = 0
pin = 0
chats = []
schats = await db.alldlbot_all_broadcast_group(client.me.id)
for chat in schats:
chats.append(int(chat))
for i in chats:
try:
m = (
await client.forward_messages(i, y, x)
if message.reply_to_message
else await client.send_message(i, text=query)
)
if "-pin" in message.text:
try:
await m.pin(disable_notification=True)
pin += 1
except Exception:
continue
elif "-pinloud" in message.text:
try:
await m.pin(disable_notification=False)
pin += 1
except Exception:
continue
sent += 1
except FloodWait as e:
flood_time = int(e.x)
if flood_time > 200:
continue
await asyncio.sleep(flood_time)
except Exception:
continue
try:
await message.reply_text(
f"Broadcasted Message In {sent} Chats with {pin} Pins from Bot"
)
except:
pass
if "-user" in message.text:
susr = 0
served_users = []
susers = await db.alldlbot_all_broadcast(client.me.id)
for user in susers:
served_users.append(int(user))
for i in served_users:
try:
m = (
await client.forward_messages(i, y, x)
if message.reply_to_message
else await client.send_message(i, text=query)
)
susr += 1
except FloodWait as e:
flood_time = int(e.x)
if flood_time > 200:
continue
await asyncio.sleep(flood_time)
except Exception:
pass
try:
await message.reply_text(
f"**Broadcasted Message to {susr} Users.**"
)
except:
pass
IS_BROADCASTING = False