forked from janek/mostr
feat: add arguments to repl task list
This commit is contained in:
parent
870a43112a
commit
76e1f87377
30
src/main.rs
30
src/main.rs
|
@ -22,8 +22,6 @@ use std::time::Duration;
|
||||||
31923 (Calendar, with Time)
|
31923 (Calendar, with Time)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static TASK_KIND: Lazy<Kind> = Lazy::new(|| Kind::from(1621));
|
|
||||||
|
|
||||||
static MY_KEYS: Lazy<Keys> = Lazy::new(|| Keys::generate());
|
static MY_KEYS: Lazy<Keys> = Lazy::new(|| Keys::generate());
|
||||||
static CLIENT: Lazy<Client> = Lazy::new(|| Client::new(MY_KEYS.borrow().deref()));
|
static CLIENT: Lazy<Client> = Lazy::new(|| Client::new(MY_KEYS.borrow().deref()));
|
||||||
|
|
||||||
|
@ -62,13 +60,9 @@ async fn main() {
|
||||||
|
|
||||||
let timeout = Duration::from_secs(3);
|
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;
|
let sub_id: SubscriptionId = CLIENT.subscribe(vec![filter.clone()], None).await;
|
||||||
|
|
||||||
for argument in args().skip(1) {
|
|
||||||
let _ = send(&argument, &[]).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
repl().await;
|
repl().await;
|
||||||
|
|
||||||
println!("Finding existing events");
|
println!("Finding existing events");
|
||||||
|
@ -99,22 +93,22 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_event(text: &str, tags: &[Tag]) -> Event {
|
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)
|
.to_event(&MY_KEYS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send(text: &str, tags: &[Tag]) -> (Event, Result<EventId, Error>) {
|
|
||||||
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() {
|
async fn repl() {
|
||||||
let mut tasks: HashMap<EventId, Task> = HashMap::new();
|
let mut tasks: HashMap<EventId, Task> = HashMap::new();
|
||||||
|
let add_task =
|
||||||
|
|tasks: &mut HashMap<EventId, Task>, 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<EventId> = None;
|
let mut position: Option<EventId> = None;
|
||||||
let mut properties: Vec<String> = vec!["id".into(), "name".into(), "state".into()];
|
let mut properties: Vec<String> = vec!["id".into(), "name".into(), "state".into()];
|
||||||
loop {
|
loop {
|
||||||
|
@ -180,7 +174,7 @@ async fn repl() {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.insert(event.id, Task::new(event));
|
add_task(&mut tasks, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue