diff --git a/ingredients.json b/ingredients.json index f981afc..c6cd34e 100644 --- a/ingredients.json +++ b/ingredients.json @@ -34,7 +34,6 @@ "turnip", "maize", "sweet potatoes" - ], "spices": [ diff --git a/src/soupbot.cpp b/src/soupbot.cpp index ef70a19..a27b32a 100644 --- a/src/soupbot.cpp +++ b/src/soupbot.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "version.hpp" namespace pt = boost::property_tree; @@ -71,6 +73,14 @@ void read_config(pt::ptree &config, string &instance, string &access_token) } } +void populate_vector(const pt::ptree &ingredients, const string &node, std::vector &vector) +{ + for (const pt::ptree::value_type &value : ingredients.get_child(node)) + { + vector.push_back(value.second.data()); + } +} + int main(int argc, char *argv[]) { pt::ptree config; @@ -81,6 +91,69 @@ int main(int argc, char *argv[]) pt::ptree ingredients; pt::read_json(filepath + "ingredients.json", ingredients); - + std::vector vegetables; + std::vector spices; + std::vector fruits; + std::vector misc; + std::vector highprio; + + populate_vector(ingredients, "vegetables", vegetables); + populate_vector(ingredients, "spices", spices); + populate_vector(ingredients, "fruits", fruits); + populate_vector(ingredients, "misc", misc); + populate_vector(ingredients, "highprio", highprio); + + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + std::default_random_engine generator(seed); + std::uniform_int_distribution distribution(0, 3); + std::uniform_int_distribution distribution_vegetables(0, vegetables.size() - 1); + std::uniform_int_distribution distribution_spices(0, spices.size() - 1); + std::uniform_int_distribution distribution_fruits(0, fruits.size() - 1); + std::uniform_int_distribution distribution_misc(0, misc.size() - 1); + std::uniform_int_distribution distribution_highprio(0, highprio.size() - 1); + + auto dice = std::bind(distribution, generator); + auto vegdice = std::bind(distribution_vegetables, generator); + auto spicedice = std::bind(distribution_spices, generator); + auto fruitdice = std::bind(distribution_fruits, generator); + auto miscdice = std::bind(distribution_misc, generator); + auto priodice = std::bind(distribution_highprio, generator); + + string toot = "Todays #soup is made of:\n\n"; + + toot += "1 part " + vegetables[vegdice()]; + if (dice() > 0) + toot += ",\n1 part " + vegetables[vegdice()]; + if (dice() > 1) + toot += ",\n1 part " + vegetables[vegdice()]; + + if (dice() > 1) + toot += ",\na few " + fruits[fruitdice()]; + + if (dice() > 1) + toot += ",\na good handful " + misc[miscdice()]; + if (dice() > 1) + toot += ",\na good handful " + misc[miscdice()]; + + toot += ",\n" + spices[spicedice()]; + if (dice() > 0) + toot += ",\n" + spices[spicedice()]; + if (dice() > 1) + toot += ",\n" + spices[spicedice()]; + + toot += ",\nan ample amount of " + highprio[priodice()]; + if (dice() > 1) + toot += " and " + highprio[priodice()]; + + toot += "\nand plenty oil.\n\n#bot"; + + cout << toot << '\n'; + + + // string answer; + // std::uint16_t ret; + // Mastodon::API masto(instance, access_token); + // masto.set_useragent("soupbot/" + (string)global::version); + return 0; }