Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Add trivial test feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tropicbliss committed Sep 29, 2021
1 parent 82c7536 commit b298081
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "buckshot"
version = "4.0.1"
version = "4.0.2"
authors = ["tropicbliss <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub struct Args {
/// Name of config file (must be a TOML file)
#[structopt(parse(from_os_str), short, long, default_value = "config.toml")]
pub config_path: PathBuf,

/// Activate testing mode in which an invalid bearer token is used to snipe names
#[structopt(short, long)]
pub test: bool,
}

impl Args {
Expand Down
152 changes: 79 additions & 73 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,94 +123,100 @@ async fn main() -> Result<()> {
continue;
}
}
let mut bearer_tokens = Vec::with_capacity(config.account_entry.len());
let mut is_warned = false;
let mut account_idx = 0;
for (count, account) in config.account_entry.clone().iter().enumerate() {
if count != 0 {
writeln!(stdout(), "Waiting 20 seconds to prevent rate limiting...")?;
sleep(std::time::Duration::from_secs(20));
}
let bearer_token = if task == SnipeTask::Mojang {
requestor
.authenticate_mojang(&account.email, &account.password, &account.sq_ans)
.with_context(|| {
format!(
"Failed to authenticate the Mojang account: {}",
account.email
)
})?
} else {
let authenticator = msauth::Auth::new(&account.email, &account.password)
.with_context(|| "Error creating Microsoft authenticator")?;
match authenticator.authenticate().with_context(|| {
format!(
"Failed to authenticate the Microsoft account: {}",
account.email
)
}) {
Ok(x) => x,
Err(y) => {
if config.account_entry.len() == 1 {
bail!(y)
}
writeln!(stdout(), "{}", style("Failed to authenticate a Microsoft account, removing it from the list...").red())?;
config.account_entry.remove(account_idx);
continue;
}
let bearer_tokens = if args.test {
vec!["abc123".to_string()]
} else {
let mut bearer_tokens = Vec::with_capacity(config.account_entry.len());
let mut is_warned = false;
let mut account_idx = 0;
for (count, account) in config.account_entry.clone().iter().enumerate() {
if count != 0 {
writeln!(stdout(), "Waiting 20 seconds to prevent rate limiting...")?;
sleep(std::time::Duration::from_secs(20));
}
};
if task == SnipeTask::Giftcode && count == 0 {
if let Some(gc) = &account.giftcode {
match requestor
.redeem_giftcode(&bearer_token, gc)
let bearer_token = if task == SnipeTask::Mojang {
requestor
.authenticate_mojang(&account.email, &account.password, &account.sq_ans)
.with_context(|| {
format!(
"Failed to redeem the giftcode of the account: {}",
"Failed to authenticate the Mojang account: {}",
account.email
)
}) {
Ok(_) => {
writeln!(
stdout(),
"{}",
style("Successfully redeemed giftcode").green()
)?;
}
})?
} else {
let authenticator = msauth::Auth::new(&account.email, &account.password)
.with_context(|| "Error creating Microsoft authenticator")?;
match authenticator.authenticate().with_context(|| {
format!(
"Failed to authenticate the Microsoft account: {}",
account.email
)
}) {
Ok(x) => x,
Err(y) => {
if config.account_entry.len() == 1 {
bail!(y);
bail!(y)
}
writeln!(stdout(), "{}", style("Failed to redeem the giftcode of an account, removing it from the list...").red())?;
writeln!(stdout(), "{}", style("Failed to authenticate a Microsoft account, removing it from the list...").red())?;
config.account_entry.remove(account_idx);
continue;
}
}
} else if !is_warned {
writeln!(
stdout(),
"{}",
style("Reminder: You should redeem your giftcode before GC sniping").red()
)?;
is_warned = true;
};
if task == SnipeTask::Giftcode && count == 0 {
if let Some(gc) = &account.giftcode {
match requestor
.redeem_giftcode(&bearer_token, gc)
.with_context(|| {
format!(
"Failed to redeem the giftcode of the account: {}",
account.email
)
}) {
Ok(_) => {
writeln!(
stdout(),
"{}",
style("Successfully redeemed giftcode").green()
)?;
}
Err(y) => {
if config.account_entry.len() == 1 {
bail!(y);
}
writeln!(stdout(), "{}", style("Failed to redeem the giftcode of an account, removing it from the list...").red())?;
config.account_entry.remove(account_idx);
continue;
}
}
} else if !is_warned {
writeln!(
stdout(),
"{}",
style("Reminder: You should redeem your giftcode before GC sniping")
.red()
)?;
is_warned = true;
}
}
account_idx += 1;
if task != SnipeTask::Giftcode {
requestor
.check_name_change_eligibility(&bearer_token)
.with_context(|| {
format!(
"Failed to check name change eligibility of {}",
account.email
)
})?;
}
bearer_tokens.push(bearer_token);
}
account_idx += 1;
if task != SnipeTask::Giftcode {
requestor
.check_name_change_eligibility(&bearer_token)
.with_context(|| {
format!(
"Failed to check name change eligibility of {}",
account.email
)
})?;
if bearer_tokens.is_empty() {
bail!("No Microsoft accounts left to use");
}
bearer_tokens.push(bearer_token);
}
if bearer_tokens.is_empty() {
bail!("No Microsoft accounts left to use");
}
bearer_tokens
};
writeln!(stdout(), "{}", style("Successfully signed in").green())?;
writeln!(stdout(), "Setup complete")?;
let mut is_success = None;
Expand Down

0 comments on commit b298081

Please sign in to comment.