From e71c6356f53538a20b711510e5d558d969474ad5 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sun, 22 Mar 2020 16:02:36 +0100 Subject: Fixed id generation for first time setup --- config.toml.example | 9 --------- src/bot/master.rs | 8 ++++---- src/command.rs | 1 - 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, - pub id: Identity, - pub ids: Vec, + pub id: Option, + pub ids: Option>, } 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> { 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> { 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> { 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 |_, _, _| {}); -- cgit v1.2.3-70-g09d2