diff --git a/Cargo.lock b/Cargo.lock index 72b33c2..601330f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -347,10 +347,12 @@ dependencies = [ name = "godette" version = "0.1.0" dependencies = [ + "lazy_static", "log", "pretty_env_logger", "teloxide", "tokio", + "url", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a615f43..b946206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,6 @@ edition = "2021" teloxide = { version = "0.11", features = ["macros", "auto-send"] } log = "0.4" pretty_env_logger = "0.4" -tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] } \ No newline at end of file +tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] } +lazy_static = "1.4.0" +url = "2.3.1" \ No newline at end of file diff --git a/src/godette.rs b/src/godette.rs index 4d57758..b607aea 100644 --- a/src/godette.rs +++ b/src/godette.rs @@ -1,9 +1,15 @@ -use teloxide::prelude::*; +use teloxide::{ + prelude::*, + types::{InlineKeyboardButton, InlineKeyboardMarkup}, +}; pub mod commands; mod handlers; +mod utils; use commands::{AdminCommand, Command}; +use url::Url; +use utils::get_text_or_empty; pub struct Godette { pub bot: Bot, } @@ -57,12 +63,23 @@ impl Godette { pub async fn message_dispatcher(bot: Bot, msg: Message) -> ResponseResult<()> { // Checking if it's a reply - let message = msg.clone(); - let reply = message.reply_to_message(); + let reply = msg.reply_to_message(); match reply { - Some(reply) => return Godette::reply_dispatcher(bot, msg, reply.to_owned()).await, + Some(reply) => { + Godette::reply_dispatcher(bot.clone(), msg.clone(), reply.to_owned()).await? + } None => (), }; + let text = utils::get_text_or_empty(&msg).to_lowercase(); + match text.find("оффтоп") { + Some(_) => { + bot.send_message(msg.chat.id, "Вот вам ссылка на оффтоп") + .reply_to_message_id(msg.id) + .reply_markup(Godette::make_offtop_keyboard()) + .await?; + } + None => (), + } Ok(()) } @@ -78,11 +95,7 @@ impl Godette { KarmaTrigger::new("👍", 1), KarmaTrigger::new("👎", -1), ]; - println!("Working on reply"); - let text = msg - .text() - .unwrap_or(msg.caption().unwrap_or_default()) - .to_string(); + let text = get_text_or_empty(&msg); println!("{:?}", text); for trigger in triggers { match text.to_lowercase().find(&trigger.text) { @@ -95,4 +108,10 @@ impl Godette { } Ok(()) } + + fn make_offtop_keyboard() -> InlineKeyboardMarkup { + let link = Url::parse("https://t.me/Godot_Engine_Offtop").unwrap(); + let button = InlineKeyboardButton::url("Godot Engine оффтоп чат".to_owned(), link); + return InlineKeyboardMarkup::new(vec![[button]]); + } } diff --git a/src/godette/utils.rs b/src/godette/utils.rs new file mode 100644 index 0000000..4d80956 --- /dev/null +++ b/src/godette/utils.rs @@ -0,0 +1,7 @@ +use teloxide::types::Message; + +pub fn get_text_or_empty(msg: &Message) -> String { + msg.text() + .unwrap_or(msg.caption().unwrap_or("")) + .to_string() +}