aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJokler <jokler@protonmail.com>2020-03-22 16:56:17 +0100
committerGitHub <noreply@github.com>2020-03-22 16:56:17 +0100
commit08794f7f7bfd226c4b68b141be14e2405ce61d03 (patch)
tree3f38be51ce65d2d82409f29580c3155a9a911d0c /src/main.rs
parent402b71b5eb83a23d613d217e63517dfa59017df6 (diff)
parente71c6356f53538a20b711510e5d558d969474ad5 (diff)
downloadpokebot-08794f7f7bfd226c4b68b141be14e2405ce61d03.tar.gz
pokebot-08794f7f7bfd226c4b68b141be14e2405ce61d03.zip
Merge pull request #47 from Mavulp/fix-id-generation
Fixed id generation for first time setup
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs18
1 files changed, 16 insertions, 2 deletions
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 |_, _, _| {});