diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index d6d2c0be0592dd1d12d5f95ab1d31dea5b6cd13a..66b9b177410915b3bea8f52650f8d9c152c5a6c8 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -37,10 +37,6 @@ spec: - name: http containerPort: {{ default 8000 .Values.env.BOT_SERVER_PORT }} protocol: TCP - livenessProbe: - httpGet: - path: /health - port: http readinessProbe: httpGet: path: /health diff --git a/src/bot/handlers/fun/blyaficator.rs b/src/bot/handlers/fun/blyaficator.rs index c8660f897be6a983b92788f7a646a733bdc22b2c..e6e41cfb727219c137aa60cb5a035361e1375dff 100644 --- a/src/bot/handlers/fun/blyaficator.rs +++ b/src/bot/handlers/fun/blyaficator.rs @@ -2,7 +2,7 @@ use crate::{ bot::handlers::Handler, utils::{inter_join::RandomIntersperse, messages::get_message}, }; -use grammers_client::{Client, Update}; +use grammers_client::{Client, InputMessage, Update}; const BLYA_WORDS: &[&str] = &[", блÑ,", ", Ñука,", ", ёбаный рот,", ", охуеть конечно,"]; @@ -32,7 +32,9 @@ impl Handler for Blyaficator { // If the text was blyaficated we send it as a reply. if let Some(blyficated) = maybe_blyaficated { - message.reply(blyficated).await?; + message + .reply(InputMessage::from(blyficated).silent(true)) + .await?; } } Ok(()) diff --git a/src/bot/handlers/fun/mod.rs b/src/bot/handlers/fun/mod.rs index 6645e922dd63e1240f2199048dc852e96a2e7a10..8d24276ed9b86f90ce272366a8ef75505d39950c 100644 --- a/src/bot/handlers/fun/mod.rs +++ b/src/bot/handlers/fun/mod.rs @@ -1,2 +1,3 @@ pub mod blyaficator; pub mod greeter; +pub mod rotator; diff --git a/src/bot/handlers/fun/rotator.rs b/src/bot/handlers/fun/rotator.rs new file mode 100644 index 0000000000000000000000000000000000000000..db4511c9a159c989b0c82eabcd586014be2a094d --- /dev/null +++ b/src/bot/handlers/fun/rotator.rs @@ -0,0 +1,49 @@ +use std::time::Duration; + +use grammers_client::{types::Message, Client, InputMessage, Update}; + +use crate::{bot::handlers::Handler, utils::messages::get_message}; + +#[derive(Clone)] +pub struct Rotator; + +async fn rotator(replied_message: Message, text: String) { + let mut skip = 1; + let start = std::time::SystemTime::now(); + let mut current = std::time::SystemTime::now(); + while current + .duration_since(start) + .map(|dur| dur.as_secs()) + .unwrap_or(100) + < 10 + { + let rotated = text + .chars() + .cycle() + .skip(skip) + .take(text.len()) + .collect::<String>(); + skip += 1; + if skip == rotated.len() { + skip = 0; + } + replied_message.edit(rotated).await.ok(); + current = std::time::SystemTime::now(); + tokio::time::sleep(Duration::from_millis(200)).await; + } + replied_message.delete().await.ok(); +} + +#[async_trait::async_trait] +impl Handler for Rotator { + async fn react(&self, _: &Client, update: &Update) -> anyhow::Result<()> { + let Some(message) = get_message(update) else{ + return Ok(()); + }; + if let Some(text) = message.text().strip_prefix(".rl").map(str::trim) { + let replied_message = message.reply(InputMessage::from(text).silent(true)).await?; + tokio::spawn(rotator(replied_message, text.to_string())); + } + Ok(()) + } +} diff --git a/src/bot/main.rs b/src/bot/main.rs index c05bb8decfd4460c04ad19e92c560de8e952e361..2459f032b92fd02ab5edaee9a127ab4143294720 100644 --- a/src/bot/main.rs +++ b/src/bot/main.rs @@ -20,7 +20,7 @@ use super::{ get_chat_id::GetChatId, help::Help, }, - fun::{blyaficator::Blyaficator, greeter::Greeter}, + fun::{blyaficator::Blyaficator, greeter::Greeter, rotator::Rotator}, Handler, }, }; @@ -104,12 +104,17 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> { .add_filter(TextFilter(&[".cid"], TextMatchMethod::IMatches)), // Make Ð±Ð»Ñ fun again. FilteredHandler::new(Blyaficator) + .add_filter(SilentFilter) .add_filter(TextFilter(&[".bl"], TextMatchMethod::IStartsWith)), // Handler for converting currecies. FilteredHandler::new(CurrencyConverter::new()?) .add_filter(SilentFilter) .add_filter(ExcludedChatsFilter(args.currency_excluded_chats)) .add_filter(CurrencyTextFilter), + // Simlpe rotator. + FilteredHandler::new(Rotator) + .add_filter(SilentFilter) + .add_filter(TextFilter(&[".rl"], TextMatchMethod::IStartsWith)), ]; loop {