use ferogram::Client;
use ferogram::filters::{
Dispatcher, album, channel, command, forwarded, group, media, photo, private, reply,
text_contains,
};
const API_ID: i32 = 0; const API_HASH: &str = "";
#[tokio::main]
async fn main() {
if let Err(e) = run().await {
eprintln!("error: {e}");
std::process::exit(1);
}
}
async fn run() -> Result<(), Box<dyn std::error::Error>> {
if API_ID == 0 || API_HASH.is_empty() {
eprintln!("Fill in API_ID and API_HASH at the top of filters_showcase.rs");
std::process::exit(1);
}
let (client, _shutdown) = Client::quick_connect("filters.session", API_ID, API_HASH).await?;
let me = client.get_me().await?;
println!(
"Bot running as @{}",
me.username.as_deref().unwrap_or("unknown")
);
let mut dp = Dispatcher::new();
dp.on_message(command("start"), |msg| async move {
msg.reply("Hello! I'm a filter showcase bot.").await.ok();
});
dp.on_message(command("help"), |msg| async move {
msg.reply(
"Commands: /start /help\n\
Also try: sending a photo, forwarded message, or album.",
)
.await
.ok();
});
dp.on_message(private() & text_contains("hello"), |msg| async move {
msg.reply("Hi! (private chat)").await.ok();
});
dp.on_message(group() & command("hi"), |msg| async move {
msg.reply("Hey group!").await.ok();
});
dp.on_message(photo(), |msg| async move {
msg.reply("Nice photo!").await.ok();
});
dp.on_message(media() & !photo(), |msg| async move {
msg.reply("Got a file!").await.ok();
});
dp.on_message(album(), |msg| async move {
msg.reply("Got an album!").await.ok();
});
dp.on_message(forwarded(), |msg| async move {
msg.reply("That looks forwarded.").await.ok();
});
dp.on_message(reply(), |msg| async move {
msg.reply("That's a reply.").await.ok();
});
dp.on_message(channel(), |msg| async move {
println!("Channel post received.");
let _ = msg;
});
dp.on_message(group() & forwarded(), |msg| async move {
msg.reply("Forwarded in a group.").await.ok();
});
let mut stream = client.stream_updates();
while let Some(upd) = stream.next().await {
dp.dispatch(upd).await;
}
Ok(())
}