Skip to content

Commit 2e967b0

Browse files
committed
Added Back Button and fixed the TotalQuestions Database logical error.
1 parent 8aff516 commit 2e967b0

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

__main__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os import cpu_count
1+
from os import cpu_count, terminal_size
22
import akinator
33
from telegram.files.inputmedia import InputMediaPhoto
44
from random import randint
@@ -8,7 +8,7 @@
88
from telegram.ext import Updater, CommandHandler, CallbackContext, CallbackQueryHandler
99
from config import BOT_TOKEN
1010
from database import addUser, getChildMode, getCorrectGuess, getLanguage, getTotalGuess, getTotalQuestions, getUnfinishedGuess, getUser, getWrongGuess, totalUsers, updateChildMode, updateCorrectGuess, updateLanguage, updateTotalGuess, updateTotalQuestions, updateWrongGuess
11-
from strings import AKI_LANG_CODE, AKI_LANG_MSG, CHILDMODE_MSG, ME_MSG, START_MSG
11+
from strings import AKI_FIRST_QUESTION, AKI_LANG_CODE, AKI_LANG_MSG, CHILDMODE_MSG, ME_MSG, START_MSG
1212
import akinator
1313

1414

@@ -53,11 +53,18 @@ def aki_play_callback_handler(update: Update, context:CallbackContext) -> None:
5353
user_id = update.effective_user.id
5454
aki = context.user_data[f"aki_{user_id}"]
5555
q = context.user_data[f"q_{user_id}"]
56-
updateTotalQuestions(user_id, context.user_data[f"ques_{user_id}"])
57-
context.user_data[f"ques_{user_id}"] = context.user_data[f"ques_{user_id}"] + 1
56+
updateTotalQuestions(user_id, 1)
5857
query = update.callback_query
5958
a = query.data.split('_')[-1]
60-
q = aki.answer(a)
59+
if a == '5':
60+
updateTotalQuestions(user_id, -1)
61+
try:
62+
q = aki.back()
63+
except akinator.exceptions.CantGoBackAnyFurther:
64+
query.answer(text=AKI_FIRST_QUESTION, show_alert=True)
65+
return
66+
else:
67+
q = aki.answer(a)
6168
query.answer()
6269
if aki.progression < 80:
6370
query.message.edit_media(
@@ -167,7 +174,6 @@ def aki_set_child_mode(update: Update, context: CallbackContext) -> None:
167174
def del_data(context:CallbackContext, user_id: int):
168175
del context.user_data[f"aki_{user_id}"]
169176
del context.user_data[f"q_{user_id}"]
170-
del context.user_data[f"ques_{user_id}"]
171177

172178
def main():
173179
updater = Updater(token=BOT_TOKEN)

database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,6 @@ def updateTotalQuestions(user_id: int, total_questions: int) -> None:
163163
"""
164164
165165
"""
166+
total_questions = total_questions+ getTotalQuestions(user_id)
166167
my_db["users"].update_one({"user_id": user_id}, {"$set": {"total_questions": total_questions}})
167168

keyboard.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
[
6363
InlineKeyboardButton("I don't know", callback_data='aki_play_2'),
6464
InlineKeyboardButton("Probably Not", callback_data='aki_play_4')
65+
],
66+
[ InlineKeyboardButton("Back", callback_data= 'aki_play_5')
6567
]
6668
]
6769
)

strings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@
4949
CHILDMODE_MSG = """
5050
If Child mode is enabled, akinator won't show any NSFW content.
5151
<b>Current Status :</b> <pre>Child mode is {} !</pre>
52-
"""
52+
"""
53+
54+
AKI_FIRST_QUESTION = "This is the first question. You can't go back any further!"

0 commit comments

Comments
 (0)