From b77ab7cb283e64fb8b23f4892115644e84596842 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 23 Feb 2018 09:18:01 -0500 Subject: Created bot --- lunatic.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lunatic.cpp (limited to 'lunatic.cpp') diff --git a/lunatic.cpp b/lunatic.cpp new file mode 100644 index 0000000..2438788 --- /dev/null +++ b/lunatic.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + if (argc != 2) + { + std::cout << "usage: lunatic [configfile]" << std::endl; + return -1; + } + + std::string configfile(argv[1]); + YAML::Node config = YAML::LoadFile(configfile); + + twitter::auth auth; + auth.setConsumerKey(config["consumer_key"].as()); + auth.setConsumerSecret(config["consumer_secret"].as()); + auth.setAccessKey(config["access_key"].as()); + auth.setAccessSecret(config["access_secret"].as()); + + twitter::client client(auth); + + std::random_device randomDevice; + std::mt19937 rng(randomDevice()); + + for (;;) + { + std::cout << "Generating tweet" << std::endl; + + // Reload achievements list every time in case it has been updated + std::vector achievements; + std::ifstream datafile(config["achievements"].as()); + if (!datafile.is_open()) + { + std::cout << "Could not find achievements file." << std::endl; + return 1; + } + + std::string line; + while (getline(datafile, line)) + { + if (line.back() == '\r') + { + line.pop_back(); + } + + achievements.push_back(line); + } + + std::uniform_int_distribution dist(0, achievements.size() - 1); + std::string achievement = achievements[dist(rng)]; + + std::string header; + if (std::bernoulli_distribution(1.0 / 50.0)(rng)) + { + header = "YOU GOT A MULTI MOON!"; + } else { + header = "YOU GOT A MOON!"; + } + + std::string action = header + "\n" + achievement; + action.resize(140); + + try + { + client.updateStatus(action); + } catch (const twitter::twitter_error& e) + { + std::cout << "Twitter error: " << e.what() << std::endl; + } + + std::cout << action << std::endl; + std::cout << "Waiting" << std::endl; + + std::this_thread::sleep_for(std::chrono::hours(3)); + + std::cout << std::endl; + } +} -- cgit 1.4.1