calendars.rs (1203B)
1 use crate::config::Config; 2 use crate::errors::Error; 3 use crate::google_calendar::list_calendars; 4 use matrix_sdk::events::room::message::MessageEventContent; 5 use matrix_sdk::events::AnyMessageEventContent; 6 use matrix_sdk::identifiers::RoomId; 7 use matrix_sdk::Client; 8 use mrsbfh::commands::command; 9 use tracing::info; 10 11 #[command(help = "`!calendars` - Displays all calendars you have.")] 12 pub async fn calendars<'a>( 13 _client: Client, 14 tx: mrsbfh::Sender, 15 _config: Config<'a>, 16 sender: String, 17 _room_id: RoomId, 18 mut _args: Vec<&str>, 19 ) -> Result<(), Error> 20 where 21 Config<'a>: mrsbfh::config::Loader + Clone, 22 { 23 // Required in case there are new things to request permissions for 24 super::do_login(sender.clone().into(), tx.clone()).await?; 25 26 let calendars = list_calendars(sender.clone()).await?; 27 info!("{:#?}", calendars); 28 for calendar in calendars.items { 29 let content = 30 AnyMessageEventContent::RoomMessage(MessageEventContent::notice_plain(format!( 31 "ID: {}, Summary: {}, Description: {:?}", 32 calendar.id, calendar.summary, calendar.description 33 ))); 34 tx.send(content).await?; 35 } 36 Ok(()) 37 }