New feature! Added panel stats
This commit is contained in:
pare
3e539de24a
commit
02f2ae6e69
S'han modificat 9 arxius amb 108 adicions i 4 eliminacions
|
@ -42,6 +42,10 @@ Don't use q for queen. Pawn is promoted to Queen by default.
|
||||||
|
|
||||||
@your_bot_username draw
|
@your_bot_username draw
|
||||||
|
|
||||||
|
- To get your panel stats:
|
||||||
|
|
||||||
|
@your_bot_username panel
|
||||||
|
|
||||||
### Commands table
|
### Commands table
|
||||||
|
|
||||||
| ca | en | es | ex. | Observ. |
|
| ca | en | es | ex. | Observ. |
|
||||||
|
@ -53,6 +57,7 @@ Don't use q for queen. Pawn is promoted to Queen by default.
|
||||||
| envia | send | envia | 1 | game number |
|
| envia | send | envia | 1 | game number |
|
||||||
| taules| draw | tablas | | |
|
| taules| draw | tablas | | |
|
||||||
| ajuda | help | ayuda | | |
|
| ajuda | help | ayuda | | |
|
||||||
|
| panell| panel | panel | | |
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
|
@ -87,3 +92,4 @@ Within Python Virtual Environment:
|
||||||
28.11.2020 - New feature! Added help
|
28.11.2020 - New feature! Added help
|
||||||
03.12.2020 - New feature! Added pgn save & send support
|
03.12.2020 - New feature! Added pgn save & send support
|
||||||
04.12.2020 - New feature! Now players can claim a draw.
|
04.12.2020 - New feature! Now players can claim a draw.
|
||||||
|
05.12.2020 - New feature! Add panel stats.
|
||||||
|
|
BIN
app/fonts/DroidSans.ttf
Normal file
BIN
app/fonts/DroidSans.ttf
Normal file
Archivo binario no mostrado.
|
@ -61,3 +61,8 @@ claim_draw_str: ha proposat taules a
|
||||||
draw_and_str: i
|
draw_and_str: i
|
||||||
agreed_draw_str: han acordat taules.
|
agreed_draw_str: han acordat taules.
|
||||||
claim_a_draw: taules (per a proposar/acceptar taules)
|
claim_a_draw: taules (per a proposar/acceptar taules)
|
||||||
|
search_panel: panell
|
||||||
|
panel_title_str: Panell de
|
||||||
|
panel_games_str: Partides
|
||||||
|
panel_wins_str: Victòries
|
||||||
|
panel_ratio_str: Ràtio
|
||||||
|
|
|
@ -61,3 +61,8 @@ claim_draw_str: had claimed draw to
|
||||||
draw_and_str: and
|
draw_and_str: and
|
||||||
agreed_draw_str: agreed draw.
|
agreed_draw_str: agreed draw.
|
||||||
claim_a_draw: draw (to claim/accept a draw)
|
claim_a_draw: draw (to claim/accept a draw)
|
||||||
|
search_panel: panel
|
||||||
|
panel_title_str: Panel of
|
||||||
|
panel_games_str: Games
|
||||||
|
panel_wins_str: Wins
|
||||||
|
panel_ratio_str: Ratio
|
||||||
|
|
|
@ -61,3 +61,8 @@ claim_draw_str: ha propuesto tablas a
|
||||||
draw_and_str: y
|
draw_and_str: y
|
||||||
agreed_draw_str: han acordado tablas.
|
agreed_draw_str: han acordado tablas.
|
||||||
claim_a_draw: tablas (para proponer/aceptar tablas)
|
claim_a_draw: tablas (para proponer/aceptar tablas)
|
||||||
|
search_panel: panel
|
||||||
|
panel_title_str: Panel de
|
||||||
|
panel_games_str: Partidas
|
||||||
|
panel_wins_str: Victorias
|
||||||
|
panel_ratio_str: Ratio
|
||||||
|
|
BIN
app/panel/chess.png
Normal file
BIN
app/panel/chess.png
Normal file
Archivo binario no mostrado.
Desprès Amplada: | Alçada: | Mida: 41 KiB |
BIN
app/panel/fons.jpg
Normal file
BIN
app/panel/fons.jpg
Normal file
Archivo binario no mostrado.
Desprès Amplada: | Alçada: | Mida: 12 KiB |
BIN
app/panel/logo.png
Normal file
BIN
app/panel/logo.png
Normal file
Archivo binario no mostrado.
Desprès Amplada: | Alçada: | Mida: 3,6 KiB |
|
@ -19,6 +19,7 @@ import chess
|
||||||
import chess.svg
|
import chess.svg
|
||||||
from cairosvg import svg2png
|
from cairosvg import svg2png
|
||||||
import chess.pgn
|
import chess.pgn
|
||||||
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
|
|
||||||
def cleanhtml(raw_html):
|
def cleanhtml(raw_html):
|
||||||
cleanr = re.compile('<.*?>')
|
cleanr = re.compile('<.*?>')
|
||||||
|
@ -29,6 +30,47 @@ def unescape(s):
|
||||||
s = s.replace("'", "'")
|
s = s.replace("'", "'")
|
||||||
return s
|
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():
|
def get_bot_id():
|
||||||
|
|
||||||
###################################################################################################################################
|
###################################################################################################################################
|
||||||
|
@ -142,7 +184,7 @@ def get_notification_data():
|
||||||
|
|
||||||
url_lst = []
|
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")
|
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
|
reply = True
|
||||||
|
|
||||||
|
elif query_word == search_panel:
|
||||||
|
|
||||||
|
reply = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
reply = False
|
reply = False
|
||||||
|
@ -1218,8 +1264,13 @@ def load_strings7(bot_lang):
|
||||||
draw_and_str = get_parameter("draw_and_str", language_filepath)
|
draw_and_str = get_parameter("draw_and_str", language_filepath)
|
||||||
agreed_draw_str = get_parameter("agreed_draw_str", language_filepath)
|
agreed_draw_str = get_parameter("agreed_draw_str", language_filepath)
|
||||||
claim_a_draw = get_parameter("claim_a_draw", 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():
|
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)
|
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()
|
mastodon, mastodon_hostname, bot_username = mastodon()
|
||||||
|
|
||||||
|
@ -1514,6 +1565,22 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
update_replies(status_id, username, now)
|
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:
|
elif query_word == search_help:
|
||||||
|
|
||||||
help_text = toot_help()
|
help_text = toot_help()
|
||||||
|
@ -1921,6 +1988,22 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
update_replies(status_id, username, now)
|
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:
|
elif query_word == search_help:
|
||||||
|
|
||||||
help_text = toot_help()
|
help_text = toot_help()
|
||||||
|
|
Loading…
Referencia en una nova incidència