randydev commited on
Commit
1ff2d48
Β·
verified Β·
1 Parent(s): 0ed11be

Upload join_request.py

Browse files
Files changed (1) hide show
  1. chatbot/plugins/join_request.py +26 -13
chatbot/plugins/join_request.py CHANGED
@@ -91,7 +91,6 @@ def generate_captcha_multiple_choice():
91
  d.line([start, end], fill=line_color, width=2)
92
 
93
  img = img.filter(ImageFilter.BLUR)
94
-
95
  img_path = f"captcha_{captcha_text}.png"
96
  img.save(img_path)
97
  return captcha_text, img_path, choices
@@ -104,10 +103,15 @@ async def join_request(client: Client, event: ChatJoinRequest):
104
  async for m in client.get_chat_members(event.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
105
  if not m.user.is_bot:
106
  user_list.append(m.user.id)
 
 
 
 
 
107
  captcha_text, img_path, choices = generate_captcha_multiple_choice()
108
  captcha_texts[event.from_user.id] = captcha_text
109
  captcha_texts["chat_id"] = event.chat.id
110
- captcha_texts["chat_username"] = event.chat.username
111
  keyboard = InlineKeyboardMarkup(
112
  [
113
  [InlineKeyboardButton(choice, callback_data=f"verify_{event.from_user.id}_{choice}")]
@@ -119,6 +123,11 @@ async def join_request(client: Client, event: ChatJoinRequest):
119
  )
120
  if event.chat.type == ChatType.SUPERGROUP:
121
  try:
 
 
 
 
 
122
  await client.send_photo(
123
  event.from_user.id,
124
  photo=img_path,
@@ -152,14 +161,22 @@ async def cancel_captcha_callback(client: Client, cb: CallbackQuery):
152
  async def close_final(client: Client, cb: CallbackQuery):
153
  await cb.message.delete()
154
 
155
- def create_button_join_group(username):
156
  return InlineKeyboardMarkup(
157
  [
 
158
  [InlineKeyboardButton("πŸ”˜ Close", callback_data="close")],
159
- [InlineKeyboardButton("πŸ‘οΈ Join chat", url=f"https://t.me/{username}")],
160
  ]
161
  )
162
 
 
 
 
 
 
 
 
 
163
  @Client.on_callback_query(filters.regex("^refresh_captcha$"))
164
  async def refresh_captcha_callback(client: Client, cb: CallbackQuery):
165
  user_id = cb.from_user.id
@@ -198,10 +215,8 @@ async def verify_captcha_multiple_choice_callback(client: Client, cb: CallbackQu
198
  return
199
  if user_id not in captcha_texts:
200
  await cb.answer("❗️ Please start the CAPTCHA verification first.", show_alert=True)
201
- logger.warning(f"User {user_id} attempted to verify CAPTCHA without starting verification.")
202
  return
203
- correct_captcha = captcha_texts.get(user_id)
204
- logger.info(f"User {user_id} selected CAPTCHA: {user_choice} (Expected: {correct_captcha})")
205
  if user_choice == correct_captcha:
206
  hacker_image = thanks_hacker_by_randydev()
207
  await cb.edit_message_media(
@@ -209,7 +224,7 @@ async def verify_captcha_multiple_choice_callback(client: Client, cb: CallbackQu
209
  hacker_image,
210
  caption="βœ… CAPTCHA verification successful!"
211
  ),
212
- reply_markup=create_button_join_group(captcha_texts.get("chat_username"))
213
  )
214
  logger.info(f"User {user_id} successfully verified CAPTCHA.")
215
  await client.approve_chat_join_request(
@@ -218,25 +233,23 @@ async def verify_captcha_multiple_choice_callback(client: Client, cb: CallbackQu
218
  )
219
  del captcha_texts[user_id]
220
  del captcha_texts["chat_id"]
221
- del captcha_texts["chat_username"]
222
  else:
223
  await cb.edit_message_text("❌ Incorrect CAPTCHA. Please try again")
224
- logger.info(f"User {user_id} failed CAPTCHA verification.")
225
  await client.decline_chat_join_request(
226
  chat_id=captcha_texts.get("chat_id"),
227
  user_id=user_id
228
  )
229
  del captcha_texts[user_id]
230
  del captcha_texts["chat_id"]
231
- del captcha_texts["chat_username"]
232
 
233
  @Client.on_callback_query(filters.regex("^verify_captcha$"))
234
  async def verify_captcha_callback(client: Client, cb: CallbackQuery):
235
  user_id = cb.from_user.id
236
  if user_id not in captcha_texts:
237
  await cb.answer("❗️ Please start the CAPTCHA verification first", show_alert=True)
238
- logger.warning(f"User {user_id} attempted to verify CAPTCHA without starting verification.")
239
  return
240
  await cb.message.reply_text("πŸ” **Please enter the CAPTCHA text exactly as shown in the image:**")
241
  await cb.answer()
242
- logger.info(f"User {user_id} is attempting to verify CAPTCHA.")
 
91
  d.line([start, end], fill=line_color, width=2)
92
 
93
  img = img.filter(ImageFilter.BLUR)
 
94
  img_path = f"captcha_{captcha_text}.png"
95
  img.save(img_path)
96
  return captcha_text, img_path, choices
 
103
  async for m in client.get_chat_members(event.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
104
  if not m.user.is_bot:
105
  user_list.append(m.user.id)
106
+ try:
107
+ chat_link = await client.export_chat_invite_link(event.chat.id)
108
+ except ChatAdminRequired:
109
+ await client.send_message(event.chat.id, text="I need to be an administrator to perform this action.")
110
+ return
111
  captcha_text, img_path, choices = generate_captcha_multiple_choice()
112
  captcha_texts[event.from_user.id] = captcha_text
113
  captcha_texts["chat_id"] = event.chat.id
114
+ captcha_texts["chat_link"] = chat_link
115
  keyboard = InlineKeyboardMarkup(
116
  [
117
  [InlineKeyboardButton(choice, callback_data=f"verify_{event.from_user.id}_{choice}")]
 
123
  )
124
  if event.chat.type == ChatType.SUPERGROUP:
125
  try:
126
+ await client.send_message(
127
+ event.chat.id,
128
+ text=f" πŸ•¦ Verify that you {event.from_user.first_name} are human!",
129
+ reply_markup=create_button_userinfo(event.from_user.id, client.me.username)
130
+ )
131
  await client.send_photo(
132
  event.from_user.id,
133
  photo=img_path,
 
161
  async def close_final(client: Client, cb: CallbackQuery):
162
  await cb.message.delete()
163
 
164
+ def create_button_join_group(chat_link):
165
  return InlineKeyboardMarkup(
166
  [
167
+ [InlineKeyboardButton("πŸ‘οΈ Join chat", url=chat_link")],
168
  [InlineKeyboardButton("πŸ”˜ Close", callback_data="close")],
 
169
  ]
170
  )
171
 
172
+ def create_button_userinfo(user_id, username):
173
+ return InlineKeyboardMarkup(
174
+ [
175
+ [InlineKeyboardButton("πŸ‘€ Chmod +W $USER", url=f"tg://user?id={user_id}")],
176
+ [InlineKeyboardButton("πŸ”” Check human Bot", url=f"https://t.me/{username}")],
177
+ ]
178
+ )
179
+
180
  @Client.on_callback_query(filters.regex("^refresh_captcha$"))
181
  async def refresh_captcha_callback(client: Client, cb: CallbackQuery):
182
  user_id = cb.from_user.id
 
215
  return
216
  if user_id not in captcha_texts:
217
  await cb.answer("❗️ Please start the CAPTCHA verification first.", show_alert=True)
 
218
  return
219
+ correct_captcha = captcha_texts.get(user_id?
 
220
  if user_choice == correct_captcha:
221
  hacker_image = thanks_hacker_by_randydev()
222
  await cb.edit_message_media(
 
224
  hacker_image,
225
  caption="βœ… CAPTCHA verification successful!"
226
  ),
227
+ reply_markup=create_button_join_group(captcha_texts.get("chat_link"))
228
  )
229
  logger.info(f"User {user_id} successfully verified CAPTCHA.")
230
  await client.approve_chat_join_request(
 
233
  )
234
  del captcha_texts[user_id]
235
  del captcha_texts["chat_id"]
236
+ del captcha_texts["chat_link"]
237
  else:
238
  await cb.edit_message_text("❌ Incorrect CAPTCHA. Please try again")
 
239
  await client.decline_chat_join_request(
240
  chat_id=captcha_texts.get("chat_id"),
241
  user_id=user_id
242
  )
243
  del captcha_texts[user_id]
244
  del captcha_texts["chat_id"]
245
+ del captcha_texts["chat_link"]
246
 
247
  @Client.on_callback_query(filters.regex("^verify_captcha$"))
248
  async def verify_captcha_callback(client: Client, cb: CallbackQuery):
249
  user_id = cb.from_user.id
250
  if user_id not in captcha_texts:
251
  await cb.answer("❗️ Please start the CAPTCHA verification first", show_alert=True)
 
252
  return
253
  await cb.message.reply_text("πŸ” **Please enter the CAPTCHA text exactly as shown in the image:**")
254
  await cb.answer()
255
+ logger.info(f"User {user_id} is attempting to verify CAPTCHA.")