From acfc1bc002bc81385285a76b262e208cb33ca4f6 Mon Sep 17 00:00:00 2001 From: Nexsescorp Date: Tue, 25 Jun 2024 19:41:25 +0530 Subject: [PATCH] Update newgroup.py . --- plugins/newgroup.py | 113 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 19 deletions(-) diff --git a/plugins/newgroup.py b/plugins/newgroup.py index 9a72ea6..eb864fb 100644 --- a/plugins/newgroup.py +++ b/plugins/newgroup.py @@ -1,22 +1,97 @@ +import datetime +import time from info import * from utils import * -from asyncio import sleep -from pyrogram import Client, filters +from pyrogram import Client, filters +from pyrogram.errors import FloodWait +import asyncio -@Client.on_message(filters.group & filters.new_chat_members) -async def new_group(bot, message): - bot_id = (await bot.get_me()).id - member = [u.id for u in message.new_chat_members] - if bot_id in member: - await add_group(group_id=message.chat.id, - group_name=message.chat.title, - user_name=message.from_user.first_name, - user_id=message.from_user.id, - channels=[], - f_sub=False, - verified=False) - m=await message.reply(f"Thanks for adding me in {message.chat.title} ✨\n\nPlease Get Access By /verify\n\n") - text=f"#NewGroup\n\nGroup: {message.chat.title}\nGroupID: `{message.chat.id}`\nAddedBy: {message.from_user.mention}\nUserID: `{message.from_user.id}`" - await bot.send_message(chat_id=LOG_CHANNEL, text=text) - await sleep(60) - await m.delete() +@Client.on_message(filters.command('broadcast') & filters.user(ADMIN)) +async def broadcast(bot, message): + if not message.reply_to_message: + return await message.reply("Use this command as a reply to any message!") + m=await message.reply("Please wait...") + + count, users = await get_users() + stats = "⚡ Broadcast Processing.." + br_msg = message.reply_to_message + total = count + remaining = total + success = 0 + failed = 0 + + for user in users: + chat_id = user["_id"] + trying = await copy_msgs(br_msg, chat_id) + if trying==False: + failed+=1 + remaining-=1 + else: + success+=1 + remaining-=1 + try: + await m.edit(script.BROADCAST.format(stats, total, remaining, success, failed)) + except: + pass + stats = "✅ Broadcast Completed" + await m.reply(script.BROADCAST.format(stats, total, remaining, success, failed)) + await m.delete() + + +@Client.on_message(filters.command('broadcast_groups') & filters.user(ADMIN)) +async def grp_broadcast(bot, message): + if not message.reply_to_message: + return await message.reply("Use this command as a reply to any message!") + m=await message.reply("Please wait...") + + count, groups = await get_groups() + stats = "⚡ Broadcast Processing.." + br_msg = message.reply_to_message + total = count + remaining = total + success = 0 + failed = 0 + + for group in groups: + chat_id = group["_id"] + trying = await grp_copy_msgs(br_msg, chat_id) + if trying==False: + failed+=1 + remaining-=1 + else: + success+=1 + remaining-=1 + try: + await m.edit(script.BROADCAST.format(stats, total, remaining, success, failed)) + except: + pass + stats = "✅ Broadcast Completed" + await m.reply(script.BROADCAST.format(stats, total, remaining, success, failed)) + await m.delete() + + + +async def grp_copy_msgs(br_msg, chat_id): + try: + h = await br_msg.copy(chat_id) + try: + await h.pin() + except: + pass + except FloodWait as e: + await asyncio.sleep(e.value) + await copy_msgs(br_msg, chat_id) + except Exception as e: + await delete_group(chat_id) + return False + + +async def copy_msgs(br_msg, chat_id): + try: + await br_msg.copy(chat_id) + except FloodWait as e: + await asyncio.sleep(e.value) + await copy_msgs(br_msg, chat_id) + except Exception as e: + await delete_user(chat_id) + return False