|
1 | | -from os import cpu_count |
| 1 | +from os import cpu_count, terminal_size |
2 | 2 | import akinator |
3 | 3 | from telegram.files.inputmedia import InputMediaPhoto |
4 | 4 | from random import randint |
|
8 | 8 | from telegram.ext import Updater, CommandHandler, CallbackContext, CallbackQueryHandler |
9 | 9 | from config import BOT_TOKEN |
10 | 10 | 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 |
12 | 12 | import akinator |
13 | 13 |
|
14 | 14 |
|
@@ -53,11 +53,18 @@ def aki_play_callback_handler(update: Update, context:CallbackContext) -> None: |
53 | 53 | user_id = update.effective_user.id |
54 | 54 | aki = context.user_data[f"aki_{user_id}"] |
55 | 55 | 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) |
58 | 57 | query = update.callback_query |
59 | 58 | 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) |
61 | 68 | query.answer() |
62 | 69 | if aki.progression < 80: |
63 | 70 | query.message.edit_media( |
@@ -167,7 +174,6 @@ def aki_set_child_mode(update: Update, context: CallbackContext) -> None: |
167 | 174 | def del_data(context:CallbackContext, user_id: int): |
168 | 175 | del context.user_data[f"aki_{user_id}"] |
169 | 176 | del context.user_data[f"q_{user_id}"] |
170 | | - del context.user_data[f"ques_{user_id}"] |
171 | 177 |
|
172 | 178 | def main(): |
173 | 179 | updater = Updater(token=BOT_TOKEN) |
|
0 commit comments