Spaces:
Running
Running
File size: 4,550 Bytes
ec03066 3547fa0 ec03066 44feb26 ec03066 3547fa0 bf800b1 7d60737 bf800b1 7d60737 bf800b1 7d60737 bf800b1 7d60737 bf800b1 7d60737 ec03066 0147678 bf800b1 67d1535 42717ba 810422d 7d60737 42717ba 7d60737 42717ba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
#!/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 <https://www.gnu.org/licenses/>.
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_messagr(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)) |