diff --git a/src/interfaces/database/migrations.rs b/src/interfaces/database/migrations.rs index 8fff6a72..f1910e09 100644 --- a/src/interfaces/database/migrations.rs +++ b/src/interfaces/database/migrations.rs @@ -2,6 +2,7 @@ use anyhow::anyhow; use diesel::migration::MigrationVersion; use diesel::PgConnection; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; + use crate::utils::anyhow_result::AnyResult; const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); diff --git a/src/interfaces/database/mod.rs b/src/interfaces/database/mod.rs index 25aefc20..70e0a5de 100644 --- a/src/interfaces/database/mod.rs +++ b/src/interfaces/database/mod.rs @@ -1,3 +1,6 @@ +pub use connect::connect; +pub use migrations::migrate; + pub mod schema; pub mod models; pub mod query_prelude; @@ -6,5 +9,3 @@ mod migrations; mod macros; mod connect; -pub use connect::connect; -pub use migrations::migrate; diff --git a/src/interfaces/database/models/brooch_match.rs b/src/interfaces/database/models/brooch_match.rs index f5127924..6c5780d2 100644 --- a/src/interfaces/database/models/brooch_match.rs +++ b/src/interfaces/database/models/brooch_match.rs @@ -3,8 +3,10 @@ use diesel::{AsExpression, FromSqlRow, Identifiable, Insertable, PgConnection, Q use diesel::deserialize::FromSql; use diesel::pg::{Pg, PgValue}; use diesel::serialize::ToSql; + use crate::newtype_sql; use crate::utils::anyhow_result::AnyResult; + use super::super::schema::brooch_match; #[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable)] diff --git a/src/interfaces/database/models/diario.rs b/src/interfaces/database/models/diario.rs index 280bc7a2..c1ecbf8b 100644 --- a/src/interfaces/database/models/diario.rs +++ b/src/interfaces/database/models/diario.rs @@ -1,7 +1,9 @@ use diesel::{Identifiable, Insertable, Queryable, Selectable}; use diesel::pg::Pg; + use crate::interfaces::database::models::users::RoyalnetUserId; use crate::newtype_sql; + use super::super::schema::diario; #[derive(Debug, Clone, PartialEq, Insertable)] diff --git a/src/interfaces/database/models/discord.rs b/src/interfaces/database/models/discord.rs index 0343ee84..f2ff7b22 100644 --- a/src/interfaces/database/models/discord.rs +++ b/src/interfaces/database/models/discord.rs @@ -1,6 +1,8 @@ use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable}; use diesel::pg::Pg; + use crate::newtype_sql; + use super::super::schema::discord; use super::users::{RoyalnetUser, RoyalnetUserId}; diff --git a/src/interfaces/database/models/matchmaking_events.rs b/src/interfaces/database/models/matchmaking_events.rs index 4f4b924e..6664591e 100644 --- a/src/interfaces/database/models/matchmaking_events.rs +++ b/src/interfaces/database/models/matchmaking_events.rs @@ -3,8 +3,10 @@ use diesel::{AsExpression, FromSqlRow, Identifiable, Insertable, PgConnection, Q use diesel::deserialize::FromSql; use diesel::pg::{Pg, PgValue}; use diesel::serialize::ToSql; + use crate::newtype_sql; use crate::utils::anyhow_result::AnyResult; + use super::super::schema::matchmaking_events; #[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable)] @@ -19,8 +21,6 @@ pub struct MatchmakingEvent { impl MatchmakingEvent { /// Create a new [MatchmakingEvent]. pub fn create(database: &mut PgConnection, text: &str, starts_at: &chrono::DateTime) -> AnyResult { - use crate::interfaces::database::query_prelude::*; - insert_into(matchmaking_events::table) .values(&( matchmaking_events::text.eq(text), @@ -32,8 +32,6 @@ impl MatchmakingEvent { /// Retrieve a [MatchmakingEvent] from the database, given its [MatchmakingId]. pub fn get(database: &mut PgConnection, matchmaking_id: MatchmakingId) -> AnyResult { - use crate::interfaces::database::query_prelude::*; - matchmaking_events::table .filter(matchmaking_events::id.eq(matchmaking_id.0)) .get_result::(database) diff --git a/src/interfaces/database/models/matchmaking_messages_telegram.rs b/src/interfaces/database/models/matchmaking_messages_telegram.rs index 66868efc..d81d2fbb 100644 --- a/src/interfaces/database/models/matchmaking_messages_telegram.rs +++ b/src/interfaces/database/models/matchmaking_messages_telegram.rs @@ -1,7 +1,9 @@ use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable}; use diesel::pg::Pg; + use crate::interfaces::database::models::MatchmakingId; use crate::interfaces::database::models::telegram::{TelegramChatId, TelegramMessageId}; + use super::matchmaking_events::MatchmakingEvent; use super::super::schema::matchmaking_messages_telegram; @@ -20,20 +22,24 @@ pub struct MatchmakingMessageTelegram { pub(crate) mod telegram_ext { use std::cmp::Ordering; use std::str::FromStr; + use anyhow::Context; use chrono::DateTime; use chrono::Local; - use matchmaking_messages_telegram::star; - use super::*; use diesel::PgConnection; - use teloxide::payloads::SendMessageSetters; use teloxide::payloads::EditMessageTextSetters; + use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::ParseMode; + + use matchmaking_messages_telegram::star; + use crate::interfaces::database::models::{MatchmakingChoice, MatchmakingId, MatchmakingReply, RoyalnetUser, TelegramUser}; use crate::utils::anyhow_result::AnyResult; use crate::utils::telegram_string::TelegramEscape; + use super::*; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MatchmakingTelegramKeyboardCallback { Yes, diff --git a/src/interfaces/database/models/matchmaking_replies.rs b/src/interfaces/database/models/matchmaking_replies.rs index d7bd1d68..99db8786 100644 --- a/src/interfaces/database/models/matchmaking_replies.rs +++ b/src/interfaces/database/models/matchmaking_replies.rs @@ -1,9 +1,12 @@ use std::ops::Add; + use anyhow::Context; use diesel::{Associations, Identifiable, Insertable, PgConnection, Queryable, Selectable}; use diesel::pg::Pg; + use crate::interfaces::database::models::{MatchmakingId, RoyalnetUserId, TelegramUser}; use crate::utils::anyhow_result::AnyResult; + use super::matchmaking_choice::MatchmakingChoice; use super::matchmaking_events::MatchmakingEvent; use super::super::schema::matchmaking_replies; @@ -24,8 +27,7 @@ pub struct MatchmakingReply { impl MatchmakingReply { pub fn get_all_telegram(database: &mut PgConnection, matchmaking_id: MatchmakingId) -> AnyResult> { - use crate::interfaces::database::query_prelude::*; - use schema::{matchmaking_replies, users, telegram}; + use schema::{matchmaking_replies, telegram, users}; matchmaking_replies::table .filter(matchmaking_replies::matchmaking_id.eq(matchmaking_id)) @@ -36,7 +38,6 @@ impl MatchmakingReply { } pub fn set(database: &mut PgConnection, matchmaking_id: MatchmakingId, user_id: RoyalnetUserId, choice: MatchmakingChoice) -> AnyResult { - use crate::interfaces::database::query_prelude::*; use schema::matchmaking_replies; insert_into(matchmaking_replies::table) @@ -57,7 +58,6 @@ impl MatchmakingReply { } pub fn add_late_minutes(database: &mut PgConnection, matchmaking_id: MatchmakingId, user_id: RoyalnetUserId, increase_by: i32) -> AnyResult { - use crate::interfaces::database::query_prelude::*; use schema::matchmaking_replies; insert_into(matchmaking_replies::table) diff --git a/src/interfaces/database/models/mod.rs b/src/interfaces/database/models/mod.rs index b169a525..5d50e25b 100644 --- a/src/interfaces/database/models/mod.rs +++ b/src/interfaces/database/models/mod.rs @@ -5,6 +5,17 @@ use std::io::Write; use diesel::deserialize::FromSql; use diesel::serialize::ToSql; +pub use brooch_match::{BroochMatch, DotaMatchId}; +pub use diario::{Diario, DiarioId}; +pub use discord::DiscordUserId; +pub use matchmaking_choice::MatchmakingChoice; +pub use matchmaking_events::{MatchmakingEvent, MatchmakingId}; +pub use matchmaking_messages_telegram::{MatchmakingMessageTelegram, telegram_ext::MatchmakingTelegramKeyboardCallback}; +pub use matchmaking_replies::MatchmakingReply; +pub use steam::SteamId64; +pub use telegram::{TelegramChatId, TelegramMessageId, TelegramUser, TelegramUserId}; +pub use users::{RoyalnetUser, RoyalnetUserId}; + mod users; mod telegram; mod discord; @@ -16,13 +27,3 @@ mod matchmaking_replies; mod matchmaking_messages_telegram; mod matchmaking_choice; -pub use users::{RoyalnetUser, RoyalnetUserId}; -pub use telegram::{TelegramUser, TelegramChatId, TelegramMessageId, TelegramUserId}; -pub use discord::{DiscordUser, DiscordUserId}; -pub use steam::{SteamUser, SteamId64}; -pub use brooch_match::{BroochMatch, DotaMatchId}; -pub use diario::{Diario, DiarioId}; -pub use matchmaking_events::{MatchmakingEvent, MatchmakingId}; -pub use matchmaking_replies::MatchmakingReply; -pub use matchmaking_messages_telegram::{MatchmakingMessageTelegram, telegram_ext::MatchmakingTelegramKeyboardCallback}; -pub use matchmaking_choice::MatchmakingChoice; diff --git a/src/interfaces/database/models/steam.rs b/src/interfaces/database/models/steam.rs index 3be2eb60..a6439e1a 100644 --- a/src/interfaces/database/models/steam.rs +++ b/src/interfaces/database/models/steam.rs @@ -1,6 +1,8 @@ use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable}; use diesel::pg::Pg; + use crate::newtype_sql; + use super::super::schema::steam; use super::users::{RoyalnetUser, RoyalnetUserId}; diff --git a/src/interfaces/database/models/telegram.rs b/src/interfaces/database/models/telegram.rs index 2fbf2464..8fce996e 100644 --- a/src/interfaces/database/models/telegram.rs +++ b/src/interfaces/database/models/telegram.rs @@ -1,6 +1,8 @@ use diesel::{Associations, Identifiable, Insertable, Queryable, Selectable}; use diesel::pg::Pg; + use crate::newtype_sql; + use super::super::schema::telegram; use super::users::{RoyalnetUser, RoyalnetUserId}; diff --git a/src/interfaces/database/models/users.rs b/src/interfaces/database/models/users.rs index 955e4aed..787a9e20 100644 --- a/src/interfaces/database/models/users.rs +++ b/src/interfaces/database/models/users.rs @@ -2,7 +2,9 @@ use diesel::{Identifiable, Insertable, Queryable, Selectable}; use diesel::deserialize::FromSql; use diesel::pg::Pg; use diesel::serialize::ToSql; + use crate::newtype_sql; + use super::super::schema::users; #[derive(Debug, Clone, PartialEq, Identifiable, Queryable, Selectable, Insertable)] diff --git a/src/interfaces/database/query_prelude.rs b/src/interfaces/database/query_prelude.rs index d97778f7..eb026d19 100644 --- a/src/interfaces/database/query_prelude.rs +++ b/src/interfaces/database/query_prelude.rs @@ -1,10 +1,9 @@ #![allow(unused_imports)] pub use diesel::dsl::*; -pub use diesel::query_dsl::*; -pub use diesel::upsert::*; -pub use diesel::OptionalExtension; pub use diesel::ExpressionMethods; +pub use diesel::OptionalExtension; +pub use diesel::query_dsl::*; pub use diesel::SelectableHelper; -pub use super::schema; -pub use super::models; +pub use diesel::upsert::*; + diff --git a/src/interfaces/stratz/guild_matches.rs b/src/interfaces/stratz/guild_matches.rs index 4344a5a9..d52f38af 100644 --- a/src/interfaces/stratz/guild_matches.rs +++ b/src/interfaces/stratz/guild_matches.rs @@ -2,10 +2,22 @@ use graphql_client::GraphQLQuery; use reqwest::Url; -pub use super::Short; -pub use super::Long; + +pub use query::GameModeEnumType as GameMode; +pub use query::LobbyTypeEnum as LobbyType; +pub use query::MatchLaneType as Lane; +pub use query::MatchPlayerRoleType as Role; +pub use query::QueryGuild as Guild; +pub use query::QueryGuildMatches as Match; +pub use query::QueryGuildMatchesPlayers as Player; +pub use query::QueryGuildMatchesPlayersHero as Hero; +pub use query::QueryGuildMatchesPlayersStatsMatchPlayerBuffEvent as Buff; +pub use query::QueryGuildMatchesPlayersSteamAccount as Steam; + pub use super::Byte; +pub use super::Long; pub use super::QueryError as Error; +pub use super::Short; #[derive(graphql_client::GraphQLQuery)] #[graphql( @@ -18,17 +30,6 @@ struct Query; pub type QueryResponse = graphql_client::Response; pub type QueryResult = Result; -pub use query::LobbyTypeEnum as LobbyType; -pub use query::GameModeEnumType as GameMode; -pub use query::MatchLaneType as Lane; -pub use query::MatchPlayerRoleType as Role; -pub use query::QueryGuild as Guild; -pub use query::QueryGuildMatches as Match; -pub use query::QueryGuildMatchesPlayers as Player; -pub use query::QueryGuildMatchesPlayersHero as Hero; -pub use query::QueryGuildMatchesPlayersSteamAccount as Steam; -pub use query::QueryGuildMatchesPlayersStatsMatchPlayerBuffEvent as Buff; - pub async fn query(client: &reqwest::Client, url: Url, guild_id: i64) -> QueryResult { log::debug!("Querying guild_matches of guild {guild_id}..."); log::trace!("Using client: {client:?}"); diff --git a/src/services/brooch/mod.rs b/src/services/brooch/mod.rs index a02432fd..3c8a0774 100644 --- a/src/services/brooch/mod.rs +++ b/src/services/brooch/mod.rs @@ -1,20 +1,22 @@ use std::cmp::PartialEq; use std::time::Duration; + use anyhow::Context; use chrono::{DateTime, Local, TimeDelta, TimeZone}; -use diesel::{PgConnection}; +use diesel::PgConnection; use reqwest::Url; use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{ChatId, LinkPreviewOptions, Message}; use tokio::time::sleep; + use crate::interfaces::database; use crate::interfaces::database::models::{BroochMatch, DotaMatchId, TelegramUserId}; -use crate::services::RoyalnetService; -use crate::utils::anyhow_result::AnyResult; use crate::interfaces::stratz::{Byte, guild_matches, Short}; use crate::interfaces::stratz::guild_matches::{GameMode, Lane, LobbyType, Match, Player, Role, Steam}; +use crate::services::RoyalnetService; +use crate::utils::anyhow_result::AnyResult; use crate::utils::telegram_string::TelegramEscape; #[derive(Debug, Clone)] @@ -434,7 +436,7 @@ impl BroochService { fn get_player_telegram_id(&self, database: &mut PgConnection, player_steam: Steam) -> AnyResult> { use diesel::prelude::*; use diesel::{ExpressionMethods, QueryDsl}; - use crate::interfaces::database::schema::{steam, users, telegram}; + use crate::interfaces::database::schema::{steam, telegram, users}; use crate::interfaces::database::models::TelegramUser; log::trace!("Getting player's Steam name..."); diff --git a/src/services/mod.rs b/src/services/mod.rs index df3c3f98..0d90bb92 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -1,5 +1,7 @@ use std::time::Duration; + use tokio::time::sleep; + use crate::utils::anyhow_result::AnyResult; #[allow(dead_code)] diff --git a/src/services/telegram/commands/answer.rs b/src/services/telegram/commands/answer.rs index bb7c0f43..286c9902 100644 --- a/src/services/telegram/commands/answer.rs +++ b/src/services/telegram/commands/answer.rs @@ -1,11 +1,12 @@ -use anyhow::{Context}; +use anyhow::Context; use rand::SeedableRng; use rand::seq::SliceRandom; use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::prelude::{Message, Requester}; use teloxide::types::ReplyParameters; -use crate::services::telegram::commands::{CommandResult}; + +use crate::services::telegram::commands::CommandResult; // Cerchiamo di tenere bilanciate le tre colonne, o almeno le prime due. // Se avete un'idea ma metterebbe troppe opzioni in un'unica categoria, mettetela sotto commento. diff --git a/src/services/telegram/commands/cat.rs b/src/services/telegram/commands/cat.rs index 556c9c9c..fc66c5b2 100644 --- a/src/services/telegram/commands/cat.rs +++ b/src/services/telegram/commands/cat.rs @@ -1,12 +1,12 @@ use anyhow::Context; use reqwest::Url; +use serde::Deserialize; use teloxide::Bot; use teloxide::payloads::SendPhotoSetters; use teloxide::requests::Requester; use teloxide::types::{InputFile, Message, ReplyParameters}; -use serde::Deserialize; -use super::{CommandResult}; +use super::CommandResult; const CAT_API_URL: &str = "https://api.thecatapi.com/v1/images/search"; diff --git a/src/services/telegram/commands/diario.rs b/src/services/telegram/commands/diario.rs index 8c139f56..61deac4d 100644 --- a/src/services/telegram/commands/diario.rs +++ b/src/services/telegram/commands/diario.rs @@ -1,5 +1,6 @@ use std::fmt::{Error, Write}; use std::str::FromStr; + use anyhow::Context; use once_cell::sync::Lazy; use regex::Regex; @@ -7,6 +8,7 @@ use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::prelude::Requester; use teloxide::types::{Message, ParseMode, ReplyParameters}; + use crate::interfaces::database::models::Diario; use crate::interfaces::database::models::RoyalnetUser; use crate::services::telegram::commands::CommandResult; @@ -122,7 +124,6 @@ pub async fn handler(bot: &Bot, message: &Message, args: &DiarioArgs, database: }; let entry = { - use crate::interfaces::database::query_prelude::*; use schema::diario; insert_into(diario::table) diff --git a/src/services/telegram/commands/dog.rs b/src/services/telegram/commands/dog.rs index 87079d47..706d4425 100644 --- a/src/services/telegram/commands/dog.rs +++ b/src/services/telegram/commands/dog.rs @@ -1,12 +1,12 @@ use anyhow::Context; use reqwest::Url; +use serde::Deserialize; use teloxide::Bot; use teloxide::payloads::SendPhotoSetters; use teloxide::requests::Requester; use teloxide::types::{InputFile, Message, ReplyParameters}; -use serde::Deserialize; -use super::{CommandResult}; +use super::CommandResult; const DOG_API_URL: &str = "https://dog.ceo/api/breeds/image/random"; diff --git a/src/services/telegram/commands/echo.rs b/src/services/telegram/commands/echo.rs index 8e05f218..f027f1ca 100644 --- a/src/services/telegram/commands/echo.rs +++ b/src/services/telegram/commands/echo.rs @@ -3,7 +3,8 @@ use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{Message, ReplyParameters}; -use super::{CommandResult}; + +use super::CommandResult; pub async fn handler(bot: &Bot, message: &Message, text: &str) -> CommandResult { let text = format!( diff --git a/src/services/telegram/commands/fortune.rs b/src/services/telegram/commands/fortune.rs index bfcf8b95..c055b466 100644 --- a/src/services/telegram/commands/fortune.rs +++ b/src/services/telegram/commands/fortune.rs @@ -1,5 +1,6 @@ use std::hash::{Hash, Hasher}; -use anyhow::{Context}; + +use anyhow::Context; use chrono::Datelike; use rand::SeedableRng; use rand::seq::SliceRandom; @@ -7,7 +8,8 @@ use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::prelude::{Message, Requester}; use teloxide::types::ReplyParameters; -use crate::services::telegram::commands::{CommandResult}; + +use crate::services::telegram::commands::CommandResult; // Tutte le fortune devono essere positive, o almeno neutrali, per poter essere aggiunte. const FORTUNES: [&str; 164] = [ diff --git a/src/services/telegram/commands/help.rs b/src/services/telegram/commands/help.rs index 6ec35155..45f843e8 100644 --- a/src/services/telegram/commands/help.rs +++ b/src/services/telegram/commands/help.rs @@ -4,7 +4,8 @@ use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{BotCommand, Message, ParseMode, ReplyParameters}; use teloxide::utils::command::BotCommands; -use super::{CommandResult}; + +use super::CommandResult; pub async fn handler_all(bot: &Bot, message: &Message) -> CommandResult { let descriptions = super::Command::descriptions().to_string(); diff --git a/src/services/telegram/commands/matchmaking.rs b/src/services/telegram/commands/matchmaking.rs index fc7ef22b..1a63479e 100644 --- a/src/services/telegram/commands/matchmaking.rs +++ b/src/services/telegram/commands/matchmaking.rs @@ -1,10 +1,12 @@ use std::str::FromStr; + use anyhow::Context; use once_cell::sync::Lazy; use parse_datetime::parse_datetime_at_date; use regex::Regex; use teloxide::Bot; use teloxide::prelude::Message; + use crate::interfaces::database::models::MatchmakingEvent; use crate::interfaces::database::models::MatchmakingMessageTelegram; use crate::services::telegram::commands::CommandResult; diff --git a/src/services/telegram/commands/mod.rs b/src/services/telegram/commands/mod.rs index c3844daa..9ab8dd0e 100644 --- a/src/services/telegram/commands/mod.rs +++ b/src/services/telegram/commands/mod.rs @@ -2,12 +2,14 @@ // https://github.com/teloxide/teloxide/blob/master/crates/teloxide/examples/dispatching_features.rs use std::sync::Arc; + use anyhow::{Context, Error}; use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{Message, ReplyParameters}; use teloxide::utils::command::BotCommands; + use crate::services::telegram::dependencies::interface_database::DatabaseInterface; use crate::utils::anyhow_result::AnyResult; diff --git a/src/services/telegram/commands/reminder.rs b/src/services/telegram/commands/reminder.rs index 415016f8..e09d5db6 100644 --- a/src/services/telegram/commands/reminder.rs +++ b/src/services/telegram/commands/reminder.rs @@ -1,16 +1,18 @@ use std::str::FromStr; + use anyhow::Context; +use once_cell::sync::Lazy; +use parse_datetime::parse_datetime_at_date; +use regex::Regex; use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{Message, ParseMode, ReplyParameters}; -use parse_datetime::parse_datetime_at_date; -use once_cell::sync::Lazy; -use regex::Regex; + use crate::utils::telegram_string::TelegramEscape; use crate::utils::time::sleep_chrono; -use super::CommandResult; +use super::CommandResult; #[derive(Debug, Clone, PartialEq, Eq)] pub struct ReminderArgs { diff --git a/src/services/telegram/commands/roll.rs b/src/services/telegram/commands/roll.rs index cfca4c41..745d44eb 100644 --- a/src/services/telegram/commands/roll.rs +++ b/src/services/telegram/commands/roll.rs @@ -1,12 +1,13 @@ -use anyhow::{Context}; +use anyhow::Context; use rand::{Rng, SeedableRng}; +use regex::Regex; use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::prelude::{Message, Requester}; -use crate::services::telegram::commands::{CommandResult}; -use regex::Regex; use teloxide::types::ReplyParameters; +use crate::services::telegram::commands::CommandResult; + pub async fn handler(bot: &Bot, message: &Message, roll: &str) -> CommandResult { let mut rng = rand::rngs::SmallRng::from_entropy(); diff --git a/src/services/telegram/commands/start.rs b/src/services/telegram/commands/start.rs index 90ddb96c..538e2bfa 100644 --- a/src/services/telegram/commands/start.rs +++ b/src/services/telegram/commands/start.rs @@ -3,8 +3,8 @@ use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{Message, ReplyParameters}; -use super::{CommandResult}; +use super::CommandResult; pub async fn handler(bot: &Bot, message: &Message) -> CommandResult { let author = message.from.as_ref() diff --git a/src/services/telegram/commands/whoami.rs b/src/services/telegram/commands/whoami.rs index e2fc02f6..189795d4 100644 --- a/src/services/telegram/commands/whoami.rs +++ b/src/services/telegram/commands/whoami.rs @@ -3,9 +3,11 @@ use teloxide::Bot; use teloxide::payloads::SendMessageSetters; use teloxide::requests::Requester; use teloxide::types::{Message, ParseMode, ReplyParameters}; + use crate::interfaces::database::models::RoyalnetUser; use crate::services::telegram::dependencies::interface_database::DatabaseInterface; use crate::utils::telegram_string::TelegramEscape; + use super::CommandResult; pub async fn handler(bot: &Bot, message: &Message, database: &DatabaseInterface) -> CommandResult { diff --git a/src/services/telegram/dependencies/interface_database.rs b/src/services/telegram/dependencies/interface_database.rs index 130d649d..08b2beec 100644 --- a/src/services/telegram/dependencies/interface_database.rs +++ b/src/services/telegram/dependencies/interface_database.rs @@ -1,5 +1,6 @@ use anyhow::Context; use diesel::PgConnection; + use crate::utils::anyhow_result::AnyResult; #[derive(Debug, Clone)] diff --git a/src/services/telegram/keyboard_callbacks/matchmaking.rs b/src/services/telegram/keyboard_callbacks/matchmaking.rs index 9037df71..95d6571c 100644 --- a/src/services/telegram/keyboard_callbacks/matchmaking.rs +++ b/src/services/telegram/keyboard_callbacks/matchmaking.rs @@ -3,6 +3,7 @@ use teloxide::Bot; use teloxide::payloads::AnswerCallbackQuerySetters; use teloxide::requests::Requester; use teloxide::types::CallbackQuery; + use crate::interfaces::database::models::{MatchmakingChoice, MatchmakingId, MatchmakingMessageTelegram, MatchmakingReply, MatchmakingTelegramKeyboardCallback, RoyalnetUser}; use crate::services::telegram::dependencies::interface_database::DatabaseInterface; use crate::services::telegram::keyboard_callbacks::KeyboardCallbackResult; diff --git a/src/services/telegram/keyboard_callbacks/mod.rs b/src/services/telegram/keyboard_callbacks/mod.rs index 35088475..30436b7a 100644 --- a/src/services/telegram/keyboard_callbacks/mod.rs +++ b/src/services/telegram/keyboard_callbacks/mod.rs @@ -1,15 +1,17 @@ -mod matchmaking; - use std::str::FromStr; use std::sync::Arc; + use anyhow::Context; use teloxide::Bot; use teloxide::payloads::AnswerCallbackQuerySetters; use teloxide::prelude::CallbackQuery; use teloxide::requests::Requester; + use crate::interfaces::database::models::{MatchmakingId, MatchmakingTelegramKeyboardCallback}; use crate::services::telegram::dependencies::interface_database::DatabaseInterface; +mod matchmaking; + #[derive(Debug, Clone, PartialEq, Eq)] pub enum KeyboardCallback { Matchmaking(MatchmakingId, MatchmakingTelegramKeyboardCallback), diff --git a/src/services/telegram/mod.rs b/src/services/telegram/mod.rs index 1c9b7279..8015d54e 100644 --- a/src/services/telegram/mod.rs +++ b/src/services/telegram/mod.rs @@ -1,22 +1,26 @@ +use std::sync::Arc; + +use anyhow::Context; +use regex::Regex; +use teloxide::dispatching::DefaultKey; +use teloxide::dptree::entry; +use teloxide::prelude::*; +use teloxide::types::{Me, ParseMode}; + +use commands::Command; +use dependencies::interface_database::DatabaseInterface; +use keyboard_callbacks::KeyboardCallback; + +use crate::utils::anyhow_result::{AnyError, AnyResult}; +use crate::utils::telegram_string::TelegramEscape; + +use super::RoyalnetService; + mod commands; mod dependencies; mod keyboard_callbacks; mod utils; -use std::sync::Arc; -use anyhow::Context; -use teloxide::prelude::*; -use teloxide::types::{Me, ParseMode}; -use regex::Regex; -use teloxide::dispatching::DefaultKey; -use teloxide::dptree::entry; -use commands::Command; -use dependencies::interface_database::DatabaseInterface; -use keyboard_callbacks::KeyboardCallback; -use crate::utils::anyhow_result::{AnyError, AnyResult}; -use crate::utils::telegram_string::TelegramEscape; -use super::RoyalnetService; - #[derive(Debug, Clone)] pub struct TelegramService { database_url: String, diff --git a/src/services/telegram/utils/database.rs b/src/services/telegram/utils/database.rs index 385f1e6c..36841814 100644 --- a/src/services/telegram/utils/database.rs +++ b/src/services/telegram/utils/database.rs @@ -1,6 +1,7 @@ use anyhow::Context; use diesel::PgConnection; use teloxide::types::UserId; + use crate::interfaces::database::models::RoyalnetUser; use crate::utils::anyhow_result::AnyResult; diff --git a/src/utils/anyhow_result.rs b/src/utils/anyhow_result.rs index bd16333a..c1f17e2a 100644 --- a/src/utils/anyhow_result.rs +++ b/src/utils/anyhow_result.rs @@ -1 +1,2 @@ pub use anyhow::Result as AnyResult; +