mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-25 04:24:20 +00:00
Fix brooch conditional compiling
This commit is contained in:
parent
5c5826c7ea
commit
6f09b0153a
9 changed files with 82 additions and 79 deletions
|
@ -121,6 +121,7 @@ service_telegram = [
|
||||||
service_brooch = [
|
service_brooch = [
|
||||||
"interface_database",
|
"interface_database",
|
||||||
"interface_stratz",
|
"interface_stratz",
|
||||||
|
"teloxide",
|
||||||
"graphql_client"
|
"graphql_client"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -39,17 +39,17 @@ pub mod brooch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "service_telegram")]
|
#[cfg(any(feature = "service_telegram", feature = "service_brooch"))]
|
||||||
pub struct ChatIdConversionHack(i64);
|
pub struct ChatIdConversionHack(i64);
|
||||||
|
|
||||||
#[cfg(feature = "service_telegram")]
|
#[cfg(any(feature = "service_telegram", feature = "service_brooch"))]
|
||||||
impl From<i64> for ChatIdConversionHack {
|
impl From<i64> for ChatIdConversionHack {
|
||||||
fn from(value: i64) -> Self {
|
fn from(value: i64) -> Self {
|
||||||
Self(value)
|
Self(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "service_telegram")]
|
#[cfg(any(feature = "service_telegram", feature = "service_brooch"))]
|
||||||
impl From<ChatIdConversionHack> for teloxide::types::ChatId {
|
impl From<ChatIdConversionHack> for teloxide::types::ChatId {
|
||||||
fn from(value: ChatIdConversionHack) -> Self {
|
fn from(value: ChatIdConversionHack) -> Self {
|
||||||
Self(value.0)
|
Self(value.0)
|
||||||
|
|
|
@ -20,8 +20,6 @@ pub struct MatchmakingMessageTelegram {
|
||||||
|
|
||||||
#[cfg(feature = "service_telegram")]
|
#[cfg(feature = "service_telegram")]
|
||||||
pub(crate) mod telegram_ext {
|
pub(crate) mod telegram_ext {
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
|
@ -36,69 +34,6 @@ pub(crate) mod telegram_ext {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub enum MatchmakingTelegramKeyboardCallback {
|
|
||||||
Yes,
|
|
||||||
Plus5Min,
|
|
||||||
Plus15Min,
|
|
||||||
Plus60Min,
|
|
||||||
Maybe,
|
|
||||||
DontWait,
|
|
||||||
Cant,
|
|
||||||
Wont,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MatchmakingTelegramKeyboardCallback {
|
|
||||||
/// Create callback data representing the [MatchmakingTelegramKeyboardCallback] in the given [MatchmakingId].
|
|
||||||
pub fn callback_data(self, matchmaking_id: MatchmakingId) -> String {
|
|
||||||
matchmaking_id.callback_data(self.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inline_button(self, matchmaking_id: MatchmakingId, text: &str) -> teloxide::types::InlineKeyboardButton {
|
|
||||||
teloxide::types::InlineKeyboardButton::new(
|
|
||||||
text,
|
|
||||||
teloxide::types::InlineKeyboardButtonKind::CallbackData(
|
|
||||||
self.callback_data(matchmaking_id)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for MatchmakingTelegramKeyboardCallback {
|
|
||||||
type Err = anyhow::Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
Ok(
|
|
||||||
match s {
|
|
||||||
"yes" => Self::Yes,
|
|
||||||
"5min" => Self::Plus5Min,
|
|
||||||
"15min" => Self::Plus15Min,
|
|
||||||
"60min" => Self::Plus60Min,
|
|
||||||
"maybe" => Self::Maybe,
|
|
||||||
"dontw" => Self::DontWait,
|
|
||||||
"cant" => Self::Cant,
|
|
||||||
"wont" => Self::Wont,
|
|
||||||
x => anyhow::bail!("Unknown keyboard callback: {x:?}"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<MatchmakingTelegramKeyboardCallback> for &'static str {
|
|
||||||
fn from(value: MatchmakingTelegramKeyboardCallback) -> Self {
|
|
||||||
match value {
|
|
||||||
MatchmakingTelegramKeyboardCallback::Yes => "yes",
|
|
||||||
MatchmakingTelegramKeyboardCallback::Plus5Min => "5min",
|
|
||||||
MatchmakingTelegramKeyboardCallback::Plus15Min => "15min",
|
|
||||||
MatchmakingTelegramKeyboardCallback::Plus60Min => "60min",
|
|
||||||
MatchmakingTelegramKeyboardCallback::Maybe => "maybe",
|
|
||||||
MatchmakingTelegramKeyboardCallback::DontWait => "dontw",
|
|
||||||
MatchmakingTelegramKeyboardCallback::Cant => "cant",
|
|
||||||
MatchmakingTelegramKeyboardCallback::Wont => "wont",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MatchmakingMessageTelegram {
|
impl MatchmakingMessageTelegram {
|
||||||
/// Get all the [MatchmakingMessageTelegram] for a specific [MatchmakingId].
|
/// Get all the [MatchmakingMessageTelegram] for a specific [MatchmakingId].
|
||||||
pub fn get_all(database: &mut PgConnection, matchmaking_id: MatchmakingId) -> AnyResult<Vec<Self>> {
|
pub fn get_all(database: &mut PgConnection, matchmaking_id: MatchmakingId) -> AnyResult<Vec<Self>> {
|
||||||
|
@ -111,7 +46,7 @@ pub(crate) mod telegram_ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reply_markup(matchmaking_id: MatchmakingId) -> teloxide::types::InlineKeyboardMarkup {
|
fn reply_markup(matchmaking_id: MatchmakingId) -> teloxide::types::InlineKeyboardMarkup {
|
||||||
use MatchmakingTelegramKeyboardCallback::*;
|
use crate::services::telegram::utils::matchmaking::MatchmakingTelegramKeyboardCallback::*;
|
||||||
|
|
||||||
let button_yes = Yes.inline_button(matchmaking_id, "🔵 Ci sarò!");
|
let button_yes = Yes.inline_button(matchmaking_id, "🔵 Ci sarò!");
|
||||||
let button_5min = Plus5Min.inline_button(matchmaking_id, "🕐 +5 min");
|
let button_5min = Plus5Min.inline_button(matchmaking_id, "🕐 +5 min");
|
||||||
|
|
|
@ -6,14 +6,12 @@ use diesel::deserialize::FromSql;
|
||||||
use diesel::serialize::ToSql;
|
use diesel::serialize::ToSql;
|
||||||
|
|
||||||
pub use brooch_match::{BroochMatch, DotaMatchId};
|
pub use brooch_match::{BroochMatch, DotaMatchId};
|
||||||
pub use diario::{Diario, DiarioId};
|
pub use diario::Diario;
|
||||||
pub use discord::DiscordUserId;
|
|
||||||
pub use matchmaking_choice::MatchmakingChoice;
|
pub use matchmaking_choice::MatchmakingChoice;
|
||||||
pub use matchmaking_events::{MatchmakingEvent, MatchmakingId};
|
pub use matchmaking_events::{MatchmakingEvent, MatchmakingId};
|
||||||
pub use matchmaking_messages_telegram::{MatchmakingMessageTelegram, telegram_ext::MatchmakingTelegramKeyboardCallback};
|
pub use matchmaking_messages_telegram::MatchmakingMessageTelegram;
|
||||||
pub use matchmaking_replies::MatchmakingReply;
|
pub use matchmaking_replies::MatchmakingReply;
|
||||||
pub use steam::SteamId64;
|
pub use telegram::{TelegramUser, TelegramUserId};
|
||||||
pub use telegram::{TelegramChatId, TelegramMessageId, TelegramUser, TelegramUserId};
|
|
||||||
pub use users::{RoyalnetUser, RoyalnetUserId};
|
pub use users::{RoyalnetUser, RoyalnetUserId};
|
||||||
|
|
||||||
mod users;
|
mod users;
|
||||||
|
|
|
@ -4,12 +4,13 @@ use teloxide::payloads::AnswerCallbackQuerySetters;
|
||||||
use teloxide::requests::Requester;
|
use teloxide::requests::Requester;
|
||||||
use teloxide::types::CallbackQuery;
|
use teloxide::types::CallbackQuery;
|
||||||
|
|
||||||
use crate::interfaces::database::models::{MatchmakingChoice, MatchmakingId, MatchmakingMessageTelegram, MatchmakingReply, MatchmakingTelegramKeyboardCallback, RoyalnetUser};
|
use crate::interfaces::database::models::{MatchmakingChoice, MatchmakingId, MatchmakingMessageTelegram, MatchmakingReply, RoyalnetUser};
|
||||||
use crate::services::telegram::dependencies::interface_database::DatabaseInterface;
|
use crate::services::telegram::dependencies::interface_database::DatabaseInterface;
|
||||||
use crate::services::telegram::keyboard_callbacks::KeyboardCallbackResult;
|
use crate::services::telegram::keyboard_callbacks::KeyboardCallbackResult;
|
||||||
|
use crate::services::telegram::utils::matchmaking::MatchmakingTelegramKeyboardCallback;
|
||||||
|
|
||||||
pub async fn handler(bot: &Bot, query: CallbackQuery, matchmaking_id: MatchmakingId, callback: MatchmakingTelegramKeyboardCallback, database: &DatabaseInterface) -> KeyboardCallbackResult {
|
pub async fn handler(bot: &Bot, query: CallbackQuery, matchmaking_id: MatchmakingId, callback: MatchmakingTelegramKeyboardCallback, database: &DatabaseInterface) -> KeyboardCallbackResult {
|
||||||
use MatchmakingTelegramKeyboardCallback::*;
|
use crate::services::telegram::utils::matchmaking::MatchmakingTelegramKeyboardCallback::*;
|
||||||
|
|
||||||
let mut database = database.connect()
|
let mut database = database.connect()
|
||||||
.context("Non è stato possibile connettersi al database RYG.")?;
|
.context("Non è stato possibile connettersi al database RYG.")?;
|
||||||
|
|
|
@ -7,8 +7,9 @@ use teloxide::payloads::AnswerCallbackQuerySetters;
|
||||||
use teloxide::prelude::CallbackQuery;
|
use teloxide::prelude::CallbackQuery;
|
||||||
use teloxide::requests::Requester;
|
use teloxide::requests::Requester;
|
||||||
|
|
||||||
use crate::interfaces::database::models::{MatchmakingId, MatchmakingTelegramKeyboardCallback};
|
use crate::interfaces::database::models::MatchmakingId;
|
||||||
use crate::services::telegram::dependencies::interface_database::DatabaseInterface;
|
use crate::services::telegram::dependencies::interface_database::DatabaseInterface;
|
||||||
|
use crate::services::telegram::utils::matchmaking::MatchmakingTelegramKeyboardCallback;
|
||||||
|
|
||||||
mod matchmaking;
|
mod matchmaking;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ use super::RoyalnetService;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod dependencies;
|
mod dependencies;
|
||||||
mod keyboard_callbacks;
|
mod keyboard_callbacks;
|
||||||
mod utils;
|
pub(crate) mod utils;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TelegramService {
|
pub struct TelegramService {
|
||||||
|
|
66
src/services/telegram/utils/matchmaking.rs
Normal file
66
src/services/telegram/utils/matchmaking.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use crate::interfaces::database::models::MatchmakingId;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum MatchmakingTelegramKeyboardCallback {
|
||||||
|
Yes,
|
||||||
|
Plus5Min,
|
||||||
|
Plus15Min,
|
||||||
|
Plus60Min,
|
||||||
|
Maybe,
|
||||||
|
DontWait,
|
||||||
|
Cant,
|
||||||
|
Wont,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MatchmakingTelegramKeyboardCallback {
|
||||||
|
/// Create callback data representing the [MatchmakingTelegramKeyboardCallback] in the given [MatchmakingId].
|
||||||
|
pub fn callback_data(self, matchmaking_id: MatchmakingId) -> String {
|
||||||
|
matchmaking_id.callback_data(self.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn inline_button(self, matchmaking_id: MatchmakingId, text: &str) -> teloxide::types::InlineKeyboardButton {
|
||||||
|
teloxide::types::InlineKeyboardButton::new(
|
||||||
|
text,
|
||||||
|
teloxide::types::InlineKeyboardButtonKind::CallbackData(
|
||||||
|
self.callback_data(matchmaking_id)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for MatchmakingTelegramKeyboardCallback {
|
||||||
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
Ok(
|
||||||
|
match s {
|
||||||
|
"yes" => Self::Yes,
|
||||||
|
"5min" => Self::Plus5Min,
|
||||||
|
"15min" => Self::Plus15Min,
|
||||||
|
"60min" => Self::Plus60Min,
|
||||||
|
"maybe" => Self::Maybe,
|
||||||
|
"dontw" => Self::DontWait,
|
||||||
|
"cant" => Self::Cant,
|
||||||
|
"wont" => Self::Wont,
|
||||||
|
x => anyhow::bail!("Unknown keyboard callback: {x:?}"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MatchmakingTelegramKeyboardCallback> for &'static str {
|
||||||
|
fn from(value: MatchmakingTelegramKeyboardCallback) -> Self {
|
||||||
|
match value {
|
||||||
|
MatchmakingTelegramKeyboardCallback::Yes => "yes",
|
||||||
|
MatchmakingTelegramKeyboardCallback::Plus5Min => "5min",
|
||||||
|
MatchmakingTelegramKeyboardCallback::Plus15Min => "15min",
|
||||||
|
MatchmakingTelegramKeyboardCallback::Plus60Min => "60min",
|
||||||
|
MatchmakingTelegramKeyboardCallback::Maybe => "maybe",
|
||||||
|
MatchmakingTelegramKeyboardCallback::DontWait => "dontw",
|
||||||
|
MatchmakingTelegramKeyboardCallback::Cant => "cant",
|
||||||
|
MatchmakingTelegramKeyboardCallback::Wont => "wont",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
mod database;
|
pub mod database;
|
||||||
|
pub mod matchmaking;
|
Loading…
Reference in a new issue