From fc0992c4c889120eae113cc8f4ed856a54080a38 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 6 Jul 2021 12:17:41 +0200 Subject: [PATCH] Add weekday to /next response --- src/lib.rs | 2 +- src/main.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 76806df..bbecfad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,7 +78,7 @@ pub fn error>(msg: S) -> Error { } pub async fn send_message>(msg: S) -> Result<(), Error> { - API.send(SendMessage::new(*OWNER, msg.into())).await?; + API.send(SendMessage::new(*OWNER, msg.into()).parse_mode(ParseMode::MarkdownV2)).await?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index e8704bb..514481a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ async fn process_one(update: Update, context: &mut Context) -> Result<(), Error> let now = Local::now(); println!("[{}-{:02}-{:02} {:02}:{:02}] Receiving msg {:?}", now.year(), now.month(), now.day(), now.hour(), now.minute(), message); if message.from.id != *OWNER { - // don't handle message + println!("ignoring, not sent by authorized user"); return Ok(()); } @@ -239,22 +239,35 @@ async fn command_next() -> Result<(), Error> { all.sort_by_key(|x| x.time()); let mut printed = 0; let now = Local::now(); - let mut buf = String::new(); + let mut buf = "```\n".to_owned(); for x in all { let time = x.time(); if time < now { continue; } - buf += &format!("{} {}\n", time.format("%Y-%m-%d %H:%M").to_string(), x.description()); + buf += &format!("{} {} {}\n", weekday_to_name(time.weekday()), time.format("%Y-%m-%d %H:%M").to_string(), x.description()); printed += 1; if printed >= 10 { break; } } + buf += "```\n"; send_message(buf).await?; Ok(()) } +fn weekday_to_name(wd: Weekday) -> &'static str { + match wd { + Weekday::Mon => "Mo", + Weekday::Tue => "Di", + Weekday::Wed => "Mi", + Weekday::Thu => "Do", + Weekday::Fri => "Fr", + Weekday::Sat => "Sa", + Weekday::Sun => "So", + } +} + enum EventOrTask { Event(UsefulEvent), Task(UsefulTask)