File size: 3,771 Bytes
21bc372 1d0a11d 21bc372 |
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 |
# credits original: yukki music
# kurigram versions: latest
# code by @xpushz
import asyncio
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
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id)
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id, client.me.id)
if not protect_own and not is_sudo:
return await message.reply_text("You are not allowed here.")
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 |