-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgcast.py
65 lines (51 loc) · 2.15 KB
/
gcast.py
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
import asyncio
from pyrogram import Client, filters
from pyrogram.errors import FloodWait
from pyrogram.types import Message
from utils.misc import modules_help, prefix
@Client.on_message(filters.command("gcast", prefix) & filters.me)
async def gcast(client: Client, message: Message):
if message.reply_to_message:
msg = message.reply_to_message.text
elif len(message.command) > 1:
msg = " ".join(message.command[1:])
else:
await message.edit("Provide text or reply to a message to broadcast globally.")
return
await message.edit("Starting global broadcast...")
done, errors = 0, 0
async for dialog in client.get_dialogs():
if dialog.chat.type.value in ["supergroup", "group"]:
try:
await client.send_message(dialog.chat.id, msg)
done += 1
except FloodWait as e:
await asyncio.sleep(e.value + 10)
except Exception as e:
errors += 1
print(f"Error: {e}")
await message.edit(f"Broadcast completed: {done} successful, {errors} failed.")
@Client.on_message(filters.command("gucast", prefix) & filters.me)
async def gucast(client: Client, message: Message):
if message.reply_to_message:
msg = message.reply_to_message.text
elif len(message.command) > 1:
msg = " ".join(message.command[1:])
else:
await message.edit("Provide text or reply to a message to broadcast globally to users.")
return
await message.edit("Starting global user broadcast...")
done, errors = 0, 0
async for dialog in client.get_dialogs():
if dialog.chat.type.value == "private" and not dialog.chat.is_bot:
try:
await client.send_message(dialog.chat.id, msg)
done += 1
except Exception as e:
errors += 1
print(f"Error: {e}")
await message.edit(f"Broadcast completed: {done} successful, {errors} failed.")
modules_help["gcast"] = {
"gcast [text/reply to text]*": "Broadcast message to all groups.",
"gucast [text/reply to text]*": "Broadcast message to all private users."
}