upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sub_commands/rebroadcast.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2023-05-21 11:27:04 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2023-05-21 11:27:04 +0000
commit318e467b158b158cf9eb843318dc14141d1b8c54 (patch)
tree46ec99fccfac487b1ff2dd29d3b01fb970fcb88d /src/sub_commands/rebroadcast.rs
parent2ce71c5434fb7245aad4d070e08bbf6792d79b4d (diff)
main and remaining subcommands
Diffstat (limited to 'src/sub_commands/rebroadcast.rs')
-rw-r--r--src/sub_commands/rebroadcast.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/sub_commands/rebroadcast.rs b/src/sub_commands/rebroadcast.rs
new file mode 100644
index 0000000..d3ece23
--- /dev/null
+++ b/src/sub_commands/rebroadcast.rs
@@ -0,0 +1,68 @@
1
2
3use std::fs;
4
5use clap::Args;
6
7use nostr::{Keys};
8
9use crate::{cli_helpers::select_relays, config::load_config, utils::{create_client, load_event}};
10
11#[derive(Args)]
12pub struct RebroadcastSubCommand {
13}
14
15pub fn rebroadcast(
16 _sub_command_args: &RebroadcastSubCommand,
17) {
18
19 // get relay input
20 let relays = select_relays(
21 &mut load_config(),
22 &vec![],
23 )
24 .expect("relays to be selected");
25
26 let client = create_client(&Keys::generate(), relays)
27 .expect("create_client to return client for create_and_broadcast_patches");
28
29 let repo_dir_path = std::env::current_dir().unwrap();
30
31 // cycle through directories and send events
32 for dir_name in [
33 "groups",
34 "branches",
35 "patches",
36 "merges",
37 "prs",
38 "issues",
39 "comments",
40 ] {
41 if !repo_dir_path.join(".ngit").exists() {
42 println!("this isn't a repository here to rebroadcast")
43 }
44 let dir_path = repo_dir_path.join(".ngit").join(&dir_name);
45 if dir_path.exists() {
46 let dir = fs::read_dir(&dir_path)
47 .expect("read_dir to produce ReadDir from a path that exists");
48 // get json in directories
49 for entry in dir {
50 let path = entry
51 .expect("DirEntry to return from ReadDir")
52 .path();
53 // send event
54 match client.send_event(
55 load_event(&path)
56 .expect("every file in .ngit paths is a valid json event")
57 ) {
58 Ok(_) => {
59 println!("sent: {}", &path.to_string_lossy());
60 },
61 // TODO: this isn't working - if a relay is specified with a type it will wait 30ish secs and then return successful
62 Err(e) => { println!("error broadcasting event: {}",e); },
63 }
64 // TODO: better error handling here / reporting. potentially warn if taking a while and report on troublesome relays
65 }
66 }
67 }
68}