#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2020-2024 (c) Randy W @xtdevs, @xtsea # # from : https://github.com/TeamKillerX # Channel : @RendyProjects # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import time import json import asyncio import io import os import re import logging from pyrogram import * from pyrogram.enums import ChatMemberStatus, ChatMembersFilter, ChatType from pyrogram import Client, filters from pyrogram.types import * from pyrogram.errors import * from database import db from logger import LOGS logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) user_list = [] @Client.on_callback_query(filters.regex("^joinrequest_")) async def joinrequest_callback(client: Client, cb: CallbackQuery): data = cb.data.split("_") if len(data) != 2: await cb.answer("Invalid data format.", True) return try: user_id = int(data[1]) except ValueError: await cb.answer("Invalid user ID.", True) return try: if cb.from_user.id in user_list: await client.approve_chat_join_request( chat_id=cb.message.chat.id, user_id=user_id, ) await cb.edit_message_text( f"User {user_id} joined the request in the group", disable_web_page_preview=True, ) else: await cb.answer("Only the Admins can perform this action.", True) except Exception as e: await cb.answer(f"Error: {e}", True) @Client.on_callback_query(filters.regex("^declinerequest_")) async def declinerequest_callback(client: Client, cb: CallbackQuery): data = cb.data.split("_") if len(data) != 2: await cb.answer("Invalid data format.", True) return try: user_id = int(data[1]) except ValueError: await cb.answer("Invalid user ID.", True) return try: if cb.from_user.id in user_list: await client.decline_chat_join_request( chat_id=cb.message.chat.id, user_id=user_id, ) await cb.edit_message_text( f"User {user_id} declined to join the support group", disable_web_page_preview=True, ) else: await cb.answer("Only the Admins can perform this action.", True) except Exception as e: await cb.answer(f"Error: {e}", True) def create_button_join_request(user_id): return InlineKeyboardMarkup( [ [ InlineKeyboardButton( text="✅ Approve", callback_data=f"joinrequest_{user_id}" ) ], [ InlineKeyboardButton( text="❌ Decline", callback_data=f"declinerequest_{user_id}" ) ] ] ) @Client.on_chat_join_request(filters.chat("KillerXSupport")) async def join_request(client: Client, event: ChatJoinRequest): member = await client.get_chat_member(event.chat.id, "me") if member.status != ChatMemberStatus.ADMINISTRATOR: return await client.send_message(event.chat.id, text="I am not an administrator in this group.") async for m in client.get_chat_members(event.chat.id, filter=ChatMembersFilter.ADMINISTRATORS): if not m.user.is_bot: user_list.append(m.user.id) if event.chat.type == ChatType.SUPERGROUP: try: user_request_text = f"UserID: {event.from_user.id} by admin soon" await client.send_message( event.chat.id, user_request_text, reply_markup=create_button_join_request(event.from_user.id) ) except Exception as e: await client.send_message( event.chat.id, text=str(e) ) logger.error(str(e))