tenebrous-dicebot/src/bin/dicebot.rs

31 lines
718 B
Rust
Raw Normal View History

2020-08-23 21:19:38 +00:00
use chronicle_dicebot::bot::DiceBot;
2020-04-17 05:25:13 +00:00
use tokio::select;
use tokio::signal::unix::{signal, SignalKind};
2020-04-17 05:20:54 +00:00
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2020-04-17 22:53:27 +00:00
let config_path = std::env::args()
2020-04-17 05:25:13 +00:00
.skip(1)
.next()
2020-04-17 22:53:27 +00:00
.expect("Need a config as an argument");
println!("Logging in");
let mut bot = DiceBot::from_path(config_path).await?;
2020-04-17 22:53:27 +00:00
println!("Logged in");
2020-04-17 05:20:54 +00:00
let mut sigint = signal(SignalKind::interrupt())?;
loop {
select! {
_ = sigint.recv() => {
break;
}
result = bot.sync() => {
result?;
2020-04-17 05:20:54 +00:00
}
}
}
2020-04-17 22:53:27 +00:00
println!("Logging out");
bot.logout().await
2020-04-17 05:20:54 +00:00
}