MissKatyPyro/misskaty/plugins/broadcast.py
yasirarism 68d006607f
Big Update And Some Fixing Code (#86)
- AutoFix Code Using DeepSource
- Fix os not defined when got error
- Fix Set Chat Photo (Only support photo)
- Fix Admins Permission Error
- Fix KeyError in Scraper
- Fix Help Module in Eval
- Fix Media Caption Too Long in IMDB
- Remove heroku support
- Some minor fix..
2023-06-22 12:52:30 +07:00

43 lines
1.5 KiB
Python

import asyncio
import datetime
import time
from pyrogram import Client, filters
from pyrogram.types import Message
from database.users_chats_db import db
from misskaty import app
from misskaty.vars import SUDO
from utils import broadcast_messages
@app.on_message(filters.command("broadcast") & filters.user(SUDO) & filters.reply)
async def broadcast(self: Client, ctx: Message):
users = await db.get_all_users()
b_msg = ctx.reply_to_message
sts = await ctx.reply_msg("Broadcasting your messages...")
start_time = time.time()
total_users = await db.total_users_count()
done = 0
blocked = 0
deleted = 0
failed = 0
success = 0
async for user in users:
pti, sh = await broadcast_messages(int(user["id"]), b_msg)
if pti:
success += 1
elif pti is False:
if sh == "Blocked":
blocked += 1
elif sh == "Deleted":
deleted += 1
elif sh == "Error":
failed += 1
done += 1
await asyncio.sleep(2)
if not done % 20:
await sts.edit_msg(f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
time_taken = datetime.timedelta(seconds=int(time.time() - start_time))
await sts.edit_msg(f"Broadcast Completed:\nCompleted in {time_taken} seconds.\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")