File size: 1,393 Bytes
8a2b961
 
 
27bdbc9
 
 
8a2b961
27bdbc9
8a2b961
27bdbc9
8a2b961
 
 
27bdbc9
 
 
 
 
 
8a2b961
 
 
 
 
 
27bdbc9
 
 
 
8a2b961
 
 
 
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
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!")