From 4cc17a27de0b24941aade735cf0c2b05823ff1d3 Mon Sep 17 00:00:00 2001 From: Aleksandr Trushkin Date: Fri, 28 Mar 2025 21:06:30 +0300 Subject: [PATCH] test build --- Cargo.toml | 19 ++++++++++++------- src/http.rs | 36 ++++++++++++++++++++++++++++++++++++ src/main.rs | 3 ++- src/repo.rs | 3 +-- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/http.rs diff --git a/Cargo.toml b/Cargo.toml index bfe4be2..78e45da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,24 +2,29 @@ name = "altherego" version = "0.9.9" authors = ["Aleksandr Trushkin "] -edition = "2018" +edition = "2024" default-run = "altherego" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] teloxide = { version = "0.12.2", features = ["macros", "auto-send"] } -tokio = {version = "1.8", features = ["full"]} +tokio = { version = "1.8", features = ["full"] } uuid = { version = "0.8.1", features = ["v4"] } log = "0.4" env_logger = "0.8.1" envconfig = "0.9.1" -serde = "1.0.137" +serde = "1.0.219" reqwest = { version = "0.11.10", features = ["tokio-native-tls"] } -serde_json = "1.0.81" -sqlx = { version = "0.5.13", features = ["sqlite", "runtime-tokio-native-tls", "chrono", "migrate"] } -chrono = "0.4.19" -anyhow = "1.0.57" +serde_json = "1.0.140" +sqlx = { version = "0.8.3", features = [ + "sqlite", + "runtime-tokio-native-tls", + "chrono", + "migrate", +] } +chrono = "0.4.40" +anyhow = "1.0.97" async-trait = "0.1.53" tokio-stream = "0.1.8" rand = "0.8.5" diff --git a/src/http.rs b/src/http.rs new file mode 100644 index 0000000..ea4eeb8 --- /dev/null +++ b/src/http.rs @@ -0,0 +1,36 @@ +#[macro_use] +extern crate rocket; + +use rocket::http::CookieJar; +use rocket::serde::{json::Json, Deserialize}; +use rocket::State; +use serde::Deserialize; + +#[derive(Debug, Deserialize)] +#[serde(crate = "rocker::serde")] +struct NotifyBody<'r> { + pub message: &'r str, +} + +struct BotContainer { + bot: Arc, +} + +#[post("/notify", format = "json")] +async fn handle_notifications( + cookies: &CookieJar<'_>, + body: Json>, + bot: &State, +) -> &'static str { + "oh well" +} + +async fn launch(bot: Arc) -> Result<(), rocket::Error> { + rocket::build() + .manage(BotContainer { bot }) + .mount("/", routes![handle_notifications]) + .launch() + .await?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index e4b4879..22ab935 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![allow(unused)] mod climate; +mod http; mod repo; mod utils; @@ -9,7 +10,7 @@ use climate::SelfTemperature; use envconfig::Envconfig; use log::{debug, info, warn}; use teloxide::{ - dispatching::{update_listeners::AsUpdateStream, UpdateFilterExt}, + dispatching::{UpdateFilterExt, update_listeners::AsUpdateStream}, dptree::di::Injectable, filter_command, payloads::SendMessage, diff --git a/src/repo.rs b/src/repo.rs index 95f63b7..6b0d651 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -3,10 +3,10 @@ use std::str::FromStr; use anyhow::Result; use log::debug; use sqlx::{ + Executor, Pool, Sqlite, sqlite::{ SqliteConnectOptions, SqliteError, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous, }, - Executor, Pool, Sqlite, }; use teloxide::types::User; @@ -50,7 +50,6 @@ impl SqliteRepo { let pool = SqlitePoolOptions::new() .max_connections(config.max_conns) - .connect_timeout(config.timeout) .connect_with(opts) .await?;