Made subs works
All checks were successful
Rust Docker Build / docker (push) Successful in 1h11m56s

This commit is contained in:
AB from home.homenet
2025-10-19 15:23:17 +03:00
parent dae787657c
commit c6892b1a73
11 changed files with 87 additions and 49 deletions

View File

@@ -9,6 +9,7 @@ pub use types::*;
use teloxide::{prelude::*, types::CallbackQuery};
use crate::database::DatabaseManager;
use crate::config::AppConfig;
/// Handle bot commands
pub async fn handle_command(
@@ -16,6 +17,7 @@ pub async fn handle_command(
msg: Message,
cmd: Command,
db: DatabaseManager,
app_config: AppConfig,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let chat_id = msg.chat.id;
let from = &msg.from.ok_or("No user info")?;
@@ -78,6 +80,7 @@ pub async fn handle_message(
bot: Bot,
msg: Message,
db: DatabaseManager,
_app_config: AppConfig,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let chat_id = msg.chat.id;
let from = msg.from.as_ref().ok_or("No user info")?;
@@ -95,6 +98,7 @@ pub async fn handle_callback_query(
bot: Bot,
q: CallbackQuery,
db: DatabaseManager,
app_config: AppConfig,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if let Some(data) = &q.data {
if let Some(callback_data) = CallbackData::parse(data) {
@@ -106,7 +110,7 @@ pub async fn handle_callback_query(
handle_my_configs_edit(bot, &q, &db).await?;
}
CallbackData::SubscriptionLink => {
handle_subscription_link(bot, &q, &db).await?;
handle_subscription_link(bot, &q, &db, &app_config).await?;
}
CallbackData::Support => {
handle_support(bot, &q).await?;

View File

@@ -673,6 +673,7 @@ pub async fn handle_subscription_link(
bot: Bot,
q: &CallbackQuery,
db: &DatabaseManager,
app_config: &crate::config::AppConfig,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let from = q.from.clone();
let telegram_id = from.id.0 as i64;
@@ -683,8 +684,7 @@ pub async fn handle_subscription_link(
let user_repo = UserRepository::new(db.connection());
if let Ok(Some(user)) = user_repo.get_by_telegram_id(telegram_id).await {
// Generate subscription URL
let base_url = std::env::var("BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string());
let subscription_url = format!("{}/sub/{}", base_url, user.id);
let subscription_url = format!("{}/sub/{}", app_config.web.base_url, user.id);
let message = match lang {
Language::Russian => {