1
Fork 0

hoooooooly cow

This commit is contained in:
Steffo 2024-11-30 14:39:46 +01:00
parent 15ad3dfb94
commit 54b15027a8
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
4 changed files with 33 additions and 23 deletions

View file

@ -5,7 +5,7 @@ use serde::Deserialize;
use skillratings::weng_lin::WengLinConfig; use skillratings::weng_lin::WengLinConfig;
use teloxide::Bot; use teloxide::Bot;
use teloxide::requests::Requester; use teloxide::requests::Requester;
use teloxide::types::{ChatId, MessageId, ThreadId}; use teloxide::types::{ChatId, MessageId, ParseMode, ThreadId};
use crate::config; use crate::config;
use crate::database::model::{Match, MatchI, Outcome, Player, WengLinRating}; use crate::database::model::{Match, MatchI, Outcome, Player, WengLinRating};
@ -33,6 +33,7 @@ pub struct MatchII {
fn player_to_text(player: &Player, before: &WengLinRating, after: &WengLinRating) -> String { fn player_to_text(player: &Player, before: &WengLinRating, after: &WengLinRating) -> String {
let name = &player.username; let name = &player.username;
let competitive = &player.competitive; let competitive = &player.competitive;
let telegram_id = &player.telegram_id;
match competitive { match competitive {
false => { false => {
@ -43,7 +44,7 @@ fn player_to_text(player: &Player, before: &WengLinRating, after: &WengLinRating
let after = after.human_score(); let after = after.human_score();
let change = after - before; let change = after - before;
format!("<b>{name}</b> <i>({change})</i>") format!(r#"<b><a href="tg://user?id={telegram_id}">{name}</a></b> <i>({change:+})</i>"#)
}, },
} }
} }
@ -58,12 +59,12 @@ fn match_to_text(r#match: &Match, player_a: &Player, player_b: &Player) -> Strin
None => format!("🔵 {player_a} ha trionfato su {player_b}!"), None => format!("🔵 {player_a} ha trionfato su {player_b}!"),
}, },
Outcome::BWins => match &r#match.name { Outcome::BWins => match &r#match.name {
Some(name) => format!("⚪️ {player_a} è stato sconfitto da {player_b} in <b>{name}</b>!"), Some(name) => format!("🟠 {player_a} è stato sconfitto da {player_b} in <b>{name}</b>!"),
None => format!("⚪️ {player_a} è stato sconfitto da {player_b}!"), None => format!("🟠 {player_a} è stato sconfitto da {player_b}!"),
}, },
Outcome::Tie => match &r#match.name { Outcome::Tie => match &r#match.name {
Some(name) => format!("🟠 {player_a} e {player_b} hanno pareggiato in <b>{name}</b>!"), Some(name) => format!("⚪️ {player_a} e {player_b} hanno pareggiato in <b>{name}</b>!"),
None => format!("🟠 {player_a} e {player_b} hanno pareggiato!"), None => format!("⚪️ {player_a} e {player_b} hanno pareggiato!"),
}, },
} }
} }
@ -141,6 +142,8 @@ pub async fn post_match(
let chat = ChatId(*chat); let chat = ChatId(*chat);
let mut send_message_future = bot.send_message(chat, match_to_text(&r#match, &player_a, &player_b)); let mut send_message_future = bot.send_message(chat, match_to_text(&r#match, &player_a, &player_b));
send_message_future.parse_mode = Some(ParseMode::Html);
let topic = config::TELEGRAM_NOTIFICATION_TOPIC_ID(); let topic = config::TELEGRAM_NOTIFICATION_TOPIC_ID();
if let Some(topic) = topic { if let Some(topic) = topic {
let topic = MessageId(*topic); let topic = MessageId(*topic);

View file

@ -1,4 +1,3 @@
import {ReportBox} from "@/components/ReportBox"
import {ReportBoxInteractive} from "@/components/ReportBoxInteractive" import {ReportBoxInteractive} from "@/components/ReportBoxInteractive"
import {PlayerO} from "@/holycow" import {PlayerO} from "@/holycow"

View file

@ -6,6 +6,14 @@ nextjs-portal {
position: absolute; position: absolute;
} }
hr {
margin: 0.5em 0;
}
.separator-lightest {
border-color: hsl(var(--bhsl-current-hue) var(--bhsl-current-saturation) var(--bhsl-current-lightness) / .05);
}
:where(body) :where(.form-flex) > :where(.form-flex-choice, label) > :where(*) { :where(body) :where(.form-flex) > :where(.form-flex-choice, label) > :where(*) {
/* TODO: Fix in bluelib */ /* TODO: Fix in bluelib */
align-items: center; align-items: center;

View file

@ -38,16 +38,22 @@ export function ReportBox({players, playerA, playerB, setPlayerB, outcome, setOu
<h3> <h3>
Registra risultato Registra risultato
</h3> </h3>
<p></p> <hr className="separator-lightest"/>
<label>
<span>Titolo</span>
<input type={"text"} onChange={e => setName(e.target.value)} value={name} placeholder={"Scontro al Garasauto"}/>
<small>opzion.</small>
</label>
<hr className="separator-lightest"/>
<label> <label>
<span>Tu</span> <span>Tu</span>
<div> <select disabled={true}>
{playerA.username} <option>{playerA.username}</option>
</div> </select>
<span>{playerA.human_score && `${playerA.human_score}`}</span> <span>{playerA.human_score && `${playerA.human_score}`}</span>
</label> </label>
<label> <label>
<span>Avversario</span> <span>Avv.</span>
<select onChange={e => setPlayerB(players.find(p => p.id == Number.parseInt(e.target.value)))} value={playerB?.id}> <select onChange={e => setPlayerB(players.find(p => p.id == Number.parseInt(e.target.value)))} value={playerB?.id}>
<option value={undefined}></option> <option value={undefined}></option>
{players {players
@ -57,11 +63,11 @@ export function ReportBox({players, playerA, playerB, setPlayerB, outcome, setOu
)) ))
} }
</select> </select>
<span>{playerB && playerB.human_score && `${playerB.human_score}`}</span> <span>{playerB && playerB.human_score && `${playerB.human_score}`}</span>
</label> </label>
<p></p> <hr className="separator-lightest"/>
<div className={"form-flex-choice"}> <div className={"form-flex-choice"}>
<span>Risultato</span> <span>Ris.</span>
<div> <div>
<label> <label>
<input type={"radio"} name={"result"} value={"AWins"} checked={outcome === Outcome.AWins} onChange={e => e.target.checked && setOutcome(Outcome.AWins)}/> Vittoria <input type={"radio"} name={"result"} value={"AWins"} checked={outcome === Outcome.AWins} onChange={e => e.target.checked && setOutcome(Outcome.AWins)}/> Vittoria
@ -75,13 +81,7 @@ export function ReportBox({players, playerA, playerB, setPlayerB, outcome, setOu
</div> </div>
<span></span> <span></span>
</div> </div>
<p></p> <hr className="separator-lightest"/>
<label>
<span>Titolo sfida</span>
<input type={"text"} onChange={e => setName(e.target.value)} value={name}/>
<small>(opzionale)</small>
</label>
<p></p>
<input <input
type={"submit"} type={"submit"}
value={"Invia"} value={"Invia"}