Compare commits
2 Commits
9d707d19a8
...
feature/te
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cc17a27de | |||
| 6186436ea8 |
17
Cargo.toml
17
Cargo.toml
@ -2,7 +2,7 @@
|
|||||||
name = "altherego"
|
name = "altherego"
|
||||||
version = "0.9.9"
|
version = "0.9.9"
|
||||||
authors = ["Aleksandr Trushkin <atrushkin@outlook.com>"]
|
authors = ["Aleksandr Trushkin <atrushkin@outlook.com>"]
|
||||||
edition = "2018"
|
edition = "2024"
|
||||||
default-run = "altherego"
|
default-run = "altherego"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
@ -14,12 +14,17 @@ uuid = { version = "0.8.1", features = ["v4"] }
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.8.1"
|
env_logger = "0.8.1"
|
||||||
envconfig = "0.9.1"
|
envconfig = "0.9.1"
|
||||||
serde = "1.0.137"
|
serde = "1.0.219"
|
||||||
reqwest = { version = "0.11.10", features = ["tokio-native-tls"] }
|
reqwest = { version = "0.11.10", features = ["tokio-native-tls"] }
|
||||||
serde_json = "1.0.81"
|
serde_json = "1.0.140"
|
||||||
sqlx = { version = "0.5.13", features = ["sqlite", "runtime-tokio-native-tls", "chrono", "migrate"] }
|
sqlx = { version = "0.8.3", features = [
|
||||||
chrono = "0.4.19"
|
"sqlite",
|
||||||
anyhow = "1.0.57"
|
"runtime-tokio-native-tls",
|
||||||
|
"chrono",
|
||||||
|
"migrate",
|
||||||
|
] }
|
||||||
|
chrono = "0.4.40"
|
||||||
|
anyhow = "1.0.97"
|
||||||
async-trait = "0.1.53"
|
async-trait = "0.1.53"
|
||||||
tokio-stream = "0.1.8"
|
tokio-stream = "0.1.8"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|||||||
4
build.rs
4
build.rs
@ -14,7 +14,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("cargo:rerun-if-env-changed=GIT_REVISION");
|
println!("cargo:rerun-if-env-changed=GIT_REVISION");
|
||||||
|
|
||||||
if let Ok(data) = std::fs::read_to_string(".env") {
|
if let Ok(data) = std::fs::read_to_string(".env") {
|
||||||
data.split('\n').into_iter().for_each(|v| {
|
data.split('\n').for_each(|v| {
|
||||||
let kv: Vec<&str> = v.split('=').collect();
|
let kv: Vec<&str> = v.split('=').collect();
|
||||||
if kv.len() != 2 {
|
if kv.len() != 2 {
|
||||||
return;
|
return;
|
||||||
@ -34,7 +34,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_value_from_env(key: &str) -> Option<String> {
|
fn get_value_from_env(key: &str) -> Option<String> {
|
||||||
env::var(key).map_or_else(|_| None, Some)
|
env::var(key).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_value_from_command<I: IntoIterator<Item = S>, S: AsRef<std::ffi::OsStr>>(
|
fn get_value_from_command<I: IntoIterator<Item = S>, S: AsRef<std::ffi::OsStr>>(
|
||||||
|
|||||||
36
src/http.rs
Normal file
36
src/http.rs
Normal file
@ -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<teloxide::Bot>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/notify", format = "json")]
|
||||||
|
async fn handle_notifications(
|
||||||
|
cookies: &CookieJar<'_>,
|
||||||
|
body: Json<NotifyBody<'_>>,
|
||||||
|
bot: &State<BotContainer>,
|
||||||
|
) -> &'static str {
|
||||||
|
"oh well"
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn launch(bot: Arc<teloxide::Bot>) -> Result<(), rocket::Error> {
|
||||||
|
rocket::build()
|
||||||
|
.manage(BotContainer { bot })
|
||||||
|
.mount("/", routes![handle_notifications])
|
||||||
|
.launch()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
mod climate;
|
mod climate;
|
||||||
|
mod http;
|
||||||
mod repo;
|
mod repo;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ use climate::SelfTemperature;
|
|||||||
use envconfig::Envconfig;
|
use envconfig::Envconfig;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
dispatching::{update_listeners::AsUpdateStream, UpdateFilterExt},
|
dispatching::{UpdateFilterExt, update_listeners::AsUpdateStream},
|
||||||
dptree::di::Injectable,
|
dptree::di::Injectable,
|
||||||
filter_command,
|
filter_command,
|
||||||
payloads::SendMessage,
|
payloads::SendMessage,
|
||||||
@ -70,7 +71,7 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
let climate_client = climate::Client::new(&settings.climate_dsn);
|
let climate_client = climate::Client::new(&settings.climate_dsn);
|
||||||
|
|
||||||
let self_temp_client = {
|
let self_temp_client = {
|
||||||
let splitted: Vec<&str> = settings.hosttemp_cmd.split(' ').into_iter().collect();
|
let splitted: Vec<&str> = settings.hosttemp_cmd.split(' ').collect();
|
||||||
let (cmd, arg) = (splitted[0], splitted[1]);
|
let (cmd, arg) = (splitted[0], splitted[1]);
|
||||||
|
|
||||||
climate::SelfTemperature::new(cmd, arg)
|
climate::SelfTemperature::new(cmd, arg)
|
||||||
|
|||||||
@ -3,10 +3,10 @@ use std::str::FromStr;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
|
Executor, Pool, Sqlite,
|
||||||
sqlite::{
|
sqlite::{
|
||||||
SqliteConnectOptions, SqliteError, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous,
|
SqliteConnectOptions, SqliteError, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous,
|
||||||
},
|
},
|
||||||
Executor, Pool, Sqlite,
|
|
||||||
};
|
};
|
||||||
use teloxide::types::User;
|
use teloxide::types::User;
|
||||||
|
|
||||||
@ -50,7 +50,6 @@ impl SqliteRepo {
|
|||||||
|
|
||||||
let pool = SqlitePoolOptions::new()
|
let pool = SqlitePoolOptions::new()
|
||||||
.max_connections(config.max_conns)
|
.max_connections(config.max_conns)
|
||||||
.connect_timeout(config.timeout)
|
|
||||||
.connect_with(opts)
|
.connect_with(opts)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user