taslim19
Update waifu_name.py: use image hash matching for waifu name lookup
27bdbc9
raw
history blame
1.39 kB
from pyrogram import filters
from DragMusic import app
from DragMusic.core.userbot import Userbot
from PIL import Image
import imagehash
import io
WAIFU_CHANNEL_ID = "Grabber_Database" # Use channel username
async def get_waifu_name_by_image_hash(target_hash):
userbot = Userbot().one
async with userbot:
async for msg in userbot.get_chat_history(WAIFU_CHANNEL_ID):
if msg.photo:
file = await userbot.download_media(msg, in_memory=True)
img = Image.open(io.BytesIO(file.getvalue()))
waifu_hash = imagehash.average_hash(img)
if waifu_hash - target_hash < 3: # 0 is identical, <3 is very similar
return msg.caption
return None
@app.on_message(filters.command("waifus") & filters.reply)
async def waifus_name(client, message):
if not message.reply_to_message or not message.reply_to_message.photo:
return await message.reply("Reply to a waifu image to get the name!")
file = await message.reply_to_message.download(in_memory=True)
img = Image.open(io.BytesIO(file.getvalue()))
target_hash = imagehash.average_hash(img)
waifu_name = await get_waifu_name_by_image_hash(target_hash)
if waifu_name:
await message.reply(f"The waifu's name is: {waifu_name}")
else:
await message.reply("Waifu not found in the database channel!")