File size: 1,705 Bytes
8fd3066
 
dc00de0
8fd3066
 
 
dc00de0
8fd3066
 
 
 
 
 
 
dc00de0
 
 
 
 
8fd3066
 
 
 
 
 
 
 
 
 
13e24c7
8fd3066
 
 
 
 
13e24c7
 
8fd3066
13e24c7
8fd3066
13e24c7
8fd3066
 
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
34
35
36
37
38
39
40
41
42
43
import base64
import requests
import tempfile
from pyrogram import filters
from DragMusic import app

API_URL = "http://aizensolo.ru/getName"
API_TOKEN = "TEST-API-TOKEN"

@app.on_message(filters.command("whois") & filters.reply)
async def whois_character(client, message):
    if not message.reply_to_message or not (message.reply_to_message.photo or message.reply_to_message.document):
        return await message.reply("Reply to an image to identify the character.")

    # Use a temporary file for download
    with tempfile.NamedTemporaryFile(suffix=".jpg") as temp_file:
        await message.reply_to_message.download(file_name=temp_file.name)
        temp_file.seek(0)
        encoded_string = base64.b64encode(temp_file.read())

    data = {
        'api_token': API_TOKEN,
        'photo_b64': encoded_string.decode()
    }

    try:
        response = requests.post(API_URL, json=data, timeout=15)
        response.raise_for_status()
        result = response.json()
        if result.get("status") and all(k in result for k in ("name", "prefix", "bot_id", "bot_name")):
            reply_text = (
                f"Name: {result['name']}\n"
                f"Prefix: {result['prefix']}\n"
                f"Bot: [{result['bot_name']}](https://t.me/{result['bot_name']}) (`{result['bot_id']}`)"
            )
        elif not result.get("status"):
            reply_text = f"No character found. (API status: {result.get('status')})"
        else:
            reply_text = f"API returned unexpected data: {result}"
    except Exception as e:
        reply_text = f"API error: {e}\nRaw response: {response.text if 'response' in locals() else 'No response'}"

    await message.reply(reply_text)