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