#api #dns #diplomacy #nation #strife

dns-wrapper

An API wrapper for Diplomacy and Strife

7 releases

0.1.6 Nov 4, 2024
0.1.5 Nov 4, 2024

#657 in Web programming

Download history 308/week @ 2024-10-30 144/week @ 2024-11-06

452 downloads per month

GPL-3.0-or-later

8KB
103 lines

DNS Wrapper

What does it do?

DNS Wrapper is an API wrapper for the brower nation simulation game Diplomacy and Strife. It has several easy to use functions you can use in your Discord bot.

How do I use it?

Step 1:

Set your Diplomacy and Strife API key, this can be found here.

use dns_wrapper::api::ApiKey;

ApiKey::set_apikey("APIKEY");

Step 2:

Use one of the fetch functions.

use dns_wrapper::api::output::fetch_output;

//...
// Fetch nation data
let nation_data = match fetch_output(nation_id).await {
    Ok(data) => data,
    Err(e) => {
        println!("{:?}", e);
        return Ok(());
    }
};

// Create an embed
let embed = serenity::CreateEmbed::default()
    .title(format!("{}'s Output", nation_data.nation))
    .description(format!(
        "**Money**: ${}\n**Production**: {}\n**Minerals**: {}\n**Uranium**: {}\n**Rare Metals**: {}\n**Fuel**: {}\n**Political Power**: {}",
        nation_data.money.round().separate_with_commas(),
        nation_data.production.round().separate_with_commas(),
        nation_data.minerals.round().separate_with_commas(),
        nation_data.uranium.round().separate_with_commas(),
        nation_data.rare_metals.round().separate_with_commas(),
        nation_data.fuel.round().separate_with_commas(),
        nation_data.political_power.round().separate_with_commas()
    ))
    .colour(Colour::DARK_GREEN);

let message = poise::CreateReply::default().embed(embed);
ctx.send(message).await?;

Ok(())
//...

The example above shows a code snippet of my Discord bot using the fetch_output() function. This Discord bot is made with the Poise library.

Dependencies

~6–17MB
~225K SLoC