|
|
|
@ -19,6 +19,7 @@ import chess
|
|
|
|
|
import chess.svg
|
|
|
|
|
from cairosvg import svg2png
|
|
|
|
|
import chess.pgn
|
|
|
|
|
from PIL import Image, ImageFont, ImageDraw
|
|
|
|
|
|
|
|
|
|
def cleanhtml(raw_html):
|
|
|
|
|
cleanr = re.compile('<.*?>')
|
|
|
|
@ -29,6 +30,47 @@ def unescape(s):
|
|
|
|
|
s = s.replace("'", "'")
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
def create_panel(username, played_games, wins):
|
|
|
|
|
|
|
|
|
|
ratio = round((wins * 100) / played_games, 2)
|
|
|
|
|
x = 10
|
|
|
|
|
y = 10
|
|
|
|
|
|
|
|
|
|
fons = Image.open('app/panel/fons.jpg')
|
|
|
|
|
print(fons.size)
|
|
|
|
|
|
|
|
|
|
# add chess icon
|
|
|
|
|
icon_path = 'app/panel/chess.png'
|
|
|
|
|
icon_img = Image.open(icon_path)
|
|
|
|
|
|
|
|
|
|
fons.paste(icon_img, (y+350, x+50), icon_img)
|
|
|
|
|
|
|
|
|
|
logo_img = Image.open('app/panel/logo.png')
|
|
|
|
|
fons.paste(logo_img, (15, 320), logo_img)
|
|
|
|
|
|
|
|
|
|
fons.save('app/panel/panel.png',"PNG")
|
|
|
|
|
|
|
|
|
|
base = Image.open('app/panel/panel.png').convert('RGBA')
|
|
|
|
|
txt = Image.new('RGBA', base.size, (255,255,255,0))
|
|
|
|
|
fnt = ImageFont.truetype('app/fonts/DroidSans.ttf', 40, layout_engine=ImageFont.LAYOUT_BASIC)
|
|
|
|
|
# get a drawing context
|
|
|
|
|
draw = ImageDraw.Draw(txt)
|
|
|
|
|
|
|
|
|
|
draw.text((y+200,x+20), panel_title_str + ' ' + username, font=fnt, fill=(255,255,255,220)) #fill=(255,255,255,255)) ## full opacity
|
|
|
|
|
|
|
|
|
|
fnt = ImageFont.truetype('app/fonts/DroidSans.ttf', 25, layout_engine=ImageFont.LAYOUT_BASIC)
|
|
|
|
|
|
|
|
|
|
draw.text((y+70,x+120), panel_games_str + ': ' + str(played_games), font=fnt, fill=(255,255,255,220)) #fill=(255,255,255,255)) ## full opacity
|
|
|
|
|
draw.text((y+70,x+170), panel_wins_str + ': ' + str(wins), font=fnt, fill=(255,255,255,220)) #fill=(255,255,255,255)) ## full opacity
|
|
|
|
|
draw.text((y+70,x+220), panel_ratio_str + ': ' + str(ratio) + '%', font=fnt, fill=(255,255,255,220))
|
|
|
|
|
|
|
|
|
|
fnt = ImageFont.truetype('app/fonts/DroidSans.ttf', 15, layout_engine=ImageFont.LAYOUT_BASIC)
|
|
|
|
|
|
|
|
|
|
draw.text((60,330), bot_username + '@' + mastodon_hostname + ' - 2020', font=fnt, fill=(255,255,255,200)) #fill=(255,255,255,255)) ## full opacity
|
|
|
|
|
|
|
|
|
|
out = Image.alpha_composite(base, txt)
|
|
|
|
|
out.save('app/panel/' + username + '_panel.png')
|
|
|
|
|
|
|
|
|
|
def get_bot_id():
|
|
|
|
|
|
|
|
|
|
###################################################################################################################################
|
|
|
|
@ -142,7 +184,7 @@ def get_notification_data():
|
|
|
|
|
|
|
|
|
|
url_lst = []
|
|
|
|
|
|
|
|
|
|
search_text = [search_end, search_move, search_new, search_games, search_send, search_help, search_draw]
|
|
|
|
|
search_text = [search_end, search_move, search_new, search_games, search_send, search_help, search_draw, search_panel]
|
|
|
|
|
|
|
|
|
|
conn = psycopg2.connect(database = mastodon_db, user = mastodon_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
|
|
|
|
|
|
|
|
@ -1109,6 +1151,10 @@ def replying():
|
|
|
|
|
|
|
|
|
|
reply = True
|
|
|
|
|
|
|
|
|
|
elif query_word == search_panel:
|
|
|
|
|
|
|
|
|
|
reply = True
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
reply = False
|
|
|
|
@ -1218,8 +1264,13 @@ def load_strings7(bot_lang):
|
|
|
|
|
draw_and_str = get_parameter("draw_and_str", language_filepath)
|
|
|
|
|
agreed_draw_str = get_parameter("agreed_draw_str", language_filepath)
|
|
|
|
|
claim_a_draw = get_parameter("claim_a_draw", language_filepath)
|
|
|
|
|
search_panel = get_parameter("search_panel", language_filepath)
|
|
|
|
|
panel_title_str = get_parameter("panel_title_str", language_filepath)
|
|
|
|
|
panel_games_str = get_parameter("panel_games_str", language_filepath)
|
|
|
|
|
panel_wins_str = get_parameter("panel_wins_str", language_filepath)
|
|
|
|
|
panel_ratio_str = get_parameter("panel_ratio_str", language_filepath)
|
|
|
|
|
|
|
|
|
|
return (claim_draw_str, draw_and_str, agreed_draw_str, claim_a_draw)
|
|
|
|
|
return (claim_draw_str, draw_and_str, agreed_draw_str, claim_a_draw, search_panel, panel_title_str, panel_games_str, panel_wins_str, panel_ratio_str)
|
|
|
|
|
|
|
|
|
|
def mastodon():
|
|
|
|
|
|
|
|
|
@ -1365,7 +1416,7 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
start_or_join_a_new_game, move_a_piece, leave_a_game, list_games, get_a_game_anotation, show_help, search_draw, ask_for_draw = load_strings6(bot_lang)
|
|
|
|
|
|
|
|
|
|
claim_draw_str, draw_and_str, agreed_draw_str, claim_a_draw = load_strings7(bot_lang)
|
|
|
|
|
claim_draw_str, draw_and_str, agreed_draw_str, claim_a_draw, search_panel, panel_title_str, panel_games_str, panel_wins_str, panel_ratio_str = load_strings7(bot_lang)
|
|
|
|
|
|
|
|
|
|
mastodon, mastodon_hostname, bot_username = mastodon()
|
|
|
|
|
|
|
|
|
@ -1514,6 +1565,22 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
update_replies(status_id, username, now)
|
|
|
|
|
|
|
|
|
|
elif query_word == search_panel:
|
|
|
|
|
|
|
|
|
|
played_games, wins = get_stats(username)
|
|
|
|
|
|
|
|
|
|
create_panel(username, played_games, wins)
|
|
|
|
|
|
|
|
|
|
toot_text = '@'+username
|
|
|
|
|
|
|
|
|
|
saved_panel = 'app/panel/' + username + '_panel.png'
|
|
|
|
|
|
|
|
|
|
image_id = mastodon.media_post(saved_panel, "image/png").id
|
|
|
|
|
|
|
|
|
|
mastodon.status_post(toot_text, in_reply_to_id=status_id, visibility=visibility, media_ids={image_id})
|
|
|
|
|
|
|
|
|
|
update_replies(status_id, username, now)
|
|
|
|
|
|
|
|
|
|
elif query_word == search_help:
|
|
|
|
|
|
|
|
|
|
help_text = toot_help()
|
|
|
|
@ -1921,6 +1988,22 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
update_replies(status_id, username, now)
|
|
|
|
|
|
|
|
|
|
elif query_word == search_panel:
|
|
|
|
|
|
|
|
|
|
played_games, wins = get_stats(username)
|
|
|
|
|
|
|
|
|
|
create_panel(username, played_games, wins)
|
|
|
|
|
|
|
|
|
|
toot_text = '@'+username
|
|
|
|
|
|
|
|
|
|
saved_panel = 'app/panel/' + username + '_panel.png'
|
|
|
|
|
|
|
|
|
|
image_id = mastodon.media_post(saved_panel, "image/png").id
|
|
|
|
|
|
|
|
|
|
mastodon.status_post(toot_text, in_reply_to_id=status_id, visibility=visibility, media_ids={image_id})
|
|
|
|
|
|
|
|
|
|
update_replies(status_id, username, now)
|
|
|
|
|
|
|
|
|
|
elif query_word == search_help:
|
|
|
|
|
|
|
|
|
|
help_text = toot_help()
|
|
|
|
|