1515
1616import asyncio
1717import re
18+
19+ from akipy .async_akipy import Akinator , akipyLOGS
1820from telethon .errors .rpcerrorlist import BotMethodInvalidError
1921from telethon .events import Raw
20- from telethon .tl .types import InputMediaPoll , Poll , PollAnswer , UpdateMessagePollVote , InputMessageID
21- from telethon . tl . functions . messages import GetMessagesRequest
22+ from telethon .tl .types import InputMediaPoll , Poll , PollAnswer , UpdateMessagePollVote
23+
2224from pyUltroid ._misc ._decorators import ultroid_cmd
2325from pyUltroid .fns .helper import inline_mention
2426from pyUltroid .fns .tools import async_searcher
27+
2528from . import * # Ensure this import matches your project structure
26- from akipy .async_akipy import Akinator
2729
2830games = {}
2931aki_photo = "https://graph.org/file/3cc8825c029fd0cab9edc.jpg"
3032
33+
3134@ultroid_cmd (pattern = "akinator" )
3235async def akina (e ):
3336 sta = Akinator ()
@@ -36,23 +39,26 @@ async def akina(e):
3639 try :
3740 m = await e .client .inline_query (asst .me .username , f"aki_{ e .chat_id } _{ e .id } " )
3841 await m [0 ].click (e .chat_id )
42+ akipyLOGS .info (f"Clicked inline result for chat { e .chat_id } " )
3943 except BotMethodInvalidError as err :
40- LOGS .error (f"BotMethodInvalidError: { err } " )
44+ akipyLOGS .error (f"BotMethodInvalidError: { err } " )
4145 await asst .send_file (
4246 e .chat_id ,
4347 aki_photo ,
4448 buttons = Button .inline (get_string ("aki_2" ), data = f"aki_{ e .chat_id } _{ e .id } " ),
4549 )
4650 except Exception as er :
47- LOGS .error (f"Unexpected error: { er } " )
51+ akipyLOGS .error (f"Unexpected error: { er } " )
4852 return await e .eor (f"ERROR : { er } " )
4953 if e .out :
5054 await e .delete ()
5155
56+
5257@asst_cmd (pattern = "akinator" , owner = True )
5358async def _akokk (e ):
5459 await akina (e )
5560
61+
5662@callback (re .compile ("aki_(.*)" ), owner = True )
5763async def doai (e ):
5864 adt = e .pattern_match .group (1 ).strip ().decode ("utf-8" )
@@ -61,22 +67,23 @@ async def doai(e):
6167 mid = int (dt [1 ])
6268 await e .edit (get_string ("com_1" ))
6369 try :
64- await games [ch ][mid ].start_game (child_mode = True )
70+ await games [ch ][mid ].start_game (child_mode = False )
6571 bts = [Button .inline (o , f"aka_{ adt } _{ o } " ) for o in ["Yes" , "No" , "Idk" ]]
6672 cts = [Button .inline (o , f"aka_{ adt } _{ o } " ) for o in ["Probably" , "Probably Not" ]]
6773 bts = [bts , cts ]
6874 await e .edit (f"Q. { games [ch ][mid ].question } " , buttons = bts )
6975 except KeyError :
7076 return await e .answer (get_string ("aki_1" ), alert = True )
7177
78+
7279@callback (re .compile ("aka_(.*)" ), owner = True )
7380async def okah (e ):
7481 try :
7582 mk = e .pattern_match .group (1 ).decode ("utf-8" ).split ("_" )
76- LOGS .info (f"Parsed values: { mk } " )
83+ #akipyLOGS .info(f"Parsed values: {mk}")
7784
7885 if len (mk ) < 3 :
79- LOGS .error ("Pattern match did not return enough parts." )
86+ akipyLOGS .error ("Pattern match did not return enough parts." )
8087 return await e .answer ("Invalid data received." , alert = True )
8188
8289 ch = int (mk [0 ])
@@ -86,27 +93,23 @@ async def okah(e):
8693 gm = games [ch ][mid ]
8794 await gm .answer (ans )
8895
89- if gm .progression is None :
90- gm .progression = 0
91-
92- if int (float (gm .progression )) >= 80 :
96+ # Check for the final guess in the API response
97+ if gm .name_proposition and gm .description_proposition :
9398 gm .win = True
94- if int (gm .step ) > 3 :
95- text = f"It's { gm .name_proposition } \n { gm .description_proposition } "
96- else :
97- text = f"Ha, You cant fool me!"
99+ text = f"It's { gm .name_proposition } \n { gm .description_proposition } "
98100 await e .edit (text , file = gm .photo )
99101 else :
102+ # Game is not won yet, continue asking questions
100103 buttons = [
101104 [Button .inline (o , f"aka_{ ch } _{ mid } _{ o } " ) for o in ["Yes" , "No" , "Idk" ]],
102- [Button .inline (o , f"aka_{ ch } _{ mid } _{ o } " ) for o in ["Probably" , "Probably Not" ]]
105+ [Button .inline (o , f"aka_{ ch } _{ mid } _{ o } " ) for o in ["Probably" , "Probably Not" ]],
103106 ]
104107 await e .edit (gm .question , buttons = buttons )
105108
106109 except KeyError :
107110 await e .answer (get_string ("aki_3" ))
108111 except Exception as ex :
109- LOGS .error (f"An unexpected error occurred: { ex } " )
112+ akipyLOGS .error (f"An unexpected error occurred: { ex } " )
110113
111114
112115@in_pattern (re .compile ("aki_?(.*)" ), owner = True )
0 commit comments