Added @all handler for groups

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2023-02-26 20:49:03 +04:00
parent 579b1daf02
commit 8b5a588770
4 changed files with 51 additions and 13 deletions

View File

@ -20,6 +20,7 @@ use super::{
currency_converter::{CurrencyConverter, CurrencyTextFilter},
get_chat_id::GetChatId,
help::Help,
notify_all::NotifyAll,
weather_forecaster::WeatherForecaster,
},
fun::{
@ -99,24 +100,23 @@ 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)),
FilteredHandler::new(Help).add_filter(TextFilter(&[".h"], TextMatchMethod::Matches)),
// Greeting my fellow humans.
FilteredHandler::new(Greeter)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(MessageDirectionFilter(MessageDirection::Incoming))
.add_filter(SilentFilter)
.add_filter(ExcludedChatsFilter(vec![me.id()]))
.add_filter(TextFilter(&["привет"], TextMatchMethod::IStartsWith))
.add_filter(TextFilter(&["привет"], TextMatchMethod::StartsWith))
.add_filter(ExcludedChatsFilter(args.excluded_chats))
.add_middleware::<MembersCount<100>>(),
// Getting chat id.
FilteredHandler::new(GetChatId)
.add_filter(TextFilter(&[".cid"], TextMatchMethod::IMatches)),
FilteredHandler::new(GetChatId).add_filter(TextFilter(&[".cid"], TextMatchMethod::Matches)),
// Make бля fun again.
FilteredHandler::new(Blyaficator)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(SilentFilter)
.add_filter(TextFilter(&[".bl"], TextMatchMethod::IStartsWith)),
.add_filter(TextFilter(&[".bl"], TextMatchMethod::StartsWith)),
// Handler for converting currecies.
FilteredHandler::new(CurrencyConverter::new()?)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
@ -127,12 +127,12 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> {
FilteredHandler::new(Rotator)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(SilentFilter)
.add_filter(TextFilter(&[".rl"], TextMatchMethod::IStartsWith)),
.add_filter(TextFilter(&[".rl"], TextMatchMethod::StartsWith)),
// Weather forecast.
FilteredHandler::new(WeatherForecaster::new()?)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(SilentFilter)
.add_filter(TextFilter(&[".w"], TextMatchMethod::IStartsWith)),
.add_filter(TextFilter(&[".w"], TextMatchMethod::StartsWith)),
// Smiley repeator.
FilteredHandler::new(Repeator)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
@ -145,12 +145,17 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> {
FilteredHandler::new(MagicBall)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(SilentFilter)
.add_filter(TextFilter(&[".mb"], TextMatchMethod::IStartsWith)),
.add_filter(TextFilter(&[".mb"], TextMatchMethod::StartsWith)),
// Random chooser.
FilteredHandler::new(Chooser)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(SilentFilter)
.add_filter(TextFilter(&[".c"], TextMatchMethod::IStartsWith)),
.add_filter(TextFilter(&[".c"], TextMatchMethod::StartsWith)),
// Notify all.
FilteredHandler::new(NotifyAll)
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
.add_filter(SilentFilter)
.add_filter(TextFilter(&["@all"], TextMatchMethod::Contains)),
];
let mut errors_count = 0;