Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 94 additions & 19 deletions plugins/newgroup.py
Original file line number Diff line number Diff line change
@@ -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