Spaces:
Running
Running
Delete chatbot/plugins/join_request
Browse files- chatbot/plugins/join_request +0 -132
chatbot/plugins/join_request
DELETED
@@ -1,132 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import time
|
3 |
-
import json
|
4 |
-
import asyncio
|
5 |
-
import io
|
6 |
-
import os
|
7 |
-
import re
|
8 |
-
import logging
|
9 |
-
import string
|
10 |
-
import random
|
11 |
-
from pyrogram import *
|
12 |
-
from pyrogram.types import *
|
13 |
-
from pyrogram.errors import *
|
14 |
-
from database import db
|
15 |
-
from logger import LOGS
|
16 |
-
|
17 |
-
from pyrogram import Client, filters
|
18 |
-
from pyrogram.enums import ChatMemberStatus, ChatMembersFilter, ChatType
|
19 |
-
from pyrogram.types import (
|
20 |
-
CallbackQuery,
|
21 |
-
InlineKeyboardMarkup,
|
22 |
-
InlineKeyboardButton,
|
23 |
-
Message
|
24 |
-
)
|
25 |
-
|
26 |
-
from PIL import Image, ImageDraw, ImageFont
|
27 |
-
|
28 |
-
logging.basicConfig(level=logging.INFO)
|
29 |
-
logger = logging.getLogger(__name__)
|
30 |
-
|
31 |
-
user_list = []
|
32 |
-
captcha_texts = {}
|
33 |
-
|
34 |
-
def generate_captcha():
|
35 |
-
letters = string.ascii_uppercase + string.digits
|
36 |
-
captcha_text = ''.join(random.choice(letters) for _ in range(5))
|
37 |
-
img = Image.new('RGB', (150, 60), color = (255, 255, 255))
|
38 |
-
d = ImageDraw.Draw(img)
|
39 |
-
try:
|
40 |
-
font = ImageFont.truetype("arial.ttf", 40)
|
41 |
-
except IOError:
|
42 |
-
font = ImageFont.load_default()
|
43 |
-
d.text((10,10), captcha_text, font=font, fill=(0,0,0))
|
44 |
-
img_path = f"captcha_{captcha_text}.png"
|
45 |
-
img.save(img_path)
|
46 |
-
return captcha_text, img_path
|
47 |
-
|
48 |
-
@Client.on_chat_join_request(filters.chat("KillerXSupport"))
|
49 |
-
async def join_request(client: Client, event: ChatJoinRequest):
|
50 |
-
member = await client.get_chat_member(event.chat.id, "me")
|
51 |
-
if member.status != ChatMemberStatus.ADMINISTRATOR:
|
52 |
-
return await client.send_message(event.chat.id, text="I am not an administrator in this group.")
|
53 |
-
async for m in client.get_chat_members(event.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
|
54 |
-
if not m.user.is_bot:
|
55 |
-
user_list.append(m.user.id)
|
56 |
-
captcha_text, img_path = generate_captcha()
|
57 |
-
captcha_texts[event.from_user.id] = captcha_text
|
58 |
-
captcha_texts["chat_id"] = event.chat.id
|
59 |
-
keyboard = InlineKeyboardMarkup(
|
60 |
-
[
|
61 |
-
[InlineKeyboardButton("π Refresh CAPTCHA", callback_data="refresh_captcha")],
|
62 |
-
[InlineKeyboardButton("β
Verify", callback_data="verify_captcha")]
|
63 |
-
]
|
64 |
-
)
|
65 |
-
if event.chat.type == ChatType.SUPERGROUP:
|
66 |
-
try:
|
67 |
-
await client.send_photo(
|
68 |
-
event.from_user.id,
|
69 |
-
photo=img_path,
|
70 |
-
caption=f"βοΈ **Verify that you are human!**\n\nβ Please enter the CAPTCHA text below the image.",
|
71 |
-
reply_markup=keyboard
|
72 |
-
)
|
73 |
-
os.remove(img_path)
|
74 |
-
except Exception as e:
|
75 |
-
await client.send_message(
|
76 |
-
event.chat.id,
|
77 |
-
text=str(e)
|
78 |
-
)
|
79 |
-
logger.error(str(e))
|
80 |
-
|
81 |
-
@Client.on_callback_query(filters.regex("^refresh_captcha$"))
|
82 |
-
async def refresh_captcha_callback(client: Client, cb: CallbackQuery):
|
83 |
-
user_id = cb.from_user.id
|
84 |
-
if user_id in captcha_texts:
|
85 |
-
del captcha_texts[user_id]
|
86 |
-
captcha_text, img_path = generate_captcha()
|
87 |
-
captcha_texts[user_id] = captcha_text
|
88 |
-
keyboard = InlineKeyboardMarkup(
|
89 |
-
[
|
90 |
-
[InlineKeyboardButton("π Refresh CAPTCHA", callback_data="refresh_captcha")],
|
91 |
-
[InlineKeyboardButton("β
Verify", callback_data="verify_captcha")]
|
92 |
-
]
|
93 |
-
)
|
94 |
-
await cb.edit_message_media(
|
95 |
-
media=InputMediaPhoto(img_path),
|
96 |
-
reply_markup=keyboard
|
97 |
-
)
|
98 |
-
os.remove(img_path)
|
99 |
-
await cb.answer("CAPTCHA refreshed!", show_alert=False)
|
100 |
-
|
101 |
-
@Client.on_callback_query(filters.regex("^verify_captcha$"))
|
102 |
-
async def verify_captcha_callback(client: Client, cb: CallbackQuery):
|
103 |
-
user_id = cb.from_user.id
|
104 |
-
if user_id not in captcha_texts:
|
105 |
-
await cb.answer("βοΈ Please start the CAPTCHA verification first by join request.", show_alert=True)
|
106 |
-
return
|
107 |
-
await cb.message.reply_text("π **Please enter the CAPTCHA text:**")
|
108 |
-
await cb.answer()
|
109 |
-
|
110 |
-
@Client.on_message(filters.text & filters.private)
|
111 |
-
async def handle_captcha_response(client: Client, message: Message):
|
112 |
-
user_id = message.from_user.id
|
113 |
-
user_response = message.text.strip().upper()
|
114 |
-
if user_id not in captcha_texts:
|
115 |
-
return
|
116 |
-
correct_captcha = captcha_texts.get(user_id)
|
117 |
-
if user_response == correct_captcha:
|
118 |
-
await message.reply("β
CAPTCHA verification successful!")
|
119 |
-
await client.approve_chat_join_request(
|
120 |
-
chat_id=captcha_texts.get("chat_id"),
|
121 |
-
user_id=user_id
|
122 |
-
)
|
123 |
-
del captcha_texts[user_id]
|
124 |
-
del captcha_texts["chat_id"]
|
125 |
-
else:
|
126 |
-
await message.reply("β Incorrect CAPTCHA. Please try again by join request again.")
|
127 |
-
await client.decline_chat_join_request(
|
128 |
-
chat_id=captcha_texts.get("chat_id"),
|
129 |
-
user_id=user_id
|
130 |
-
)
|
131 |
-
del captcha_texts[user_id]
|
132 |
-
del captcha_texts["chat_id"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|