15
15
16
16
import asyncio
17
17
import re
18
+
19
+ from akipy .async_akipy import Akinator , akipyLOGS
18
20
from telethon .errors .rpcerrorlist import BotMethodInvalidError
19
21
from 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
+
22
24
from pyUltroid ._misc ._decorators import ultroid_cmd
23
25
from pyUltroid .fns .helper import inline_mention
24
26
from pyUltroid .fns .tools import async_searcher
27
+
25
28
from . import * # Ensure this import matches your project structure
26
- from akipy .async_akipy import Akinator
27
29
28
30
games = {}
29
31
aki_photo = "https://graph.org/file/3cc8825c029fd0cab9edc.jpg"
30
32
33
+
31
34
@ultroid_cmd (pattern = "akinator" )
32
35
async def akina (e ):
33
36
sta = Akinator ()
@@ -36,23 +39,26 @@ async def akina(e):
36
39
try :
37
40
m = await e .client .inline_query (asst .me .username , f"aki_{ e .chat_id } _{ e .id } " )
38
41
await m [0 ].click (e .chat_id )
42
+ akipyLOGS .info (f"Clicked inline result for chat { e .chat_id } " )
39
43
except BotMethodInvalidError as err :
40
- LOGS .error (f"BotMethodInvalidError: { err } " )
44
+ akipyLOGS .error (f"BotMethodInvalidError: { err } " )
41
45
await asst .send_file (
42
46
e .chat_id ,
43
47
aki_photo ,
44
48
buttons = Button .inline (get_string ("aki_2" ), data = f"aki_{ e .chat_id } _{ e .id } " ),
45
49
)
46
50
except Exception as er :
47
- LOGS .error (f"Unexpected error: { er } " )
51
+ akipyLOGS .error (f"Unexpected error: { er } " )
48
52
return await e .eor (f"ERROR : { er } " )
49
53
if e .out :
50
54
await e .delete ()
51
55
56
+
52
57
@asst_cmd (pattern = "akinator" , owner = True )
53
58
async def _akokk (e ):
54
59
await akina (e )
55
60
61
+
56
62
@callback (re .compile ("aki_(.*)" ), owner = True )
57
63
async def doai (e ):
58
64
adt = e .pattern_match .group (1 ).strip ().decode ("utf-8" )
@@ -61,22 +67,23 @@ async def doai(e):
61
67
mid = int (dt [1 ])
62
68
await e .edit (get_string ("com_1" ))
63
69
try :
64
- await games [ch ][mid ].start_game (child_mode = True )
70
+ await games [ch ][mid ].start_game (child_mode = False )
65
71
bts = [Button .inline (o , f"aka_{ adt } _{ o } " ) for o in ["Yes" , "No" , "Idk" ]]
66
72
cts = [Button .inline (o , f"aka_{ adt } _{ o } " ) for o in ["Probably" , "Probably Not" ]]
67
73
bts = [bts , cts ]
68
74
await e .edit (f"Q. { games [ch ][mid ].question } " , buttons = bts )
69
75
except KeyError :
70
76
return await e .answer (get_string ("aki_1" ), alert = True )
71
77
78
+
72
79
@callback (re .compile ("aka_(.*)" ), owner = True )
73
80
async def okah (e ):
74
81
try :
75
82
mk = e .pattern_match .group (1 ).decode ("utf-8" ).split ("_" )
76
- LOGS .info (f"Parsed values: { mk } " )
83
+ #akipyLOGS .info(f"Parsed values: {mk}")
77
84
78
85
if len (mk ) < 3 :
79
- LOGS .error ("Pattern match did not return enough parts." )
86
+ akipyLOGS .error ("Pattern match did not return enough parts." )
80
87
return await e .answer ("Invalid data received." , alert = True )
81
88
82
89
ch = int (mk [0 ])
@@ -86,27 +93,23 @@ async def okah(e):
86
93
gm = games [ch ][mid ]
87
94
await gm .answer (ans )
88
95
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 :
93
98
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 } "
98
100
await e .edit (text , file = gm .photo )
99
101
else :
102
+ # Game is not won yet, continue asking questions
100
103
buttons = [
101
104
[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" ]],
103
106
]
104
107
await e .edit (gm .question , buttons = buttons )
105
108
106
109
except KeyError :
107
110
await e .answer (get_string ("aki_3" ))
108
111
except Exception as ex :
109
- LOGS .error (f"An unexpected error occurred: { ex } " )
112
+ akipyLOGS .error (f"An unexpected error occurred: { ex } " )
110
113
111
114
112
115
@in_pattern (re .compile ("aki_?(.*)" ), owner = True )
0 commit comments