Added .rl, fixed some messages, removed liveness probe.

This commit is contained in:
2023-02-21 22:53:31 +00:00
parent 9b6308ecc0
commit fe2a863bc5
5 changed files with 60 additions and 7 deletions

View File

@ -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

View File

@ -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(())

View File

@ -1,2 +1,3 @@
pub mod blyaficator;
pub mod greeter;
pub mod rotator;

View File

@ -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(())
}
}

View File

@ -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 {