Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyrogram V2 + pillow V10 #7

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions helpers/captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ def make_captcha(id: str):
paste_image_list = list()
emoji_names = list()
supported_emojis = ['🃏', '🎤', '🎥', '🎨', '🎩', '🎬', '🎭', '🎮', '🎯', '🎱', '🎲', '🎷', '🎸', '🎹', '🎾', '🏀', '🏆', '🏈', '🏉', '🏐', '🏓', '💠', '💡', '💣', '💨', '💸', '💻', '💾', '💿', '📈', '📉', '📊', '📌', '📍', '📎', '📏', '📐', '📞', '📟', '📠', '📡', '📢', '📣', '📦', '📹', '📺', '📻', '📼', '📽', '🖥', '🖨', '🖲', '🗂', '🗃', '🗄', '🗜', '🗝', '🗡', '🚧', '🚨', '🛒', '🛠', '🛢', '🧀', '🌭', '🌮', '🌯', '🌺', '🌻', '🌼', '🌽', '🌾', '🌿', '🍊', '🍋', '🍌', '🍍', '🍎', '🍏', '🍚', '🍛', '🍜', '🍝', '🍞', '🍟', '🍪', '🍫', '🍬', '🍭', '🍮', '🍯', '🍺', '🍻', '🍼', '🍽', '🍾', '🍿', '🎊', '🎋', '🎍', '🎏', '🎚', '🎛', '🎞', '🐌', '🐍', '🐎', '🐚', '🐛', '🐝', '🐞', '🐟', '🐬', '🐭', '🐮', '🐯', '🐻', '🐼', '🐿', '👛', '👜', '👝', '👞', '👟', '💊', '💋', '💍', '💎', '🔋', '🔌', '🔪', '🔫', '🔬', '🔭', '🔮', '🕯', '🖊', '🖋', '🖌', '🖍', '🥚', '🥛', '🥜', '🥝', '🥞', '🦊', '🦋', '🦌', '🦍', '🦎', '🦏', '🌀', '🌂', '🌑', '🌕', '🌡', '🌤', '⛅️', '🌦', '🌧', '🌨', '🌩', '🌰', '🌱', '🌲', '🌳', '🌴', '🌵', '🌶', '🌷', '🌸', '🌹', '🍀', '🍁', '🍂', '🍃', '🍄', '🍅', '🍆', '🍇', '🍈', '🍉', '🍐', '🍑', '🍒', '🍓', '🍔', '🍕', '🍖', '🍗', '🍘', '🍙', '🍠', '🍡', '🍢', '🍣', '🍤', '🍥', '🍦', '🍧', '🍨', '🍩', '🍰', '🍱', '🍲', '🍴', '🍵', '🍶', '🍷', '🍸', '🍹', '🎀', '🎁', '🎂', '🎃', '🎄', '🎈', '🎉', '🎒', '🎓', '🎙', '🐀', '🐁', '🐂', '🐃', '🐄', '🐅', '🐆', '🐇', '🐕', '🐉', '🐓', '🐖', '🐗', '🐘', '🐙', '🐠', '🐡', '🐢', '🐣', '🐤', '🐥', '🐦', '🐧', '🐨', '🐩', '🐰', '🐱', '🐴', '🐵', '🐶', '🐷', '🐸', '🐹', '👁\u200d🗨', '👑', '👒', '👠', '👡', '👢', '💄', '💈', '🔗', '🔥', '🔦', '🔧', '🔨', '🔩', '🔰', '🔱', '🕰', '🕶', '🕹', '🖇', '🚀', '🤖', '🥀', '🥁', '🥂', '🥃', '🥐', '🥑', '🥒', '🥓', '🥔', '🥕', '🥖', '🥗', '🥘', '🥙', '🦀', '🦁', '🦂', '🦃', '🦄', '🦅', '🦆', '🦇', '🦈', '🦉', '🦐', '🦑', '⭐️', '⏰', '⏲', '⚠️', '⚡️', '⚰️', '⚽️', '⚾️', '⛄️', '⛅️', '⛈', '⛏', '⛓', '⌚️', '☎️', '⚜️', '✏️', '⌨️', '☁️', '☃️', '☄️', '☕️', '☘️', '☠️', '♨️', '⚒', '⚔️', '⚙️', '✈️', '✉️', '✒️']
r = random.random()
random.shuffle(supported_emojis, lambda: r)
r = random.random()
random.shuffle(supported_emojis, lambda: r)
random.shuffle(supported_emojis)
random.shuffle(supported_emojis)
for i in range(6):
emoji_names.append(supported_emojis[i])
paste_image_list.append(Image.open(f"helpers/assets/emojis/{emojis_index.get(f'{supported_emojis[i]}')}.png"))
position = [(20, 20), (180, 20), (310, 20), (20, 160), (180, 160), (310, 160)]
for i in range(len(paste_image_list)):
img = paste_image_list[i].rotate(random.randint(0, 360), resample=Image.BICUBIC, expand=True)
img.thumbnail((200, 200), Image.ANTIALIAS)
img.thumbnail((200, 200), Image.Resampling.LANCZOS)
background.paste(img, (position[i]), img)
background.save(f"helpers/cache/{id}.png", "PNG", quality=100)
captcha_answer = "Answer:"
Expand Down
6 changes: 3 additions & 3 deletions helpers/markup_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def make_captcha_markup(markup, __emoji, indicator):
__markup = markup
for i in markup:
for k in i:
if k["text"] == __emoji:
k["text"] = f"{indicator}"
k["callback_data"] = "HeHe"
if k.text == __emoji:
k.text = f"{indicator}"
k.callback_data = "HeHe"
return __markup
16 changes: 12 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import random
import logging
import aiohttp
import asyncio
from configs import Config
Expand All @@ -12,8 +13,14 @@
from helpers.markup_maker import make_captcha_markup
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message, CallbackQuery, ChatPermissions

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
handlers=[logging.StreamHandler(), logging.FileHandler("log.txt")],
)

CaptchaBot = Client(
session_name=Config.SESSION_NAME,
Config.SESSION_NAME,
api_id=Config.API_ID,
api_hash=Config.API_HASH,
bot_token=Config.BOT_TOKEN
Expand Down Expand Up @@ -146,7 +153,7 @@ async def buttons_handlers(bot: Client, cb: CallbackQuery):
reply_markup=InlineKeyboardMarkup(markup)
)
os.remove(emoji_path_)
CaptchaDB[cb.from_user.id]["message_id"] = __message.message_id
CaptchaDB[cb.from_user.id]["message_id"] = __message.id
await cb.message.delete(revoke=True)

elif cb.data.startswith("verify_"):
Expand All @@ -157,6 +164,7 @@ async def buttons_handlers(bot: Client, cb: CallbackQuery):
return
if cb.from_user.id not in CaptchaDB:
await cb.answer("Try Again After Re-Join!", show_alert=True)
await cb.message.delete()
if __emoji not in CaptchaDB.get(cb.from_user.id).get("emojis"):
CaptchaDB[cb.from_user.id]["mistakes"] += 1
await cb.answer("You pressed wrong emoji!", show_alert=True)
Expand All @@ -171,7 +179,7 @@ async def buttons_handlers(bot: Client, cb: CallbackQuery):
await asyncio.sleep(600)
del CaptchaDB[cb.from_user.id]
return
markup = make_captcha_markup(cb.message["reply_markup"]["inline_keyboard"], __emoji, "❌")
markup = make_captcha_markup(cb.message.reply_markup.inline_keyboard, __emoji, "❌")
await cb.message.edit_caption(
caption=f"{cb.from_user.mention}, select all the emojis you can see in the picture. "
f"You are allowed only ({n}) mistakes.",
Expand All @@ -180,7 +188,7 @@ async def buttons_handlers(bot: Client, cb: CallbackQuery):
return
else:
CaptchaDB.get(cb.from_user.id).get("emojis").remove(__emoji)
markup = make_captcha_markup(cb.message["reply_markup"]["inline_keyboard"], __emoji, "✅")
markup = make_captcha_markup(cb.message.reply_markup.inline_keyboard, __emoji, "✅")
await cb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(markup))
if not CaptchaDB.get(cb.from_user.id).get("emojis"):
await cb.answer("You Passed the Captcha!", show_alert=True)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Pyrogram==1.4.16
Pyrogram
TgCrypto
aiohttp
Pillow