From 794beece5112fdd70a70020efba5e8be604a8fb1 Mon Sep 17 00:00:00 2001 From: spla Date: Sat, 28 Nov 2020 20:12:36 +0100 Subject: [PATCH] Added fediverse support! Any fediverse user can play Mastodon Chess! --- locales/ca.txt | 1 + locales/en.txt | 1 + locales/es.txt | 1 + mastochess.py | 37 +++++++++++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/locales/ca.txt b/locales/ca.txt index 2c23c6c..439a2c4 100644 --- a/locales/ca.txt +++ b/locales/ca.txt @@ -12,6 +12,7 @@ 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. +cant_send_to_fediverse_account: per ara no és possible :-( it_not_exists: no existeix... game_already_started: ja tenies iniciada una partida! wait_other_player: espera l'altre jugador diff --git a/locales/en.txt b/locales/en.txt index 508e755..6387db3 100644 --- a/locales/en.txt +++ b/locales/en.txt @@ -12,6 +12,7 @@ send_error: sending anotations error :-( game_number_anotations: the anotations of game n. anotations_sent: succesfully sent! game_no_exists: the game n. +cant_send_to_fediverse_account: not possible yet :-( it_not_exists: don't exists... game_already_started: you already started a game! wait_other_player: wait for the second player diff --git a/locales/es.txt b/locales/es.txt index 60f02e5..6cbd5b1 100644 --- a/locales/es.txt +++ b/locales/es.txt @@ -12,6 +12,7 @@ send_error: error al enviar las anotaciones :-( game_number_anotations: las anotaciones de la partida n. anotations_sent: enviades con éxito! game_no_exists: la partida n. +cant_send_to_fediverse_account: por ahora no es posible :-( it_not_exists: no existe... game_already_started: ja tenias iniciada una partida! wait_other_player: espera al otro jugador diff --git a/mastochess.py b/mastochess.py index 96ca4a1..4f7b0cc 100644 --- a/mastochess.py +++ b/mastochess.py @@ -612,7 +612,13 @@ def get_email_address(username): row = cur.fetchone() - username_email = row[0] + if row != None: + + username_email = row[0] + + else: + + username_email = None cur.close() @@ -636,6 +642,10 @@ def send_anotation(game_id): username_email = get_email_address(username) + if username_email == None: + + return (emailed, game_id, game_found) + # Create message object instance msg = MIMEMultipart() @@ -1042,12 +1052,13 @@ def load_strings1(bot_lang): 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) + cant_send_to_fediverse_account = get_parameter("cant_send_to_fediverse_account", 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) + return (game_number_anotations, anotations_sent, game_no_exists, cant_send_to_fediverse_account, it_not_exists, game_already_started, wait_other_player, is_not_legal_move, check_done, check_mate) def load_strings2(bot_lang): @@ -1235,7 +1246,7 @@ if __name__ == '__main__': 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) + game_number_anotations, anotations_sent, game_no_exists, cant_send_to_fediverse_account, 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) @@ -1266,21 +1277,25 @@ if __name__ == '__main__': username, domain = get_user_domain(account_id) + if domain != None: + + username = username + '@' + domain + status_id = status_id_lst[i] replied = check_replies(status_id) - if replied == True or domain != None: + if replied == True: #or domain != None: i += 1 continue - if domain != None: + #if domain != None: - update_replies(username, status_id) + #update_replies(username, status_id) - i += 1 + #i += 1 # listen them or not @@ -1384,7 +1399,13 @@ if __name__ == '__main__': elif emailed == False and game_found == False: - toot_text = '@'+username + ' ' + game_no_exists + str(game_id) + ' ' + it_not_exists + if domain != None: + + toot_text = '@'+username + ' ' + cant_send_to_fediverse_account + + else: + + 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)