async def play_game(message): print("{} play game".format(message.chat.username)) user_data = UserData(message.chat.id) print(user_data.get_count_answers()) if user_data.get_count_answers() != 0: db_worker = SQLither(config.database_name) db_worker.insert_answer(message.chat.id, user_data.get_question_id(), message.text) db_worker.update_last_activity(message.chat.id, time.time()) db_worker.close() if user_data.get_count_answers() >= Questions.get_questions_limit(): markup = types.ReplyKeyboardMarkup(one_time_keyboard=False, resize_keyboard=True) markup.add(string_worker.get_yes_button()) markup.add(string_worker.get_no_button()) await send_message(message.chat.id, string_worker.get_ask_feedback(), reply_markup=markup) user_data.delete() return next_question_id = Questions.get_next_random_question_id(user_data.get_answers_id()) user_data.set_question_id(next_question_id) question_text = Questions.get_question(next_question_id) if Questions.is_time_to_praise(user_data.get_count_answers()): await send_message(message.chat.id, string_worker.get_praise(user_data.get_count_answers())) user_data.save() await send_message(message.chat.id, "<b>{}.</b> {}".format(user_data.get_count_answers(), question_text), parse_mode='HTML') if Questions.is_gif_time(user_data.get_count_answers()): await asyncio.sleep(10) await bot.send_chat_action(message.chat.id, 'upload_video') await asyncio.sleep(5) await bot.send_video(message.chat.id, config.pic_begin_game)
async def start(message: types.Message): print("{} has id {}".format(message.chat.username, message.chat.id)) # for question in Questions.questions: # await send_message(message.chat.id, question, parse_mode='HTML') if message.chat.id in config.admins: markup = types.ReplyKeyboardMarkup(one_time_keyboard=False, resize_keyboard=True) markup.add(string_worker.get_list_users_button()) # markup.add(string_worker.get_delete_data_button()) await send_message(message.chat.id, string_worker.get_instructions(), parse_mode='HTML', reply_markup=markup) return else: # user_data = UserData(message.chat.id) # user_data.delete() user_data = UserData(message.chat.id) user_data.set_is_active(True) user_data.save() db_worker = SQLither(config.database_name) if db_worker.is_user_exist(message.chat.id): await send_message(message.chat.id, string_worker.get_pass_one_time()) return else: db_worker.update_last_activity(message.chat.id, time.time()) db_worker.insert_user(message.chat.id, message.chat.first_name, message.chat.last_name, message.chat.username) db_worker.close() markup = types.ReplyKeyboardRemove() await send_message(message.chat.id, string_worker.get_hello(), parse_mode='HTML', reply_markup=markup) await asyncio.sleep(10) await bot.send_chat_action(message.chat.id, 'upload_video') await asyncio.sleep(5) await bot.send_video(message.chat.id, config.pic_begin_game) await asyncio.sleep(5) next_question_id = Questions.get_next_random_question_id( user_data.get_answers_id()) user_data.set_question_id(next_question_id) question_text = Questions.get_question(next_question_id) await send_message(message.chat.id, "<b>{}.</b> {}".format( user_data.get_count_answers(), question_text), parse_mode='HTML') user_data.set_is_active(False) user_data.save()