From 76e1f873771fbd4af8a857d563c2660b1bb52642 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 18 Jul 2024 13:20:25 +0300 Subject: [PATCH] feat: add arguments to repl task list --- src/main.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4dad0f3..9bd91c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,8 +22,6 @@ use std::time::Duration; 31923 (Calendar, with Time) */ -static TASK_KIND: Lazy = Lazy::new(|| Kind::from(1621)); - static MY_KEYS: Lazy = Lazy::new(|| Keys::generate()); static CLIENT: Lazy = Lazy::new(|| Client::new(MY_KEYS.borrow().deref())); @@ -62,13 +60,9 @@ async fn main() { let timeout = Duration::from_secs(3); - let filter = Filter::new().kind(*TASK_KIND); + let filter = Filter::new(); let sub_id: SubscriptionId = CLIENT.subscribe(vec![filter.clone()], None).await; - for argument in args().skip(1) { - let _ = send(&argument, &[]).await; - } - repl().await; println!("Finding existing events"); @@ -99,22 +93,22 @@ async fn main() { } fn make_event(text: &str, tags: &[Tag]) -> Event { - EventBuilder::new(*TASK_KIND, text, tags.to_vec()) + EventBuilder::new(Kind::from(1621), text, tags.to_vec()) .to_event(&MY_KEYS) .unwrap() } -async fn send(text: &str, tags: &[Tag]) -> (Event, Result) { - println!("Sending {}", text); - let event = EventBuilder::new(*TASK_KIND, text, tags.to_vec()) - .to_event(&MY_KEYS) - .unwrap(); - let result = CLIENT.send_event(event.clone()).await; - return (event, result); -} - async fn repl() { let mut tasks: HashMap = HashMap::new(); + let add_task = + |tasks: &mut HashMap, event: Event| tasks.insert(event.id, Task::new(event)); + for argument in args().skip(1) { + add_task( + &mut tasks, + make_event(&argument, &[Tag::Hashtag("arg".to_string())]), + ); + } + let mut position: Option = None; let mut properties: Vec = vec!["id".into(), "name".into(), "state".into()]; loop { @@ -180,7 +174,7 @@ async fn repl() { _ => {} } } - tasks.insert(event.id, Task::new(event)); + add_task(&mut tasks, event); } } };