def command_theme(m): cid = m.chat.id user = str(m.from_user.id) text = m.text exist = settings.settings_exist(cid) if exist: theme = text.split("/theme")[1].replace(" ", "") if not theme in THEMES: markup = types.ReplyKeyboardMarkup(row_width=2) for key in THEMES.keys(): markup.add("/theme " + key) current = game.get_info(cid)['theme'] bot.send_message(cid, "Choose one option:\n <b>Current: </b>" + current, reply_markup=markup, parse_mode="HTML", disable_notification=True) else: markup = types.ReplyKeyboardHide(selective=False) bot.send_message(cid, "Succesful!", reply_markup=markup, disable_notification=True) settings.update_settings(cid, theme=theme) playing = tools.game_exist(cid) if playing: game.update_info(cid, theme=theme) caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption, silent=True)
def command_engine(m): cid = m.chat.id user = str(m.from_user.id) text = m.text exist = settings.settings_exist(cid) playing = tools.game_exist(cid) if exist and (not playing): engine = text.split("/engine")[1].replace(" ", "") if not engine in ENGINES: markup = types.ReplyKeyboardMarkup(row_width=2) for key in ENGINES: markup.add("/engine " + key) current = settings.get_settings(cid)['engine'] bot.send_message(cid, "Choose one option:\n <b>Current: </b>" + current, reply_markup=markup, parse_mode="HTML", disable_notification=True) else: markup = types.ReplyKeyboardHide(selective=False) bot.send_message(cid, "Succesful!", reply_markup=markup, disable_notification=True) settings.update_settings(cid, engine=engine)
def command_white(m): cid = m.chat.id user = str(m.from_user.id) first_name = str(m.from_user.first_name) last_name = str(m.from_user.last_name) userMG.create_user(user, first_name, last_name) text = m.text exist = tools.game_exist(cid) if exist and not game.is_ready_info(cid): game_type = game.get_info(cid)['game_type'] if game_type == "0": uci = settings.get_settings(cid)['engine'] game.update_info(cid, white=user, black=uci, uci_white="0") firs_step(cid, bot) elif game_type == "1": players = [game.white(cid), game.black(cid)] if not user in players: if players[0] == "0": game.update_info(cid, white=user) if game.black(cid) != "0": firs_step(cid, bot) else: bot.send_message(cid, "Waiting for /black player...") else: bot.send_message( cid, "This color was already chosen.\nChoose /black...", disable_notification=True) else: bot.send_message(cid, "You've already chosen color.", disable_notification=True)
def command_fen(m): cid = m.chat.id user = str(m.from_user.id) exist = tools.game_exist(cid) if exist: fen = game.get_info(cid)['fen'] bot.send_message(cid, fen, disable_notification=True) else: bot.send_message(cid, "Type for /start a new game", disable_notification=True)
def command_board(m): cid = m.chat.id user = str(m.from_user.id) exist = tools.game_exist(cid) if exist: caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption, silent=True) else: bot.send_message(cid, "Type for /start a new game", disable_notification=True)
def command_stop(m): cid = m.chat.id user = str(m.from_user.id) exist = tools.game_exist(cid) if exist: if user in [game.white(cid), game.black(cid)]: tools.delete_game(cid) markup = types.ReplyKeyboardHide(selective=False) bot.send_message(cid, "End...\nType for /start a new game", disable_notification=True, reply_markup=markup) else: bot.send_message(cid, "You're not allowed to stop this game")
def command_flip(m): cid = m.chat.id user = str(m.from_user.id) exist = tools.game_exist(cid) if exist: flipped = game.get_info(cid)['flipped'] if flipped == "0": game.update_info(cid, flipped="1") else: game.update_info(cid, flipped="0") caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption, silent=True) else: bot.send_message(cid, "Type for /start a new game", disable_notification=True)
def command_play(m): cid = m.chat.id text = m.text exist = tools.game_exist(cid) if exist and text in ["/play vs computer", "/play vs human"]: playing_option = text.split("/play vs")[1].replace(" ", "") if playing_option == "computer": game.update_info(cid, game_type="0") if playing_option == "human": game.update_info(cid, game_type="1") markup = types.ReplyKeyboardMarkup(row_width=2) markup.add("/white", "/black") bot.send_message(cid, "Choose color:", reply_markup=markup, disable_notification=True)
def command_start(m): cid = m.chat.id exist = tools.game_exist(cid) if not exist: settings.create_settings(cid) game.create_info(cid) game.update_info(cid, theme=settings.get_settings(cid)['theme']) tools.create_pgn_buffer(cid) markup = types.ReplyKeyboardMarkup(row_width=2) markup.add("/play vs computer", "/play vs human") bot.send_message(cid, "Choose par:", reply_markup=markup, disable_notification=True) # tools.send_board_image(bot,cid) else: bot.send_message(cid, "There's a previous game", disable_notification=True) #Text
def play_move(m): # print m cid = m.chat.id user = str(m.from_user.id) move = m.text exist = tools.game_exist(cid) if exist and game.is_ready_info(cid): game_type = game.get_info(cid)['game_type'] if game_type == "0": legal_moves = tools.get_legal_moves(cid) if move in legal_moves: user_move = tools.make_allowed_user_move(cid, user, move) if user_move != "INCORRECT_TURN": engine_move = tools.make_engine_move(cid) if user_move != "FINISHED" or engine_move != "FINISHED": caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption) if tools.finished( chess.Board(game.get_info(cid)['fen'])): tools.delete_game(cid) bot.send_message( cid, "End...\nType for /start a new game", disable_notification=True) else: tools.delete_game(cid) bot.send_message( cid, "Game finished...\nType for /start a new game") elif game_type == "1": legal_moves = tools.get_legal_moves(cid) if move in legal_moves: user_move = tools.make_allowed_user_move(cid, user, move) if user_move != "FINISHED": if user_move != "INCORRECT_TURN": caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption) else: tools.delete_game(cid) bot.send_message( cid, "Game finished...\nType for /start a new game")