diff options
| author | Jokler <jokler@protonmail.com> | 2020-03-22 16:02:36 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-03-22 16:29:53 +0100 |
| commit | e71c6356f53538a20b711510e5d558d969474ad5 (patch) | |
| tree | 3f38be51ce65d2d82409f29580c3155a9a911d0c | |
| parent | 402b71b5eb83a23d613d217e63517dfa59017df6 (diff) | |
| download | pokebot-e71c6356f53538a20b711510e5d558d969474ad5.tar.gz pokebot-e71c6356f53538a20b711510e5d558d969474ad5.zip | |
Fixed id generation for first time setup
| -rw-r--r-- | config.toml.example | 9 | ||||
| -rw-r--r-- | src/bot/master.rs | 8 | ||||
| -rw-r--r-- | src/command.rs | 1 | ||||
| -rw-r--r-- | src/main.rs | 18 |
4 files changed, 20 insertions, 16 deletions
diff --git a/config.toml.example b/config.toml.example index 50cec56..c436610 100644 --- a/config.toml.example +++ b/config.toml.example @@ -11,12 +11,3 @@ bind_address = "127.0.0.1:45538" # Names for the music bots names = ["MusicBot"] - -# Identity of the master bot -[id] -key = "insert-key-here" -counter = 0 -max_counter = 0 - -# Add identities for music bots here -# [[ids]] diff --git a/src/bot/master.rs b/src/bot/master.rs index 755aaa1..7a1201f 100644 --- a/src/bot/master.rs +++ b/src/bot/master.rs @@ -40,7 +40,7 @@ impl MasterBot { let mut con_config = ConnectOptions::new(args.address.clone()) .version(tsclientlib::Version::Linux_3_3_2) .name(args.master_name.clone()) - .identity(args.id) + .identity(args.id.expect("identity should exist")) .log_commands(args.verbose >= 1) .log_packets(args.verbose >= 2) .log_udp_packets(args.verbose >= 3); @@ -59,7 +59,7 @@ impl MasterBot { master_name: args.master_name, address: args.address, names: args.names, - ids: args.ids, + ids: args.ids.expect("identies should exists"), local: args.local, verbose: args.verbose, }); @@ -283,8 +283,8 @@ pub struct MasterArgs { pub domain: String, pub bind_address: String, pub names: Vec<String>, - pub id: Identity, - pub ids: Vec<Identity>, + pub id: Option<Identity>, + pub ids: Option<Vec<Identity>>, } fn default_name() -> String { diff --git a/src/command.rs b/src/command.rs index 695cdc4..207a1c6 100644 --- a/src/command.rs +++ b/src/command.rs @@ -2,7 +2,6 @@ use std::time::Duration; use structopt::clap::AppSettings::*; use structopt::StructOpt; -use log::debug; #[derive(StructOpt, Debug)] #[structopt( diff --git a/src/main.rs b/src/main.rs index 81b5bec..6442005 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,10 +81,19 @@ fn run() -> Result<(), Box<dyn std::error::Error>> { let mut config: MasterArgs = toml::from_str(&toml)?; + if config.id.is_none() { + let id = Identity::create().expect("Failed to create id"); + config.id = Some(id); + } + if let Some(count) = args.gen_id_count { for _ in 0..count { let id = Identity::create().expect("Failed to create id"); - config.ids.push(id); + if let Some(ids) = &mut config.ids { + ids.push(id); + } else { + config.ids = Some(vec![id]); + } } let toml = toml::to_string(&config)?; @@ -94,6 +103,11 @@ fn run() -> Result<(), Box<dyn std::error::Error>> { return Ok(()); } + if config.id.is_none() || config.ids.is_none() { + error!("Failed to find required identites, try running with `-g`"); + return Ok(()); + } + let bot_args = config.merge(args); info!("Starting PokeBot!"); @@ -104,7 +118,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> { async { if bot_args.local { let name = bot_args.names[0].clone(); - let id = bot_args.ids[0].clone(); + let id = bot_args.ids.expect("identies should exists")[0].clone(); let disconnect_cb = Box::new(move |_, _, _| {}); |
