2022-12-22 17:29:13 +00:00
|
|
|
#![cfg_attr(not(feature = "toml"), allow(dead_code))]
|
|
|
|
#![cfg_attr(not(feature = "toml"), allow(unused_imports))]
|
|
|
|
mod register;
|
|
|
|
|
|
|
|
use futures_util::TryStreamExt;
|
|
|
|
use log::{as_serde, info};
|
2022-12-22 18:19:49 +00:00
|
|
|
use mastodon_async::Result;
|
2022-12-22 17:29:13 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "toml")]
|
2022-12-30 14:59:39 +00:00
|
|
|
async fn run() -> Result<()> {
|
2022-12-22 17:29:13 +00:00
|
|
|
use log::warn;
|
|
|
|
|
|
|
|
femme::with_level(log::LevelFilter::Info);
|
|
|
|
let mastodon = register::get_mastodon_data().await?;
|
|
|
|
let stream = mastodon.stream_user().await?;
|
|
|
|
info!("watching mastodon for events. This will run forever, press Ctrl+C to kill the program.");
|
|
|
|
stream
|
2023-02-13 16:54:49 +00:00
|
|
|
.try_for_each(|(event, _client)| async move {
|
2022-12-22 17:29:13 +00:00
|
|
|
match event {
|
|
|
|
// fill in how you want to handle events here.
|
|
|
|
_ => warn!(event = as_serde!(event); "unrecognized event received"),
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:59:39 +00:00
|
|
|
#[cfg(all(feature = "toml", feature = "mt"))]
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
run().await
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(all(feature = "toml", not(feature = "mt")))]
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
run().await
|
|
|
|
}
|
|
|
|
|
2022-12-22 17:29:13 +00:00
|
|
|
#[cfg(not(feature = "toml"))]
|
|
|
|
fn main() {
|
|
|
|
println!(
|
|
|
|
"examples require the `toml` feature, run this command for this example:\n\ncargo run \
|
|
|
|
--example log_events --features toml\n"
|
|
|
|
);
|
|
|
|
}
|