def next_player(update, context): chat = update.effective_chat user = update.effective_user lang_id = Database().get_lang_id(chat.id) translator = Translator(lang_id=lang_id) game = GameStore().get_game(chat.id) try: if user.id != game.get_current_player().user_id: update.callback_query.answer(translator("mp_not_your_turn_callback").format(user.first_name)) return remove_inline_keyboard(update, context) game.next_player() except NoPlayersLeftException: # TODO merge messages update.effective_message.reply_text(translator("dealers_cards_are").format(game.dealer.cardvalue, get_cards_string(game.dealer, lang_id)), parse_mode=ParseMode.HTML) evaluation_string = generate_evaluation_string(game, lang_id) newgame_button = InlineKeyboardButton(text=translator("inline_keyboard_newgame"), callback_data="newgame") keyboard = InlineKeyboardMarkup(inline_keyboard=[[newgame_button]]) update.effective_message.reply_text(evaluation_string, reply_markup=keyboard) game.stop(-1) return players_turn(update, context)
def stop_cmd(update, context): """Stops a game for a specific user""" user = update.effective_user chat = update.effective_chat lang_id = Database().get_lang_id(chat.id) translator = Translator(lang_id=lang_id) game = GameStore().get_game(chat.id) try: game.stop(user.id) update.effective_message.reply_text(translator("game_ended")) except errors.InsufficientPermissionsException: update.effective_message.reply_text( translator("mp_only_creator_can_end"))
def stop_cmd(update, context): """Stops a game for a specific user""" user = update.effective_user chat = update.effective_chat lang_id = Database().get_lang_id(chat.id) translator = Translator(lang_id=lang_id) game = GameStore().get_game(chat.id) user_id = user.id try: if chat.type == "group" or chat.type == "supergroup": # If yes, get the chat admins admins = context.bot.get_chat_administrators(chat_id=chat.id) # if user.id in chat admin IDs, let them end the game with admin powers if user.id in [x.user.id for x in admins]: user_id = -1 game.stop(user_id) update.effective_message.reply_text(translator("game_ended")) except errors.InsufficientPermissionsException: update.effective_message.reply_text(translator("mp_only_creator_can_end"))