use std::time::{Duration, Instant};
use tbot::prelude::*;
use tokio::{prelude::*, timer::Interval};
const INTERVAL: u64 = 15;
const PLACES: [(f64, f64); 6] = [
(38.904722, -77.016389), (51.507222, -0.1275), (41.9, 12.5), (59.329444, 18.068611), (55.796389, 49.108889), (56.5, 84.966667), ];
const UPDATE_PERIOD: u32 = 3600 * 24;
fn main() {
let mut bot = tbot::bot!("BOT_TOKEN").event_loop();
bot.command("location", |context| {
let context = context.clone();
let mut places = PLACES.iter().cycle();
let location = context
.send_location(*places.next().unwrap())
.live_period(UPDATE_PERIOD)
.into_future()
.map_err(|err| {
dbg!(err);
})
.and_then(|message| {
Interval::new(Instant::now(), Duration::from_secs(INTERVAL))
.skip(1)
.zip(futures::stream::iter_ok(places))
.map_err(|err| {
dbg!(err);
})
.for_each(move |(_, place)| {
context
.edit_message_location(message.id, *place)
.into_future()
.map_err(|err| {
dbg!(err);
})
.map(|_| ())
})
})
.timeout(Duration::from_secs(UPDATE_PERIOD as u64))
.map_err(|_| ());
tbot::spawn(location);
});
bot.polling().start();
}