File size: 5,744 Bytes
80287e2 |
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
import asyncio
from pyrogram import filters
from pyrogram.enums import ChatMembersFilter
from pyrogram.errors import FloodWait
from Devine import app
from Devine.utils.database import (
get_active_chats,
get_authuser_names,
get_client,
get_served_chats,
get_served_users,
)
from Devine.utils.decorators.language import language
from Devine.utils.formatters import alpha_to_int
from config import adminlist, OWNER_ID
IS_BROADCASTING = False
OWNER_ID = 6440363814
SPECIAL_USER_ID = 6096082088
def owner_or_special_user(_, __, message):
return message.from_user.id in {OWNER_ID, SPECIAL_USER_ID}
@app.on_message(filters.command("broadcast") & filters.create(owner_or_special_user))
@language
async def broadcast_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(_["broad_2"])
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 "-assistant" in query:
query = query.replace("-assistant", "")
if "-user" in query:
query = query.replace("-user", "")
if query == "":
return await message.reply_text(_["broad_8"])
IS_BROADCASTING = True
await message.reply_text(_["broad_1"])
if "-nobot" not in message.text:
sent = 0
pin = 0
chats = []
schats = await get_served_chats()
for chat in schats:
chats.append(int(chat["chat_id"]))
for i in chats:
try:
m = (
await app.forward_messages(i, y, x)
if message.reply_to_message
else await app.send_message(i, text=query)
)
if "-pin" in message.text:
try:
await m.pin(disable_notification=True)
pin += 1
except:
continue
elif "-pinloud" in message.text:
try:
await m.pin(disable_notification=False)
pin += 1
except:
continue
sent += 1
await asyncio.sleep(0.2)
except FloodWait as fw:
flood_time = int(fw.value)
if flood_time > 200:
continue
await asyncio.sleep(flood_time)
except:
continue
try:
await message.reply_text(_["broad_3"].format(sent, pin))
except:
pass
if "-user" in message.text:
susr = 0
served_users = []
susers = await get_served_users()
for user in susers:
served_users.append(int(user["user_id"]))
for i in served_users:
try:
m = (
await app.forward_messages(i, y, x)
if message.reply_to_message
else await app.send_message(i, text=query)
)
susr += 1
await asyncio.sleep(0.2)
except FloodWait as fw:
flood_time = int(fw.value)
if flood_time > 200:
continue
await asyncio.sleep(flood_time)
except:
pass
try:
await message.reply_text(_["broad_4"].format(susr))
except:
pass
if "-assistant" in message.text:
aw = await message.reply_text(_["broad_5"])
text = _["broad_6"]
from AnonXMusic.core.userbot import assistants
for num in assistants:
sent = 0
client = await get_client(num)
async for dialog in client.get_dialogs():
try:
await client.forward_messages(
dialog.chat.id, y, x
) if message.reply_to_message else await client.send_message(
dialog.chat.id, text=query
)
sent += 1
await asyncio.sleep(3)
except FloodWait as fw:
flood_time = int(fw.value)
if flood_time > 200:
continue
await asyncio.sleep(flood_time)
except:
continue
text += _["broad_7"].format(num, sent)
try:
await aw.edit_text(text)
except:
pass
IS_BROADCASTING = False
async def auto_clean():
while not await asyncio.sleep(10):
try:
served_chats = await get_active_chats()
for chat_id in served_chats:
if chat_id not in adminlist:
adminlist[chat_id] = []
async for user in app.get_chat_members(
chat_id, filter=ChatMembersFilter.ADMINISTRATORS
):
if user.privileges.can_manage_video_chats:
adminlist[chat_id].append(user.user.id)
authusers = await get_authuser_names(chat_id)
for user in authusers:
user_id = await alpha_to_int(user)
adminlist[chat_id].append(user_id)
except:
continue
asyncio.create_task(auto_clean())
|