From ffc9edbc9fbeb65fd32c1fa24584010a83a6de31 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 24 Feb 2017 11:15:12 -0500 Subject: Created bot --- support.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 support.cpp (limited to 'support.cpp') diff --git a/support.cpp b/support.cpp new file mode 100644 index 0000000..8dc6c4e --- /dev/null +++ b/support.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include +#include +#include "sentence.h" + +int main(int argc, char** argv) +{ + if (argc != 2) + { + std::cout << "usage: support [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()}; + + verbly::database database(config["verbly_datafile"].as()); + sentence generator(database, rng); + + for (;;) + { + verbly::word adjective = database.words( + (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective) + && (verbly::word::antiPertainyms %= + (verbly::word::forms(verbly::inflection::plural)))).first(); + + verbly::word noun = database.words( + (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) + && (verbly::word::pertainyms %= adjective) + && (verbly::word::forms(verbly::inflection::plural))).first(); + + verbly::token action = { + "RT if you ARE", + verbly::token::punctuation(",", adjective), + "if you SUPPORT", + verbly::token::punctuation(",", + verbly::token(noun, verbly::inflection::plural)), + "or if you", + generator.generate()}; + + std::string result = action.compile(); + if (result.length() <= 140) + { + std::cout << result << std::endl; + + try + { + client.updateStatus(result); + + std::cout << "Tweeted!" << std::endl; + } catch (const twitter::twitter_error& e) + { + std::cout << "Twitter error: " << e.what() << std::endl; + } + + std::this_thread::sleep_for(std::chrono::hours(1)); + + std::cout << std::endl; + } + } +} + -- cgit 1.4.1