|
| 1 | +import os |
| 2 | +import asyncio |
| 3 | +from pyrogram.types import Message |
| 4 | +from pyrogram import Client, filters |
| 5 | +from pyrogram.errors import FloodWait |
| 6 | +from database.support import users_info |
| 7 | +from database.sql import add_user, query_msg |
| 8 | +from config import OWNER_ID |
| 9 | + |
| 10 | +USERS_LIST = """<b>⭕️Total:</b>\n\n⭕️Subscribers - {}\n⭕️Blocked- {}""" |
| 11 | + |
| 12 | +WAIT_MSG = """"<b>Processing ...</b>""" |
| 13 | + |
| 14 | +REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>""" |
| 15 | + |
| 16 | +@Client.on_message(filters.private & filters.command('start')) |
| 17 | +async def start_bot(bot, m: Message): |
| 18 | + id = m.from_user.id |
| 19 | + user_name = '@' + m.from_user.username if m.from_user.username else None |
| 20 | + await add_user(id, user_name) |
| 21 | + |
| 22 | + |
| 23 | +@Client.on_message(filters.private & filters.command('users')) |
| 24 | +async def subscribers_count(bot, m: Message): |
| 25 | + id = m.from_user.id |
| 26 | + if id not in OWNER_ID: |
| 27 | + return |
| 28 | + msg = await m.reply_text(WAIT_MSG) |
| 29 | + messages = await users_info(bot) |
| 30 | + active = messages[0] |
| 31 | + blocked = messages[1] |
| 32 | + await m.delete() |
| 33 | + await msg.edit(USERS_LIST.format(active, blocked)) |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +@Client.on_message(filters.private & filters.command('broadcast')) |
| 38 | +async def send_text(bot, m: Message): |
| 39 | + id = m.from_user.id |
| 40 | + if id not in OWNER_ID: |
| 41 | + return |
| 42 | + if (" " not in m.text) and ("broadcast" in m.text) and (m.reply_to_message is not None): |
| 43 | + query = await query_msg() |
| 44 | + for row in query: |
| 45 | + chat_id = int(row[0]) |
| 46 | + try: |
| 47 | + await bot.copy_message( |
| 48 | + chat_id=chat_id, |
| 49 | + from_chat_id=m.chat.id, |
| 50 | + message_id=m.reply_to_message.message_id, |
| 51 | + caption=m.caption, |
| 52 | + reply_markup=m.reply_markup |
| 53 | + ) |
| 54 | + except FloodWait as e: |
| 55 | + await asyncio.sleep(e.x) |
| 56 | + except Exception: |
| 57 | + pass |
| 58 | + else: |
| 59 | + msg = await m.reply_text(REPLY_ERROR, m.message_id) |
| 60 | + await asyncio.sleep(8) |
| 61 | + await msg.delete() |
0 commit comments