From 35ca5e322a621d7ae6356add31f53367fd79fbf0 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Wed, 2 Feb 2022 17:17:21 +0700 Subject: [PATCH] some changes auto approve chat (let the userbot to enter the private chat with join request mode automatically) --- program/start.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/program/start.py b/program/start.py index d3e7bc9..f03c566 100644 --- a/program/start.py +++ b/program/start.py @@ -1,3 +1,6 @@ +import asyncio +import logging + from datetime import datetime from sys import version_info from time import time @@ -16,10 +19,10 @@ from driver.veez import user from driver.filters import command, other_filters from driver.database.dbchat import add_served_chat, is_served_chat from driver.database.dbpunish import is_gbanned_user -from pyrogram import Client, filters -from pyrogram import __version__ as pyrover +from pyrogram import Client, filters, __version__ as pyrover +from pyrogram.errors import FloodWait, MessageNotModified from pytgcalls import (__version__ as pytover) -from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message +from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message, ChatJoinRequest __major__ = 0 __minor__ = 2 @@ -39,6 +42,14 @@ TIME_DURATION_UNITS = ( ) +logging.getLogger("pyrogram").setLevel(logging.WARNING) +logging.basicConfig( + level=logging.INFO, + datefmt="[%d/%m/%Y %H:%M:%S]", + format=" %(asctime)s - [APPROVE-CHAT] >> %(levelname)s << %(message)s", + handlers=[logging.FileHandler("approvechat.log"), logging.StreamHandler()]) + + async def _human_time_duration(seconds): if seconds == 0: return "inf" @@ -144,6 +155,18 @@ async def get_uptime(client: Client, message: Message): ) +@Client.on_chat_join_request() +async def approve_join_chat(c: Client, m: ChatJoinRequest): + if not m.from_user: + return + try: + await c.approve_chat_join_request(m.chat.id, m.from_user.id) + except FloodWait as e: + logging.info(f"Sleeping for {e.x + 2} seconds due to floodwaits!") + await asyncio.sleep(e.x + 2) + await c.approve_chat_join_request(m.chat.id, m.from_user.id) + + @Client.on_message(filters.new_chat_members) async def new_chat(c: Client, m: Message): chat_id = m.chat.id