Added weather.
This commit is contained in:
@ -4,14 +4,15 @@ use crate::args::BotConfig;
|
||||
use grammers_client::{Client, Config, SignInError, Update};
|
||||
use grammers_session::Session;
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
use regex::Regex;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::{
|
||||
filters::{
|
||||
filtered_handler::FilteredHandler,
|
||||
message_fitlers::{
|
||||
ExcludedChatsFilter, MessageDirection, MessageDirectionFilter, SilentFilter,
|
||||
TextFilter, TextMatchMethod,
|
||||
ExcludedChatsFilter, MessageDirection, MessageDirectionFilter, RegexFilter,
|
||||
SilentFilter, TextFilter, TextMatchMethod,
|
||||
},
|
||||
},
|
||||
handlers::{
|
||||
@ -19,8 +20,9 @@ use super::{
|
||||
currency_converter::{CurrencyConverter, CurrencyTextFilter},
|
||||
get_chat_id::GetChatId,
|
||||
help::Help,
|
||||
weather_forecaster::WeatherForecaster,
|
||||
},
|
||||
fun::{blyaficator::Blyaficator, greeter::Greeter, rotator::Rotator},
|
||||
fun::{blyaficator::Blyaficator, greeter::Greeter, repeator::Repeator, rotator::Rotator},
|
||||
Handler,
|
||||
},
|
||||
};
|
||||
@ -90,11 +92,13 @@ async fn handle_with_log(handler: Box<dyn Handler>, client: Client, update_data:
|
||||
///
|
||||
/// Also, every available handler is defined here.
|
||||
async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> {
|
||||
let me = client.get_me().await?;
|
||||
let handlers: Vec<FilteredHandler> = vec![
|
||||
// Printing help.
|
||||
FilteredHandler::new(Help).add_filter(TextFilter(&[".h"], TextMatchMethod::IMatches)),
|
||||
// Greeting my fellow humans.
|
||||
FilteredHandler::new(Greeter)
|
||||
.add_filter(ExcludedChatsFilter(vec![me.id()]))
|
||||
.add_filter(SilentFilter)
|
||||
.add_filter(MessageDirectionFilter(MessageDirection::Incoming))
|
||||
.add_filter(TextFilter(&["привет"], TextMatchMethod::IStartsWith))
|
||||
@ -115,6 +119,16 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> {
|
||||
FilteredHandler::new(Rotator)
|
||||
.add_filter(SilentFilter)
|
||||
.add_filter(TextFilter(&[".rl"], TextMatchMethod::IStartsWith)),
|
||||
// Weather forecast.
|
||||
FilteredHandler::new(WeatherForecaster::new()?)
|
||||
.add_filter(SilentFilter)
|
||||
.add_filter(TextFilter(&[".w"], TextMatchMethod::IStartsWith)),
|
||||
// Smiley repeator.
|
||||
FilteredHandler::new(Repeator)
|
||||
.add_filter(ExcludedChatsFilter(vec![me.id()]))
|
||||
.add_filter(MessageDirectionFilter(MessageDirection::Incoming))
|
||||
.add_filter(SilentFilter)
|
||||
.add_filter(RegexFilter(Regex::new("^[)0]+$")?)),
|
||||
];
|
||||
|
||||
let mut errors_count = 0;
|
||||
@ -154,7 +168,6 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn bot_life(
|
||||
args: BotConfig,
|
||||
web_code: Arc<RwLock<Option<String>>>,
|
||||
|
Reference in New Issue
Block a user