diff --git a/Cargo.toml b/Cargo.toml index c49d561..b140f21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ color = ["tracing-subscriber/ansi"] [dependencies] # bot -teloxide = { version = "0.11.0", default-features = false, features = ["macros", "auto-send","ctrlc_handler","rustls","nightly", "webhooks-axum"] } +teloxide = { version = "0.11.1", default-features = false, features = ["macros", "auto-send","ctrlc_handler","rustls","nightly", "webhooks-axum"] } teloxide-core = { version = "0.8.0", default-features = false, features = ["rustls", "cache_me"] } teloxide-macros = "0.7.0" @@ -25,32 +25,33 @@ singleton = { branch= "master", git = "https://github.com/Itsusinn/singleton-rs. # singleton = { path = "/code/singleton-rs" } # logging -tracing = "0.1.36" -tracing-subscriber = { version = "0.3.15", default-features = false, features = ["tracing-log", "std", "local-time","fmt"] } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.16", default-features = false, features = ["tracing-log", "std", "local-time","fmt"] } colored = "2.0.0" -time = { version = "0.3.14", features = ["macros", "local-offset"] } -chrono = "0.4.22" +time = { version = "0.3.17", features = ["macros", "local-offset"] } +chrono = "0.4.23" # serialization -serde = { version = "1.0.144", default-features = false, features = ["derive","rc"] } -serde_json = "1.0.85" -serde_yaml = "0.9.13" +serde = { version = "1.0.147", default-features = false, features = ["derive","rc"] } +serde_json = "1.0.87" +serde_yaml = "0.9.14" # asynchronous -tokio = { version = "1.21.1", default-features = false, features = ["macros","signal","rt-multi-thread"] } -tokio-stream = "0.1.10" -futures-util = "0.3.24" -async-trait = "0.1.57" -reqwest = { version = "0.11.11", default-features = false, features = ["rustls","rustls-tls-native-roots","stream","multipart", "blocking"] } +tokio = { version = "1.21.2", default-features = false, features = ["macros","signal","rt-multi-thread"] } +tokio-stream = "0.1.11" +futures-util = "0.3.25" +async-trait = "0.1.58" +reqwest = { version = "0.11.13", default-features = false, features = ["rustls","rustls-tls-native-roots","stream","multipart", "blocking"] } # error handling -thiserror = "1.0.35" +thiserror = "1.0.37" color-eyre = "0.6.2" tracing-error = "0.2.0" color-spantrace = "0.2.0" # encoding and decoding base64-url = "1.4.13" +image = { version = "0.24.5", features = ["webp-encoder"] } # hex = "0.4" # crypto @@ -58,15 +59,15 @@ aes-gcm = { version = "0.10.1", features = ["std"] } # tools dashmap = { version = "5.4.0", features = ["serde"] } -once_cell = "1.15.0" -educe = { version = "0.4.19", default-features = false, features = ["Default"] } -arcstr = { version = "1.1.4", features = ["serde"] } +once_cell = "1.16.0" +educe = { version = "0.4.20", default-features = false, features = ["Default"] } +arcstr = { version = "1.1.5", features = ["serde"] } yaml-rust = "0.4.5" linked-hash-map = "0.5.6" either = "1.8.0" mime = "0.3.16" infer = "0.11.0" -uuid = "1.2.1" +uuid = "1.2.2" # self_update = { path = "/home/itsusinn/Workspace/Clone/self_update", features = ["archive-zip","compression-zip-deflate","rustls"] } self_update = { branch = "proxy", git = "https://github.com/Itsusinn/self_update.git", default-features = false, features = ["archive-zip","compression-zip-deflate","rustls"] } diff --git a/src/bot.rs b/src/bot.rs index bf2a3e5..903779b 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use arcstr::ArcStr; use color_eyre::eyre::Result; use lateinit::LateInit; -use mesagisto_client::{cache::CACHE, net::NET, res::RES}; +use mesagisto_client::{net::NET, res::RES}; use teloxide::{ adaptors::DefaultParseMode, payloads::{SendAnimationSetters, SendMessageSetters, SendPhotoSetters}, @@ -45,7 +45,7 @@ impl TgBot { let tmp_path = RES.tmp_path(&id_str); let url = self.get_url_by_path(path); NET.download(&url, &tmp_path).await?; - CACHE.put_file(uid, &tmp_path).await?; + RES.put_file(uid, &tmp_path).await?; Ok(()) } @@ -109,7 +109,7 @@ impl TgBot { .expect("file read failed when refering file type") .expect("Unkown file type"); let is_gif = "gif" == kind.extension(); - + let is_webp = "webp" == kind.extension(); let result = if is_gif { let photo = photo.clone().file_name(format!( "{:?}.gif", @@ -123,11 +123,15 @@ impl TgBot { send.await } } else { - let send = self.inner.send_photo(chat_id, photo.clone()); - if let Some(reply) = reply { - send.reply_to_message_id(MessageId(reply)).await + if is_webp { + self.inner.send_sticker(chat_id, photo.clone()).await } else { - send.await + let send = self.inner.send_photo(chat_id, photo.clone()); + if let Some(reply) = reply { + send.reply_to_message_id(MessageId(reply)).await + } else { + send.await + } } }; diff --git a/src/commands/manage.rs b/src/commands/manage.rs index 11d4620..398736d 100644 --- a/src/commands/manage.rs +++ b/src/commands/manage.rs @@ -1,8 +1,5 @@ use color_eyre::eyre::Result; -use teloxide::{ - prelude::*, - utils::command::BotCommands -}; +use teloxide::{prelude::*, utils::command::BotCommands}; use crate::bot::BotRequester; @@ -15,7 +12,7 @@ pub enum ManageCommand { #[command(description = "Disaplay manage commands help")] ManageHelp, #[command(description = "Add a new WS Server", parse_with = "split")] - NewServer { name: String, address: String }, + NewProfile { name: String, address: String }, } impl ManageCommand { pub async fn answer(msg: Message, bot: BotRequester, cmd: ManageCommand) -> Result<()> { @@ -25,7 +22,7 @@ impl ManageCommand { .send_message(msg.chat.id, ManageCommand::descriptions().to_string()) .await?; } - ManageCommand::NewServer { name, address } => {} + ManageCommand::NewProfile { name, address } => {} } Ok(()) } diff --git a/src/config.rs b/src/config.rs index 076c38a..0f21b89 100644 --- a/src/config.rs +++ b/src/config.rs @@ -52,7 +52,11 @@ impl Config { } pub fn migrate(&self) { - self.centers.insert("mesagisto".into(), "wss://center.mesagisto.org".into()); + if !self.centers.contains_key("mesagisto".into()) { + self + .centers + .insert("mesagisto".into(), "wss://center.mesagisto.org".into()); + } } pub fn migrate_chat(&self, old_chat_id: &i64, new_chat_id: &i64) -> bool { @@ -103,5 +107,5 @@ pub struct AutoUpdateConfig { pub struct TlsConfig { #[educe(Default = false)] pub skip_verify: bool, - pub custom_cert: ArcStr -} \ No newline at end of file + pub custom_cert: ArcStr, +} diff --git a/src/dispatch.rs b/src/dispatch.rs index 8c31b45..0065bf7 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -1,9 +1,10 @@ -use crate::fl; use teloxide::prelude::*; -use crate::commands::manage::ManageCommand; -use crate::info; -use crate::{bot::BotRequester, commands::bind::BindCommand, handlers}; +use crate::{ + bot::BotRequester, + commands::{bind::BindCommand, manage::ManageCommand}, + fl, handlers, info, +}; pub async fn start(bot: &BotRequester) { let message_handler = Update::filter_message() diff --git a/src/handlers/send.rs b/src/handlers/send.rs index 3644b21..bf1fe59 100644 --- a/src/handlers/send.rs +++ b/src/handlers/send.rs @@ -99,7 +99,7 @@ pub async fn answer_common(msg: Message) -> Result<()> { id: msg.id.0.to_be_bytes().to_vec(), chain, reply, - from: target.to_be_bytes().to_vec() + from: target.to_be_bytes().to_vec(), }; let room_id = SERVER.room_id(room_address); let packet = Packet::new(room_id, message.tl())?; diff --git a/src/i18n.rs b/src/i18n.rs index 9e1ce1c..041d8e9 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -1,8 +1,7 @@ use i18n_embed::{ - fluent::{FluentLanguageLoader, fluent_language_loader}, - DesktopLanguageRequester, LanguageLoader + fluent::{fluent_language_loader, FluentLanguageLoader}, + DesktopLanguageRequester, LanguageLoader, }; - use once_cell::sync::Lazy; use rust_embed::RustEmbed; diff --git a/src/log.rs b/src/log.rs index 3f83ccd..39fba8d 100644 --- a/src/log.rs +++ b/src/log.rs @@ -28,7 +28,7 @@ pub(crate) async fn init() -> Result<()> { .with_target(true) .with_timer(tracing_subscriber::fmt::time::OffsetTime::new( time::UtcOffset::from_whole_seconds( - Local.timestamp(0, 0).offset().fix().local_minus_utc(), + Local.timestamp_opt(0, 0).unwrap().offset().fix().local_minus_utc(), ) .unwrap_or(time::UtcOffset::UTC), time::macros::format_description!( diff --git a/src/main.rs b/src/main.rs index 2790224..aa2a993 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ #![feature(let_chains)] +#![feature(trait_alias)] +#![feature(type_alias_impl_trait)] use std::ops::Deref; @@ -8,6 +10,7 @@ use futures_util::FutureExt; use locale_config::Locale; use mesagisto_client::{MesagistoConfig, MesagistoConfigBuilder}; use once_cell::sync::Lazy; +use res::TG_RES; use self_update::Status; use teloxide::{prelude::*, types::ParseMode, Bot}; @@ -32,6 +35,7 @@ mod handlers; mod i18n; mod log; mod net; +pub mod res; mod update; mod webhook; @@ -87,9 +91,9 @@ async fn run() -> Result<()> { .remote_address(CONFIG.deref().centers.to_owned()) .same_side_deliver(true) .skip_verify(CONFIG.tls.skip_verify) - .custom_cert(if CONFIG.tls.custom_cert.is_empty(){ + .custom_cert(if CONFIG.tls.custom_cert.is_empty() { None - }else{ + } else { Some(CONFIG.deref().tls.custom_cert.to_owned()) }) .proxy(if CONFIG.proxy.enable { @@ -100,7 +104,7 @@ async fn run() -> Result<()> { .build()? .apply() .await?; - + TG_RES.init().await; MesagistoConfig::packet_handler(|pkt| async { packet_handler(pkt).await }.boxed()); info!("log-boot-start", version = env!("CARGO_PKG_VERSION")); let bot = Bot::with_client(CONFIG.telegram.token.clone(), net::client_from_config())