Skip to content

Commit

Permalink
Chore/08.07 (#4)
Browse files Browse the repository at this point in the history
* feat: add speed_up

* feat: speed up
  • Loading branch information
JesuisTong authored Aug 8, 2024
1 parent 37206c4 commit 1ef1d76
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tg_banana_bot"
version = "0.0.2"
version = "0.0.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -15,7 +15,7 @@ log = "0.4.22"
percent-encoding = "2.3.1"
rand = "0.8.5"
regex = "1.10.5"
reqwest = "0.12.5"
reqwest = { version = "0.12.5", features = ["json"] }
rsa = "0.9.6"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"
Expand Down
65 changes: 49 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,37 @@ impl Banana {
Ok(())
}

// function Q(A) {
// return g.api.post("/banana/achieve_quest", {
// data: A
// })
// }
// function o(A) {
// return g.api.post("/banana/claim_quest", {
// data: A
// })
// }
async fn do_speedup(&self) -> Result<Option<i64>, Box<dyn std::error::Error>> {
let (client, headers) = self.request();

let response = client
.post("https://interface.carv.io/banana/do_speedup")
.headers(headers)
.body("{}")
.send()
.await?;

utils::format_println(&self.name, &format!("do_speedup: {:?}", response.status()));

if response.status() == StatusCode::OK {
let data = &response.json::<serde_json::Value>().await?;
let code = data["code"].as_i64().unwrap();
if code == 0i64 {
let can_claim_time = data["data"]["lottery_info"]["last_countdown_start_time"]
.as_i64()
.unwrap()
+ (data["data"]["lottery_info"]["countdown_interval"]
.as_i64()
.unwrap()
* 60000);
let rest_time = can_claim_time - utils::get_current_timestamp();

return Ok(Some(rest_time));
}
}

Ok(None)
}
}

async fn login(
Expand Down Expand Up @@ -332,12 +353,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap();
user.access_token = Some(access_token);
user.cookie_token = Some(cookie_token);
// update json
copy_users.insert(name.clone().to_string(), user.clone());
utils::write_config_json(file_path.to_str().unwrap(), &copy_users);
} else {
copy_users.insert(name.clone().to_string(), user.clone());
utils::write_config_json(file_path.to_str().unwrap(), &copy_users);
}

// update json
copy_users.insert(name.clone().to_string(), user.clone());
utils::write_config_json(file_path.to_str().unwrap(), &copy_users);

info!("name: {}, start", &name);

let user = Banana::new(
Expand All @@ -355,6 +378,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
user.complete_quest().await.unwrap();

let arc_user = Arc::new(user);

tokio::spawn(async move {
let can_claim_time = userinfo.lottery_info.last_countdown_start_time
+ (userinfo.lottery_info.countdown_interval as i64 * 60000);
Expand All @@ -373,8 +397,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});

loop {
utils::format_println(&name, "claim loop start!");
sleep(Duration::from_secs(60 * 60 * 8 + 10)).await;
let do_speedup_res = arc_user.do_speedup().await.unwrap();

let rest_time = match do_speedup_res {
Some(rest_time) => rest_time / 1000 + 10,
None => 60 * 60 * 8 + 10,
} as u64;
utils::format_println(
&name,
&format!("next claim is after: {}secs", rest_time.max(0)),
);
sleep(Duration::from_secs(rest_time)).await;

let _ = arc_user.claim().await.map_err(|err| {
utils::format_error(&name, &format!("err: {:?}", err));
Expand Down

0 comments on commit 1ef1d76

Please sign in to comment.