From eb8c9f975f0105f7df40b45090f7b2c46f3ddcd3 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 11 Feb 2017 20:01:21 -0500 Subject: Created bot --- .gitmodules | 9 +++++ CMakeLists.txt | 12 ++++++ fefisms.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/libtwittercpp | 1 + vendor/verbly | 1 + vendor/yaml-cpp | 1 + 6 files changed, 127 insertions(+) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 fefisms.cpp create mode 160000 vendor/libtwittercpp create mode 160000 vendor/verbly create mode 160000 vendor/yaml-cpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f4b3cdf --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "vendor/verbly"] + path = vendor/verbly + url = git@github.com:hatkirby/verbly +[submodule "vendor/yaml-cpp"] + path = vendor/yaml-cpp + url = git@github.com:jbeder/yaml-cpp +[submodule "vendor/libtwittercpp"] + path = vendor/libtwittercpp + url = git@github.com:hatkirby/libtwittercpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a2a8f0f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required (VERSION 3.1) +project (fefisms) + +add_subdirectory(vendor/libtwittercpp) +add_subdirectory(vendor/verbly) +add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) + +include_directories(vendor/libtwittercpp/src vendor/verbly/lib vendor/yaml-cpp/include) +add_executable(fefisms fefisms.cpp) +set_property(TARGET fefisms PROPERTY CXX_STANDARD 11) +set_property(TARGET fefisms PROPERTY CXX_STANDARD_REQUIRED ON) +target_link_libraries(fefisms verbly twitter++ yaml-cpp) diff --git a/fefisms.cpp b/fefisms.cpp new file mode 100644 index 0000000..44e69b4 --- /dev/null +++ b/fefisms.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + std::random_device random_device; + std::mt19937 random_engine{random_device()}; + + if (argc != 2) + { + std::cout << "usage: fefisms [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); + + verbly::database database(config["verbly_datafile"].as()); + + verbly::filter formFilter = + (verbly::form::complexity == 1) + && (verbly::form::proper == false); + + verbly::filter cleanFilter = + !(verbly::word::usageDomains %= (verbly::notion::wnid == 106718862)); // Blacklist ethnic slurs + + for (;;) + { + std::cout << "Generating tweet..." << std::endl; + + verbly::token utterance; + + verbly::inflection nounInfl = verbly::inflection::base; + verbly::inflection hypoInfl = verbly::inflection::base; + + if (std::bernoulli_distribution(1.0/2.0)(random_engine)) + { + hypoInfl = verbly::inflection::plural; + } + + if (std::bernoulli_distribution(1.0/2.0)(random_engine)) + { + nounInfl = verbly::inflection::plural; + } + + verbly::word noun = database.words( + (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) + && (verbly::word::forms(nounInfl) %= formFilter) + && cleanFilter + && (verbly::notion::hyponyms %= + (verbly::word::forms(hypoInfl) %= formFilter) + && cleanFilter)).first(); + + verbly::word hyponym = database.words( + (verbly::notion::partOfSpeech == verbly::part_of_speech::noun) + && (verbly::notion::hypernyms %= noun) + && cleanFilter + && (verbly::word::forms(hypoInfl) %= formFilter)).first(); + + if (std::bernoulli_distribution(1.0/2.0)(random_engine)) + { + utterance << verbly::token(noun, nounInfl); + utterance << verbly::token(hyponym, hypoInfl); + } else { + utterance << verbly::token(hyponym, hypoInfl); + utterance << verbly::token(noun, nounInfl); + } + + std::string action = utterance.compile(); + std::cout << action << std::endl; + + try + { + std::cout << "Tweeting..." << std::endl; + + client.updateStatus(action); + + std::cout << "Success!" << std::endl; + std::cout << "Waiting..." << std::endl; + } catch (const twitter::twitter_error& e) + { + std::cout << "Error while tweeting: " << e.what() << std::endl; + } + + std::this_thread::sleep_for(std::chrono::hours(1)); + + std::cout << std::endl; + } +} + diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 index 0000000..df90612 --- /dev/null +++ b/vendor/libtwittercpp @@ -0,0 +1 @@ +Subproject commit df906121dd862c0f704e44f28ee079158c431c41 diff --git a/vendor/verbly b/vendor/verbly new file mode 160000 index 0000000..88e931e --- /dev/null +++ b/vendor/verbly @@ -0,0 +1 @@ +Subproject commit 88e931e8acbaf41b8d36e4ae00b06764793a1441 diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000 index 0000000..bedb28f --- /dev/null +++ b/vendor/yaml-cpp @@ -0,0 +1 @@ +Subproject commit bedb28fdb4fd52d97e02f6cb946cae631037089e -- cgit 1.4.1