예제 #1
0
 def test_board_when_game_is_running(self):
     game = Game(-999, 12345)
     game.board = Board(5, game)
     GamesController.games[-999] = game
     self.updater.dispatcher.add_handler(
         CommandHandler("board", command_board))
     self.updater.start_polling()
     chat = self.cg.get_chat(cid=-999)
     update = self.mg.get_message(chat=chat, text="/board")
     self.bot.insertUpdate(update)
     self.assertEqual(len(self.bot.sent_messages), 1)
     sent = self.bot.sent_messages[0]
     self.assertEqual(sent['method'], "sendMessage")
     self.assertIn("--- Liberal acts ---", sent['text'])
     self.updater.stop()
예제 #2
0
def callback_finish_game_buttons(bot, update):
    callback = update.callback_query
    try:
        #log.info('callback_finish_game_buttons called: %s' % callback.data)
        regex = re.search("(-[0-9]*)\*chooseend\*(.*)\*([0-9]*)",
                          callback.data)
        cid, strcid, opcion, uid, struid = int(
            regex.group(1)), regex.group(1), regex.group(2), int(
                regex.group(3)), regex.group(3)
        mensaje_edit = "Has elegido el diccionario: {0}".format(opcion)
        try:
            bot.edit_message_text(mensaje_edit, cid,
                                  callback.message.message_id)
        except Exception as e:
            bot.edit_message_text(mensaje_edit, uid,
                                  callback.message.message_id)
        game = Commands.get_game(cid)

        # Obtengo el diccionario actual, primero casos no tendre el config y pondre el community
        try:
            dicc = game.configs.get('diccionario', 'community')
        except Exception as e:
            dicc = 'community'

        # Obtengo datos de juego anterior
        groupName = game.groupName
        tipojuego = game.tipo
        modo = game.modo
        descarte = game.board.discards
        # Dependiendo de la opcion veo que como lo inicio
        players = game.playerlist.copy()
        # Creo nuevo juego
        game = Game(cid, uid, groupName, tipojuego, modo)
        GamesController.games[cid] = game
        # Guarda los descartes en configs para asi puedo recuperarlos
        game.configs['discards'] = descarte
        if opcion == "Nuevo":
            bot.send_message(
                cid,
                "Cada jugador puede unirse al juego con el comando /join.\nEl iniciador del juego (o el administrador) pueden unirse tambien y escribir /startgame cuando todos se hayan unido al juego!"
            )
            return
        #log.info('Llego hasta la creacion')
        game.playerlist = players
        # StartGame
        player_number = len(game.playerlist)
        game.board = Board(player_number, game)
        game.player_sequence = []
        game.shuffle_player_sequence()

        if opcion == "Mismo Diccionario":
            #(Beta) Nuevo Partido, mismos jugadores, mismo diccionario
            #log.info('Llego hasta el new2')
            game.configs['diccionario'] = dicc
            finish_config(bot, game, dicc)
        if opcion == "Otro Diccionario":
            #(Beta) Nuevo Partido, mismos jugadores, diferente diccionario
            call_dicc_buttons(bot, game)
    except Exception as e:
        bot.send_message(ADMIN[0],
                         'No se ejecuto el comando debido a: ' + str(e))
        bot.send_message(ADMIN[0], callback.data)