Added pawn promotion and locales support!

This commit is contained in:
spla 2020-11-27 20:50:38 +01:00
parent 2d43565417
commit 8ec306c680
4 changed files with 360 additions and 121 deletions

48
locales/cat.txt Normal file
View file

@ -0,0 +1,48 @@
search_end: fi
search_move: mou
search_new: nova
search_games: jocs
search_send: envia
new_game_started: partida iniciada! Esperant jugador...
playing_with: jugues amb
your_turn: el teu torn
game_name: partida
chess_hashtag: #escacs
send_error: error al enviar les anotacions :-(
game_number_anotations: les anotacions de la partida n.
anotations_sent: enviades amb èxit!
game_no_exists: la partida n.
it_not_exists: no existeix...
game_already_started: ja tenies iniciada una partida!
wait_other_player: espera l'altre jugador
is_not_legal_move: és un moviment il·legal. Torna a tirar.
check_done: t'ha fet escac!
check_mate: Escac i mat! (en
check_mate_movements: moviments)
the_winner_is: El guanyador és:
well_done: ben jugat!
winned_games: Partides guanyades:
wins_of_many: de
lost_piece: * has perdut
not_legal_move_str: moviment il·legal!
player_leave_game: ha deixat la partida amb
leave_waiting_game: has abandonat la partida en espera.
started_games: partides iniciades:
game_is_waiting: en espera...
game_is_on_going: (en joc)
no_on_going_games: cap partida en joc
is_not_your_turn: no és el teu torn.
is_the_turn_of: és el torn de
pawn_piece: un peó
knight_piece: un cavall
bishop_piece: l'alfil
rook_piece: una torre
queen_piece: la Dama
king_piece: el Rei
pawn_piece_letter: P
knight_piece_letter: C
bishop_piece_letter: A
rook_piece_letter: T
queen_piece_letter: D
king_piece_letter: R
email_subject: Anotacions partida n.

48
locales/eng.txt Normal file
View file

@ -0,0 +1,48 @@
search_end: end
search_move: move
search_new: new
search_games: games
search_send: send
new_game_started: game started! Waiting for the second player...
playing_with: you play with
your_turn: it's your turn
game_name: game
chess_hashtag: #chess
send_error: sending anotations error :-(
game_number_anotations: the anotations of game n.
anotations_sent: succesfully sent!
game_no_exists: the game n.
it_not_exists: don't exists...
game_already_started: you already started a game!
wait_other_player: wait for the second player
is_not_legal_move: is not a legal move. Play again.
check_done: you are in check!
check_mate: it's a checkmate! (in
check_mate_movements: moves)
the_winner_is: The winner is:
well_done: well done!
winned_games: Won games:
wins_of_many: of
lost_piece: * you have lost
not_legal_move_str: not a legal move!
player_leave_game: has left the game with
leave_waiting_game: you have left the game in hold.
started_games: started games:
game_is_waiting: on hold...
game_is_on_going: (on going)
no_on_going_games: no games
is_not_your_turn: it's not your turn.
is_the_turn_of: it's the turn of
pawn_piece: a pawn
knight_piece: one knight
bishop_piece: one bishop
rook_piece: a rook
queen_piece: the Queen
king_piece: the King
pawn_piece_letter: P
knight_piece_letter: N
bishop_piece_letter: B
rook_piece_letter: R
queen_piece_letter: Q
king_piece_letter: K
email_subject: Anotations of game n.

View file

@ -101,27 +101,27 @@ def get_piece_name(captured_piece):
if captured_piece == 1:
piece_name = "un Peó"
piece_name = pawn_piece
if captured_piece == 2:
piece_name = "un cavall"
piece_name = knight_piece
if captured_piece == 3:
piece_name = "l'àlfil"
piece_name = bishop_piece
if captured_piece == 4:
piece_name = "una torre"
piece_name = rook_piece
if captured_piece == 5:
piece_name = "la Dama"
piece_name = queen_piece
if captured_piece == 6:
piece_name = "el Rei"
piece_name = king_piece
return piece_name
@ -129,27 +129,27 @@ def get_moved_piece_name(moved_piece):
if moved_piece == 1:
moved_piece_name = "P"
moved_piece_name = pawn_piece_letter
if moved_piece == 2:
moved_piece_name = "C"
moved_piece_name = knight_piece_letter
if moved_piece == 3:
moved_piece_name = "A"
moved_piece_name = bishop_piece_letter
if moved_piece == 4:
moved_piece_name = "T"
moved_piece_name = rook_piece_letter
if moved_piece == 5:
moved_piece_name = "D"
moved_piece_name = queen_piece_letter
if moved_piece == 6:
moved_piece_name = "R"
moved_piece_name = king_piece_letter
return moved_piece_name
@ -167,7 +167,7 @@ def get_notification_data():
url_lst = []
search_text = ['fi','mou','nova','jocs', 'envia']
search_text = [search_end, search_move, search_new, search_games, search_send]
conn = None
@ -511,13 +511,23 @@ def update_game(board_game, toot_url):
conn.close()
def save_annotation():
def save_anotation(moving):
square_index = chess.SQUARE_NAMES.index(moving[2:])
if moving_piece != 1:
moved_piece = board.piece_type_at(square_index)
square_index = chess.SQUARE_NAMES.index(moving[2:])
moved_piece_name = get_moved_piece_name(moved_piece)
moved_piece = board.piece_type_at(square_index)
moved_piece_name = get_moved_piece_name(moved_piece)
else:
moved_piece_name = 'P'
if promoted == True:
moving = moving + 'q'
game_file = "anotations/" + str(game_id) + ".txt"
@ -541,7 +551,13 @@ def save_annotation():
if check != True and checkmate != True:
line_data = str(board.fullmove_number) + ". " + moved_piece_name + moving[2:]
if promoted != True:
line_data = str(board.fullmove_number) + ". " + moved_piece_name + moving[2:]
else:
line_data = str(board.fullmove_number) + ". " + moved_piece_name + "=D"
else:
@ -553,15 +569,20 @@ def save_annotation():
if check != True and checkmate != True:
line_data = " - " + moved_piece_name + moving[2:] + "\n"
if promoted != True:
line_data = " - " + moved_piece_name + moving[2:] + "\n"
else:
line_data = " - " + moved_piece_name + "=D"
else:
line_data = " - " + moved_piece_name + "\n"
if not os.path.isfile(game_file):
file_header = "Partida: " + str(game_id) + "\n" + white_user + " / " + black_user + "\n\n"
file_header = game_name + ': ' + str(game_id) + "\n" + white_user + " / " + black_user + "\n\n"
with open(game_file, 'w+') as f:
@ -621,7 +642,7 @@ def send_anotation(game_id):
# Declare message elements
msg['From'] = smtp_user_login
msg['To'] = username_email
msg['Subject'] = "Anotaciones partida n." + game_id
msg['Subject'] = email_subject + game_id
# Attach the game anotation
file_to_attach = "anotations/" + game_id + ".txt"
@ -967,30 +988,30 @@ def replying():
if unidecode.unidecode(question)[0:query_word_length] == query_word:
if query_word[0:4] == 'nova':
if query_word == search_new:
reply = True
reply = True
elif query_word[0:3] == 'mou':
elif query_word[:search_move_slicing] == search_move:
moving = query_word[4:query_word_length].replace(" ","")
reply = True
moving = query_word[4:query_word_length].replace(" ","")
reply = True
elif query_word[0:2] == 'fi':
elif query_word == search_end:
reply = True
reply = True
elif query_word[0:4] == 'jocs':
elif query_word == search_games:
reply = True
reply = True
elif query_word[0:5] == 'envia':
elif query_word[:search_send_slicing] == search_send:
reply = True
reply = True
else:
else:
reply = False
reply = False
return (reply, query_word, moving)
@ -998,6 +1019,84 @@ def replying():
print(v_error)
def load_strings(bot_lang):
search_end = get_parameter("search_end", language_filepath)
search_move = get_parameter("search_move", language_filepath)
search_new = get_parameter("search_new", language_filepath)
search_games = get_parameter("search_games", language_filepath)
search_send = get_parameter("search_send", language_filepath)
new_game_started = get_parameter("new_game_started", language_filepath)
playing_with = get_parameter("playing_with", language_filepath)
your_turn = get_parameter("your_turn", language_filepath)
game_name = get_parameter("game_name", language_filepath)
chess_hashtag = get_parameter("chess_hashtag", language_filepath)
send_error = get_parameter("send_error", language_filepath)
return (search_end, search_move, search_new, search_games, search_send, new_game_started, playing_with, your_turn, game_name, chess_hashtag, send_error)
def load_strings1(bot_lang):
game_number_anotations = get_parameter("game_number_anotations", language_filepath)
anotations_sent = get_parameter("anotations_sent", language_filepath)
game_no_exists = get_parameter("game_no_exists", language_filepath)
it_not_exists = get_parameter("it_not_exists", language_filepath)
game_already_started = get_parameter("game_already_started", language_filepath)
wait_other_player = get_parameter("wait_other_player", language_filepath)
is_not_legal_move = get_parameter("is_not_legal_move", language_filepath)
check_done = get_parameter("check_done", language_filepath)
check_mate = get_parameter("check_mate", language_filepath)
return (game_number_anotations, anotations_sent, game_no_exists, it_not_exists, game_already_started, wait_other_player, is_not_legal_move, check_done, check_mate)
def load_strings2(bot_lang):
check_mate_movements = get_parameter("check_mate_movements", language_filepath)
the_winner_is = get_parameter("the_winner_is", language_filepath)
well_done = get_parameter("well_done", language_filepath)
winned_games = get_parameter("winned_games", language_filepath)
wins_of_many = get_parameter("wins_of_many", language_filepath)
lost_piece = get_parameter("lost_piece", language_filepath)
not_legal_move_str = get_parameter("not_legal_move_str", language_filepath)
player_leave_game = get_parameter("player_leave_game", language_filepath)
return (check_mate_movements, the_winner_is, well_done, winned_games, wins_of_many, lost_piece, not_legal_move_str, player_leave_game)
def load_strings3(bot_lang):
leave_waiting_game = get_parameter("leave_waiting_game", language_filepath)
started_games = get_parameter("started_games", language_filepath)
game_is_waiting = get_parameter("game_is_waiting", language_filepath)
game_is_on_going = get_parameter("game_is_on_going", language_filepath)
no_on_going_games = get_parameter("no_on_going_games", language_filepath)
is_not_your_turn = get_parameter("is_not_your_turn", language_filepath)
is_the_turn_of = get_parameter("is_the_turn_of", language_filepath)
return (leave_waiting_game, started_games, game_is_waiting, game_is_on_going, no_on_going_games, is_not_your_turn, is_the_turn_of)
def load_strings4(bot_lang):
pawn_piece = get_parameter("pawn_piece", language_filepath)
knight_piece = get_parameter("knight_piece", language_filepath)
bishop_piece = get_parameter("bishop_piece", language_filepath)
rook_piece = get_parameter("rook_piece", language_filepath)
queen_piece = get_parameter("queen_piece", language_filepath)
king_piece = get_parameter("king_piece", language_filepath)
return (pawn_piece, knight_piece, bishop_piece, rook_piece, queen_piece, king_piece)
def load_strings5(bot_lang):
pawn_piece_letter = get_parameter("pawn_piece_letter", language_filepath)
knight_piece_letter = get_parameter("knight_piece_letter", language_filepath)
bishop_piece_letter = get_parameter("bishop_piece_letter", language_filepath)
rook_piece_letter = get_parameter("rook_piece_letter", language_filepath)
queen_piece_letter = get_parameter("queen_piece_letter", language_filepath)
king_piece_letter = get_parameter("king_piece_letter", language_filepath)
email_subject = get_parameter("email_subject", language_filepath)
return (pawn_piece_letter, knight_piece_letter, bishop_piece_letter, rook_piece_letter, queen_piece_letter, king_piece_letter, email_subject)
def mastodon():
# Load secrets from secrets file
@ -1066,7 +1165,7 @@ def create_dir():
def usage():
print('usage: python ' + sys.argv[0] + ' --play')
print('usage: python ' + sys.argv[0] + ' --play' + ' --eng')
###############################################################################
# main
@ -1079,10 +1178,58 @@ if __name__ == '__main__':
usage()
elif len(sys.argv) == 2:
elif len(sys.argv) >= 2:
if sys.argv[1] == '--play':
if len(sys.argv) == 3:
if sys.argv[2] == '--eng':
bot_lang = 'eng'
else:
bot_lang = 'ca'
if bot_lang == "ca":
language_filepath = "locales/cat.txt"
elif bot_lang == "eng":
language_filepath = "locales/eng.txt"
else:
print("\nOnly 'cat' and 'eng' languages are supported.\n")
sys.exit(0)
if bot_lang == 'ca':
search_move_slicing = 3
search_send_slicing = 5
send_game_slicing = 6
elif bot_lang == 'eng':
search_move_slicing = 4
search_send_slicing = 4
send_game_slicing = 5
search_end, search_move, search_new, search_games, search_send, new_game_started, playing_with, your_turn, game_name, chess_hashtag, send_error = load_strings(bot_lang)
game_number_anotations, anotations_sent, game_no_exists, it_not_exists, game_already_started, wait_other_player, is_not_legal_move, check_done, check_mate = load_strings1(bot_lang)
check_mate_movements, the_winner_is, well_done, winned_games, wins_of_many, lost_piece, not_legal_move_str, player_leave_game = load_strings2(bot_lang)
leave_waiting_game, started_games, game_is_waiting, game_is_on_going, no_on_going_games, is_not_your_turn, is_the_turn_of = load_strings3(bot_lang)
pawn_piece, knight_piece, bishop_piece, rook_piece, queen_piece, king_piece = load_strings4(bot_lang)
pawn_piece_letter, knight_piece_letter, bishop_piece_letter, rook_piece_letter, queen_piece_letter, king_piece_letter, email_subject = load_strings5(bot_lang)
mastodon, mastodon_hostname, bot_username = mastodon()
mastodon_db, mastodon_db_user, chess_db, chess_db_user = db_config()
@ -1130,7 +1277,7 @@ if __name__ == '__main__':
status_url = url_lst[i]
if query_word != "jocs":
if query_word != search_games:
is_playing, game_id, white_user, black_user, on_going_game, waiting, playing_user = check_games()
@ -1144,7 +1291,7 @@ if __name__ == '__main__':
if reply == True and is_playing == False:
if query_word == 'nova' and not game_waiting:
if query_word == search_new and not game_waiting:
board = chess.Board()
@ -1154,7 +1301,7 @@ if __name__ == '__main__':
svg2png(bytestring=svgfile,write_to=board_file)
toot_text = "@"+username+ " partida iniciada! Esperant jugador... " +"\n"
toot_text = '@'+username + ' ' + new_game_started + '\n'
toot_text += '\n'
@ -1168,7 +1315,7 @@ if __name__ == '__main__':
update_replies(status_id, username, now)
elif query_word == 'nova' and game_waiting:
elif query_word == search_new and game_waiting:
game_status, white_user, chess_game = join_player()
@ -1184,15 +1331,15 @@ if __name__ == '__main__':
svg2png(bytestring=svgfile,write_to=board_file)
toot_text = "@"+username + " jugues amb " + white_user + "\n"
toot_text = '@'+username + ' ' + playing_with + ' ' + white_user + "\n"
toot_text += '\n'
toot_text += "@"+white_user + ": el teu torn" + "\n"
toot_text += '@'+white_user + ': ' + your_turn + "\n"
toot_text += '\n'
toot_text += 'partida: ' + str(game_id) + ' ' + '#escacs' + '\n'
toot_text += game_name + ': ' + str(game_id) + ' ' + chess_hashtag + '\n'
image_id = mastodon.media_post(board_file, "image/png").id
@ -1204,25 +1351,25 @@ if __name__ == '__main__':
update_replies(status_id, username, now)
elif query_word[0:5] == 'envia':
elif query_word[:search_send_slicing] == search_send:
query_word_length = len(query_word)
send_game = query_word[6:query_word_length].replace(' ', '')
send_game = query_word[send_game_slicing:query_word_length].replace(' ', '')
emailed, game_id, game_found = send_anotation(send_game)
if emailed == False and game_found == True:
toot_text = "@"+username + " error al enviar les anotacions :-("
toot_text = '@'+username + send_error
elif emailed == True and game_found == True:
toot_text = "@"+username + " les anotaciones de la partida n." + str(game_id) + " enviades amb èxit!"
toot_text = '@'+username + ' ' + game_number_anotations + str(game_id) + ' ' + anotations_sent
elif emailed == False and game_found == False:
toot_text = "@"+username + " la partida n." + str(game_id) + " no existeix..."
toot_text = '@'+username + ' ' + game_no_exists + str(game_id) + ' ' + it_not_exists
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1234,9 +1381,9 @@ if __name__ == '__main__':
elif reply and is_playing:
if query_word == 'nova':
if query_word == search_new:
toot_text = "@"+username + ' ja tenies iniciada una partida!' + '\n'
toot_text = '@'+username + ' ' + game_already_started + '\n'
if black_user != '':
@ -1244,11 +1391,11 @@ if __name__ == '__main__':
else:
toot_text += "espera l'altre jugador" + '\n'
toot_text += wait_other_player + '\n'
toot_text += '\n'
toot_text += 'partida: ' + str(game_id) + ' ' + '#escacs' + '\n'
toot_text += game_name + ': ' + str(game_id) + ' ' + chess_hashtag + '\n'
board = chess.Board(on_going_game)
@ -1264,15 +1411,47 @@ if __name__ == '__main__':
update_replies(status_id, username, now)
elif query_word[0:3] == 'mou' and playing_user == username:
elif query_word[:search_move_slicing] == search_move and playing_user == username:
board = chess.Board(on_going_game)
promoted = False
try:
if chess.Move.from_uci(moving) not in board.legal_moves:
piece_square_index = chess.SQUARE_NAMES.index(moving[:2])
toot_text = "@"+username + ": " + moving + " és un moviment il·legal. Torna a tirar." + "\n"
moving_piece = board.piece_type_at(piece_square_index)
if moving_piece == 1:
square_index = chess.SQUARE_NAMES.index(moving[2:4])
if bool(board.turn == chess.WHITE) == True:
square_rank_trigger = 7
elif bool(board.turn == chess.BLACK) == True:
square_rank_trigger = 0
if chess.square_rank(square_index) == square_rank_trigger:
promoted = True
if len(moving) == 4:
moving = moving + 'q'
not_legal_move = chess.Move.from_uci(moving) not in board.legal_moves
else:
not_legal_move = chess.Move.from_uci(moving) not in board.legal_moves
if not_legal_move:
toot_text = '@'+username + ': ' + moving + ' ' + is_not_legal_move + '\n'
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1288,7 +1467,7 @@ if __name__ == '__main__':
capture = True
square_capture_index = chess.SQUARE_NAMES.index(moving[2:])
square_capture_index = chess.SQUARE_NAMES.index(moving[2:4])
captured_piece = board.piece_type_at(square_capture_index)
@ -1326,33 +1505,33 @@ if __name__ == '__main__':
if check == True and checkmate == False:
toot_text = "@"+playing_user + " " + username + " t'ha fet escac!\n"
toot_text = "@"+playing_user + " " + username + ' ' + check_done + '\n'
elif check == True and checkmate == True:
toot_text = "\nEscac i mat! (en " + str(game_moves) + " moviments)" + "\n\nEl guanyador és: " + "@"+username + '\n'
toot_text = '\n' + check_mate + ' ' + str(game_moves) + ' ' + check_mate_movements + '\n\n' + the_winner_is + ' ' + "@"+username + '\n'
toot_text += "\n@"+playing_user + ": ben jugat!" + "\n"
toot_text += "\n@"+playing_user + ': ' + well_done + "\n"
toot_text += "\nPartides guanyades:" + "\n"
toot_text += '\n' + winned_games + "\n"
played_games, wins = get_stats(username)
toot_text += username + ": " + str(wins) + " de " + str(played_games) + "\n"
toot_text += username + ': ' + str(wins) + ' ' + wins_of_many + ' ' + str(played_games) + "\n"
played_games, wins = get_stats(playing_user)
toot_text += playing_user + ": " + str(wins) + " de " + str(played_games) + "\n"
toot_text += playing_user + ': ' + str(wins) + ' ' + wins_of_many + ' ' + str(played_games) + "\n"
else:
toot_text = "@"+playing_user + ' el teu torn.'+ '\n'
toot_text = '@'+playing_user + ' ' + your_turn + '\n'
if capture == True and checkmate == False:
toot_text += "\n* has perdut " + piece_name + "!\n"
toot_text += '\n' + lost_piece + ' ' + piece_name + '!\n'
toot_text += '\npartida: ' + str(game_id) + ' ' + '#escacs' + '\n'
toot_text += '\n' + game_name + ': ' + str(game_id) + ' ' + chess_hashtag + '\n'
if username == white_user:
@ -1390,7 +1569,7 @@ if __name__ == '__main__':
game_moves = board.ply()
save_annotation()
save_anotation(moving)
update_moves(username, game_moves)
@ -1400,7 +1579,7 @@ if __name__ == '__main__':
print(v_error)
toot_text = "@"+username + ' moviment il·legal! (' + moving + '!?)\n'
toot_text = '@'+username + ' ' + not_legal_move_str + moving + '!?)\n'
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1412,7 +1591,7 @@ if __name__ == '__main__':
print(a_error)
toot_text = "@"+username + ' moviment il·legal! (' + moving + '!?)\n'
toot_text = '@'+username + ' ' + not_legal_move_str + moving + '!?)\n'
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1420,13 +1599,13 @@ if __name__ == '__main__':
pass
elif query_word[0:2] == 'fi':
elif query_word == search_end:
if black_user != '':
if username == white_user:
toot_text = "@"+username + " ha deixat la partida amb " + "@"+black_user
toot_text = '@'+username + ' ' + player_leave_game + ' ' + '@'+black_user
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1440,7 +1619,7 @@ if __name__ == '__main__':
else:
toot_text = "@"+username + " ha deixat la partida amb " + white_user
toot_text = '@'+username + ' ' + player_leave_game + ' ' + white_user
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1454,7 +1633,7 @@ if __name__ == '__main__':
else:
toot_text = "@"+username + " has abandonat la partida en espera."
toot_text = '@'+username + ' ' + leave_waiting_game
mastodon.status_post(toot_text, in_reply_to_id=status_id, visibility=visibility)
@ -1466,30 +1645,30 @@ if __name__ == '__main__':
continue
elif query_word == 'jocs':
elif query_word == search_games:
player1_name_lst, player2_name_lst, game_status_lst, game_link_lst, next_move_lst = current_games()
if len(player1_name_lst) > 0:
toot_text = "@"+username + " partides iniciades:" + "\n"
toot_text = "@"+username + ' ' + started_games + "\n"
i = 0
while i < len(player1_name_lst):
if game_status_lst[i] == 'waiting':
toot_text += "\n" + player1_name_lst[i] + " / " + player2_name_lst[i] + " (en espera...)" + "\n"
toot_text += '\n' + player1_name_lst[i] + ' / ' + player2_name_lst[i] + ' ' + game_is_waiting + "\n"
else:
if next_move_lst[i] == player1_name_lst[i]:
toot_text += "\n*" + player1_name_lst[i] + " / " + player2_name_lst[i] + " (en joc)" + "\n"
toot_text += '\n*' + player1_name_lst[i] + ' / ' + player2_name_lst[i] + ' ' + game_is_on_going + '\n'
else:
toot_text += "\n" + player1_name_lst[i] + " / *" + player2_name_lst[i] + " (en joc)" + "\n"
toot_text += '\n' + player1_name_lst[i] + ' / *' + player2_name_lst[i] + ' ' + game_is_on_going + '\n'
if game_link_lst[i] != None:
@ -1501,13 +1680,13 @@ if __name__ == '__main__':
else:
toot_text = "@"+username + " cap partida en joc" + "\n"
toot_text = '@'+username + ' ' + no_on_going_games + '\n'
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
update_replies(status_id, username, now)
elif query_word[0:5] == 'envia':
elif query_word[:search_send_slicing] == search_send:
query_word_length = len(query_word)
@ -1517,15 +1696,15 @@ if __name__ == '__main__':
if emailed == False and game_found == True:
toot_text = "@"+username + " error al enviar les anotacions :-("
toot_text = '@'+username + ' ' + send_error
elif emailed == True and game_found == True:
toot_text = "@"+username + " les anotaciones de la partida n." + str(game_id) + " enviades amb èxit!"
toot_text = '@'+username + ' ' + game_number_anotations + str(game_id) + ' ' + anotations_sent
elif emailed == False and game_found == False:
toot_text = "@"+username + " la partida n." + str(game_id) + " no existeix..."
toot_text = '@'+username + ' ' + game_no_exists + str(game_id) + ' ' + it_not_exists
mastodon.status_post(toot_text, in_reply_to_id=status_id,visibility=visibility)
@ -1535,15 +1714,15 @@ if __name__ == '__main__':
if playing_user == None:
toot_text = "@"+username + " no és el teu torn." + "\n"
toot_text = '@'+username + ' ' + is_not_your_turn + '\n'
else:
toot_text = "@"+username + " és el torn de " + playing_user + "\n"
toot_text = '@'+username + ' ' + is_the_turn_of + ' ' + playing_user + "\n"
toot_text += '\n'
toot_text += 'partida: ' + str(game_id) + ' ' + '#escacs' + '\n'
toot_text += game_name + ': ' + str(game_id) + ' ' + chess_hashtag + '\n'
board = chess.Board(on_going_game)

View file

@ -39,11 +39,6 @@ def write_config():
print("Writing parameters names 'mastodon_hostname' and 'bot_username' to " + config_filepath)
the_file.write('mastodon_hostname: \n' + 'bot_username: \n')
def write_lang_config():
with open(lang_config_filepath, 'a') as lang_file:
lang_file.write('bot_lang: \n')
print("adding Bot lang parameter name 'bot_lang' to "+ lang_config_filepath)
def read_client_lines(self):
client_path = 'app_clientcred.txt'
with open(client_path) as fp:
@ -72,12 +67,6 @@ def read_config_line():
modify_file(config_filepath, "mastodon_hostname: ", value=hostname)
modify_file(config_filepath, "bot_username: ", value=bot_username)
def read_lang_config_line():
with open(lang_config_filepath) as fp:
line = fp.readline()
lang = input("Enter Bot lang, ex. en or ca: ")
modify_file(lang_config_filepath, "bot_lang: ", value=lang)
def log_in():
error = 0
try:
@ -195,27 +184,6 @@ def get_hostname( parameter, config_filepath ):
print("setup done!")
sys.exit(0)
# Returns the parameter from the specified file
def get_lang( parameter, lang_config_filepath ):
# Check if lang file exists
if not os.path.isfile(lang_config_filepath):
print("File %s not found, creating it."%lang_config_filepath)
create_lang_config()
# Find parameter in file
with open( lang_config_filepath ) as f:
for line in f:
if line.startswith( parameter ):
return line.replace(parameter + ":", "").strip()
# Cannot find parameter, exit
print(lang_config_filepath + " Missing parameter %s "%parameter)
write_lang_config()
read_lang_config_line()
print("Bot lang setup done!")
sys.exit(0)
###############################################################################
# main
@ -232,7 +200,3 @@ if __name__ == '__main__':
mastodon_hostname = get_hostname("mastodon_hostname", config_filepath)
bot_username = get_parameter("bot_username", config_filepath)
# Load Bot lang from config file
lang_config_filepath = "config/lang_config.txt"
bot_lang = get_lang("bot_lang", lang_config_filepath) # E.g., en or ca