mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-22 02:54:21 +00:00
Run "Reformat code..." IDE feature
This commit is contained in:
parent
b84b70080f
commit
ec3f5daff7
34 changed files with 67626 additions and 67621 deletions
|
@ -51,7 +51,7 @@ impl RoyalnetInstance {
|
||||||
fn run_pending_migrations() {
|
fn run_pending_migrations() {
|
||||||
if !config::interface_database::DATABASE_AUTOMIGRATE() {
|
if !config::interface_database::DATABASE_AUTOMIGRATE() {
|
||||||
log::warn!("Database automigration is disabled.");
|
log::warn!("Database automigration is disabled.");
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log::debug!("Automatically applying database migrations...");
|
log::debug!("Automatically applying database migrations...");
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) mod telegram_ext {
|
||||||
text,
|
text,
|
||||||
teloxide::types::InlineKeyboardButtonKind::CallbackData(
|
teloxide::types::InlineKeyboardButtonKind::CallbackData(
|
||||||
self.callback_data(matchmaking_id)
|
self.callback_data(matchmaking_id)
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ pub(crate) mod telegram_ext {
|
||||||
pub async fn destroy_and_send_delete(
|
pub async fn destroy_and_send_delete(
|
||||||
self,
|
self,
|
||||||
database: &mut PgConnection,
|
database: &mut PgConnection,
|
||||||
bot: &teloxide::Bot
|
bot: &teloxide::Bot,
|
||||||
)
|
)
|
||||||
-> AnyResult<()>
|
-> AnyResult<()>
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl BroochService {
|
||||||
min_players_to_process: usize,
|
min_players_to_process: usize,
|
||||||
telegram_bot_token: String,
|
telegram_bot_token: String,
|
||||||
notification_chat_id: ChatId,
|
notification_chat_id: ChatId,
|
||||||
max_imp_wait: TimeDelta
|
max_imp_wait: TimeDelta,
|
||||||
)
|
)
|
||||||
-> AnyResult<Self>
|
-> AnyResult<Self>
|
||||||
{
|
{
|
||||||
|
@ -352,21 +352,21 @@ impl BroochService {
|
||||||
side = match (side, player.is_radiant) {
|
side = match (side, player.is_radiant) {
|
||||||
(_, None) => {
|
(_, None) => {
|
||||||
anyhow::bail!("Non è stata ricevuta da STRATZ la squadra di almeno uno dei giocatori.")
|
anyhow::bail!("Non è stata ricevuta da STRATZ la squadra di almeno uno dei giocatori.")
|
||||||
},
|
}
|
||||||
(None, Some(true)) => {
|
(None, Some(true)) => {
|
||||||
Some(Radiant)
|
Some(Radiant)
|
||||||
},
|
}
|
||||||
(None, Some(false)) => {
|
(None, Some(false)) => {
|
||||||
Some(Dire)
|
Some(Dire)
|
||||||
},
|
}
|
||||||
(Some(Radiant), Some(true)) |
|
(Some(Radiant), Some(true)) |
|
||||||
(Some(Dire), Some(false)) => {
|
(Some(Dire), Some(false)) => {
|
||||||
side
|
side
|
||||||
},
|
}
|
||||||
(Some(Radiant), Some(false)) |
|
(Some(Radiant), Some(false)) |
|
||||||
(Some(Dire), Some(true)) => {
|
(Some(Dire), Some(true)) => {
|
||||||
Some(Both)
|
Some(Both)
|
||||||
},
|
}
|
||||||
(Some(Both), _) => {
|
(Some(Both), _) => {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -391,21 +391,21 @@ impl BroochService {
|
||||||
outcome = match (outcome, player.is_victory) {
|
outcome = match (outcome, player.is_victory) {
|
||||||
(_, None) => {
|
(_, None) => {
|
||||||
anyhow::bail!("Non è stata ricevuta da STRATZ la squadra di almeno uno dei giocatori.")
|
anyhow::bail!("Non è stata ricevuta da STRATZ la squadra di almeno uno dei giocatori.")
|
||||||
},
|
}
|
||||||
(None, Some(true)) => {
|
(None, Some(true)) => {
|
||||||
Some(Victory)
|
Some(Victory)
|
||||||
},
|
}
|
||||||
(None, Some(false)) => {
|
(None, Some(false)) => {
|
||||||
Some(Defeat)
|
Some(Defeat)
|
||||||
},
|
}
|
||||||
(Some(Victory), Some(true)) |
|
(Some(Victory), Some(true)) |
|
||||||
(Some(Defeat), Some(false)) => {
|
(Some(Defeat), Some(false)) => {
|
||||||
outcome
|
outcome
|
||||||
},
|
}
|
||||||
(Some(Victory), Some(false)) |
|
(Some(Victory), Some(false)) |
|
||||||
(Some(Defeat), Some(true)) => {
|
(Some(Defeat), Some(true)) => {
|
||||||
Some(Clash)
|
Some(Clash)
|
||||||
},
|
}
|
||||||
(Some(Clash), _) => {
|
(Some(Clash), _) => {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -661,7 +661,7 @@ impl BroochService {
|
||||||
|
|
||||||
if !self.should_process_match_exists(database, match_id)? {
|
if !self.should_process_match_exists(database, match_id)? {
|
||||||
log::trace!("Skipping match, already parsed.");
|
log::trace!("Skipping match, already parsed.");
|
||||||
return Ok((match_id, None))
|
return Ok((match_id, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
let datetime = self.get_match_datetime(&r#match)?;
|
let datetime = self.get_match_datetime(&r#match)?;
|
||||||
|
@ -675,12 +675,12 @@ impl BroochService {
|
||||||
|
|
||||||
if !self.should_process_match_players(&players) {
|
if !self.should_process_match_players(&players) {
|
||||||
log::trace!("Skipping match, not enough players.");
|
log::trace!("Skipping match, not enough players.");
|
||||||
return Ok((match_id, None))
|
return Ok((match_id, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.should_process_match_imp(&players, &timedelta) {
|
if !self.should_process_match_imp(&players, &timedelta) {
|
||||||
log::trace!("Skipping match, IMP is not ready.");
|
log::trace!("Skipping match, IMP is not ready.");
|
||||||
return Ok((match_id, None))
|
return Ok((match_id, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
players.sort_unstable_by_key(|a| Self::numberify_role_lane(&a.role, &a.lane));
|
players.sort_unstable_by_key(|a| Self::numberify_role_lane(&a.role, &a.lane));
|
||||||
|
|
|
@ -17,10 +17,10 @@ pub trait RoyalnetService {
|
||||||
match result {
|
match result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Service exited with error: {e:?}.")
|
log::error!("Service exited with error: {e:?}.")
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::debug!("Service exited successfully!")
|
log::debug!("Service exited successfully!")
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let backoff_secs = backoff.as_secs();
|
let backoff_secs = backoff.as_secs();
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl FromStr for DiarioArgs {
|
||||||
.map(|s| s.as_str().to_owned());
|
.map(|s| s.as_str().to_owned());
|
||||||
|
|
||||||
DiarioArgs { warning, quote, quoted, context }
|
DiarioArgs { warning, quote, quoted, context }
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
let warning = None;
|
let warning = None;
|
||||||
let quote = s.to_string();
|
let quote = s.to_string();
|
||||||
|
@ -56,7 +56,7 @@ impl FromStr for DiarioArgs {
|
||||||
let context = None;
|
let context = None;
|
||||||
|
|
||||||
DiarioArgs { warning, quote, quoted, context }
|
DiarioArgs { warning, quote, quoted, context }
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(args)
|
Ok(args)
|
||||||
|
@ -65,7 +65,8 @@ impl FromStr for DiarioArgs {
|
||||||
|
|
||||||
impl TelegramWrite for Diario {
|
impl TelegramWrite for Diario {
|
||||||
fn write_telegram<T>(&self, f: &mut T) -> Result<(), Error>
|
fn write_telegram<T>(&self, f: &mut T) -> Result<(), Error>
|
||||||
where T: Write
|
where
|
||||||
|
T: Write,
|
||||||
{
|
{
|
||||||
// Diario ID
|
// Diario ID
|
||||||
write!(f, "<code>#{}</code>", self.id)?;
|
write!(f, "<code>#{}</code>", self.id)?;
|
||||||
|
|
|
@ -181,7 +181,7 @@ const FORTUNES: [&str; 164] = [
|
||||||
|
|
||||||
struct FortuneKey {
|
struct FortuneKey {
|
||||||
today: chrono::NaiveDate,
|
today: chrono::NaiveDate,
|
||||||
author_id: teloxide::types::UserId
|
author_id: teloxide::types::UserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for FortuneKey {
|
impl Hash for FortuneKey {
|
||||||
|
|
|
@ -34,7 +34,9 @@ type CommandResult = AnyResult<()>;
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
#[command(description = "Invia messaggio di introduzione.")]
|
#[command(description = "Invia messaggio di introduzione.")]
|
||||||
Start,
|
Start,
|
||||||
#[command(description = "Visualizza l'elenco dei comandi disponibili, o mostra informazioni su uno specifico comando.")]
|
#[command(
|
||||||
|
description = "Visualizza l'elenco dei comandi disponibili, o mostra informazioni su uno specifico comando."
|
||||||
|
)]
|
||||||
Help(String),
|
Help(String),
|
||||||
#[command(description = "Mostra il tuo oroscopo di oggi.")]
|
#[command(description = "Mostra il tuo oroscopo di oggi.")]
|
||||||
Fortune,
|
Fortune,
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub async fn handler(bot: &Bot, message: &Message, roll: &str) -> CommandResult
|
||||||
.await
|
.await
|
||||||
.context("Non è stato possibile inviare la risposta.")?;
|
.context("Non è stato possibile inviare la risposta.")?;
|
||||||
|
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let re = Regex::new(r#"(?P<qty>[0-9]*)?d(?P<die>[0-9]+)(?P<modifier>[+-]+[0-9]+)?"#).unwrap();
|
let re = Regex::new(r#"(?P<qty>[0-9]*)?d(?P<die>[0-9]+)(?P<modifier>[+-]+[0-9]+)?"#).unwrap();
|
||||||
|
|
|
@ -13,10 +13,10 @@ pub async fn handler(bot: &Bot, message: &Message) -> CommandResult {
|
||||||
let author_username = match author.username.as_ref() {
|
let author_username = match author.username.as_ref() {
|
||||||
None => {
|
None => {
|
||||||
author.first_name.clone()
|
author.first_name.clone()
|
||||||
},
|
}
|
||||||
Some(username) => {
|
Some(username) => {
|
||||||
format!("@{}", &username)
|
format!("@{}", &username)
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let me = bot
|
let me = bot
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl FromStr for KeyboardCallback {
|
||||||
.parse()
|
.parse()
|
||||||
.map(|c| Self::Matchmaking(id, c))
|
.map(|c| Self::Matchmaking(id, c))
|
||||||
.context("Impossibile processare i dati.")
|
.context("Impossibile processare i dati.")
|
||||||
},
|
}
|
||||||
x => {
|
x => {
|
||||||
anyhow::bail!("Keyword sconosciuta: {x:?}")
|
anyhow::bail!("Keyword sconosciuta: {x:?}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl TelegramService {
|
||||||
database_url,
|
database_url,
|
||||||
bot,
|
bot,
|
||||||
me,
|
me,
|
||||||
notification_chat_id
|
notification_chat_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
log::trace!("Created service: {service:#?}");
|
log::trace!("Created service: {service:#?}");
|
||||||
|
@ -152,7 +152,7 @@ impl TelegramService {
|
||||||
.endpoint(KeyboardCallback::handle_self)
|
.endpoint(KeyboardCallback::handle_self)
|
||||||
)
|
)
|
||||||
.endpoint(KeyboardCallback::handle_unknown)
|
.endpoint(KeyboardCallback::handle_unknown)
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
.dependencies(
|
.dependencies(
|
||||||
dptree::deps![
|
dptree::deps![
|
||||||
|
|
|
@ -2,7 +2,8 @@ use std::fmt::{Error, Write};
|
||||||
|
|
||||||
pub trait TelegramWrite {
|
pub trait TelegramWrite {
|
||||||
fn write_telegram<T>(&self, f: &mut T) -> Result<(), Error>
|
fn write_telegram<T>(&self, f: &mut T) -> Result<(), Error>
|
||||||
where T: Write;
|
where
|
||||||
|
T: Write;
|
||||||
|
|
||||||
fn to_string_telegram(&self) -> String {
|
fn to_string_telegram(&self) -> String {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
|
@ -16,7 +17,8 @@ pub trait TelegramEscape {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> TelegramEscape for T
|
impl<T> TelegramEscape for T
|
||||||
where String: From<T>
|
where
|
||||||
|
String: From<T>,
|
||||||
{
|
{
|
||||||
fn escape_telegram_html(self) -> String {
|
fn escape_telegram_html(self) -> String {
|
||||||
String::from(self)
|
String::from(self)
|
||||||
|
|
Loading…
Reference in a new issue