lz1998 / welove520

Rust 情侣空间农场 自动种菜收菜卖菜 跑订单
3 stars 0 forks source link

Request for New Features #1

Open huaiqianqian opened 1 year ago

huaiqianqian commented 1 year ago

Hello,

I'm wondering if this project is still being maintained? I'm really enjoying it and would love to see some new features added, such as:

  1. Leaderboard Integration: It would be great if a user could view their current points and their ranking on the leaderboard, even showing the point gap between them and the leading position (or how many points they need to get on the leaderboard).

  2. Automated Ship and Train Loading: A feature that could automatically fill the ships and trains at scheduled times and send them off would be very useful.

  3. Item Finding with Panda: I suggest having a feature where the panda could be assigned to find items. The decision to accept or reject could then be based on the maximum number of items that the panda can find.

I would be immensely grateful if all or some of these features could be implemented. I truly believe they would greatly enhance the experience of using this project. Thank you for your consideration.

Best regards, huaiqian

lz1998 commented 1 year ago

Item Finding with panda

welove520/src/bin/panda.rs

use std::collections::HashMap;
use tracing::Level;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use welove520::api::WeLoveClient;

#[tokio::main]
async fn main() {
    init_log();

    let base_url = "XXXX".to_string();
    let version = "XXXX".to_string();
    let union_id = "UID_XXXXXXXXXX".to_string();
    let cli = WeLoveClient::new(
        base_url,
        HashMap::from([
            ("fv".to_string(), version),
            ("union_id".to_string(), union_id),
        ]),
        Default::default(),
    );
    loop {
        // let _ = dbg!(cli.get_warehouses().await.unwrap());
        let resp = match cli
            .post(
                "/v1/game/farm/panda/find",
                HashMap::from([
                    ("item_id", "209002"), // ("item_id", "903004")
                ]),
            )
            .await
        {
            Ok(resp) => resp,
            Err(err) => {
                tracing::error!("failed to post {err}");
                tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;
                continue;
            }
        };
        tracing::info!("resp: {}", serde_json::to_string(&resp).unwrap());
        let msg = match resp.messages.into_iter().find(|m| m["msg_type"] == 32) {
            Some(msg) => msg,
            None => {
                tracing::error!("msg_type=32 is none");
                tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;
                continue;
            }
        };
        if let Some(items) = msg["items"].as_array() {
            if let Some(item) = items.last() {
                tracing::info!("item: {}", serde_json::to_string(&item).unwrap());
                let resp = match cli
                    .post(
                        "/v1/game/farm/panda/buy",
                        HashMap::from([(
                            "only_id",
                            item["id"].as_i64().unwrap().to_string().as_str(),
                        )]),
                    )
                    .await
                {
                    Ok(resp) => resp,
                    Err(err) => {
                        tracing::error!("failed to post {err}");
                        tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;
                        continue;
                    }
                };
                tracing::info!("buy response: {}", serde_json::to_string(&resp).unwrap());
            }
        }
        tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;
    }
}

fn init_log() {
    tracing_subscriber::registry()
        .with(
            tracing_subscriber::fmt::layer()
                .with_target(true)
                .with_timer(tracing_subscriber::fmt::time::OffsetTime::new(
                    time::UtcOffset::__from_hms_unchecked(8, 0, 0),
                    time::macros::format_description!(
                        "[year]-[month]-[day] [hour]:[minute]:[second]"
                    ),
                )),
        )
        .with(
            tracing_subscriber::filter::Targets::new()
                .with_target("panda", Level::DEBUG)
                .with_target("welove520", Level::DEBUG),
        )
        .init();
}