taslim19 commited on
Commit
8fd3066
·
1 Parent(s): 3c55597

Update whois.py: new API endpoint and message formatting

Browse files
Files changed (1) hide show
  1. DragMusic/plugins/games/whois.py +37 -0
DragMusic/plugins/games/whois.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import requests
3
+ from pyrogram import filters
4
+ from DragMusic import app
5
+
6
+ API_URL = "http://aizensolo.ru/"
7
+ API_TOKEN = "TEST-API-TOKEN"
8
+
9
+ @app.on_message(filters.command("whois") & filters.reply)
10
+ async def whois_character(client, message):
11
+ if not message.reply_to_message or not (message.reply_to_message.photo or message.reply_to_message.document):
12
+ return await message.reply("Reply to an image to identify the character.")
13
+
14
+ file = await message.reply_to_message.download(in_memory=True)
15
+ encoded_string = base64.b64encode(bytes(file.getbuffer()))
16
+
17
+ data = {
18
+ 'api_token': API_TOKEN,
19
+ 'photo_b64': encoded_string.decode()
20
+ }
21
+
22
+ try:
23
+ response = requests.post(API_URL, json=data, timeout=15)
24
+ response.raise_for_status()
25
+ result = response.json()
26
+ if result.get("status"):
27
+ reply_text = (
28
+ f"Name: {result['name']}\n"
29
+ f"Prefix: {result['prefix']}\n"
30
+ f"Bot: [{result['bot_name']}](https://t.me/{result['bot_name']}) (`{result['bot_id']}`)"
31
+ )
32
+ else:
33
+ reply_text = "No character found."
34
+ except Exception as e:
35
+ reply_text = f"API error: {e}"
36
+
37
+ await message.reply(reply_text)