From aec538929aa73600be65e6bebf8322ed928f7fcf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 19 Mar 2016 09:17:07 -0400 Subject: Initial commit --- .gitmodules | 12 ++++++++ CMakeLists.txt | 19 +++++++++++++ vendor/twitcurl | 1 + vendor/verbly | 1 + vendor/yaml-cpp | 1 + wordplay.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 160000 vendor/twitcurl create mode 160000 vendor/verbly create mode 160000 vendor/yaml-cpp create mode 100644 wordplay.cpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b678533 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "verbly"] + path = verbly + url = https://github.com/hatkirby/verbly +[submodule "vendor/verbly"] + path = vendor/verbly + url = https://github.com/hatkirby/verbly +[submodule "vendor/twitcurl"] + path = vendor/twitcurl + url = https://github.com/swatkat/twitcurl +[submodule "vendor/yaml-cpp"] + path = vendor/yaml-cpp + url = https://github.com/jbeder/yaml-cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a7693ff --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required (VERSION 2.6) +project (wordplay) + +find_package(PkgConfig) +pkg_check_modules(sqlite3 sqlite3 REQUIRED) + +add_subdirectory(vendor/twitcurl/libtwitcurl) +include_directories(vendor/twitcurl/libtwitcurl) + +add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) +include_directories(vendor/yaml-cpp/include) + +add_subdirectory(vendor/verbly) +include_directories(vendor/verbly/lib) + +add_executable(wordplay wordplay.cpp) +set_property(TARGET wordplay PROPERTY CXX_STANDARD 11) +set_property(TARGET wordplay PROPERTY CXX_STANDARD_REQUIRED ON) +target_link_libraries(wordplay ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl verbly) diff --git a/vendor/twitcurl b/vendor/twitcurl new file mode 160000 index 0000000..6659e86 --- /dev/null +++ b/vendor/twitcurl @@ -0,0 +1 @@ +Subproject commit 6659e86de7481e50977b7569c75138f7f69ad3c7 diff --git a/vendor/verbly b/vendor/verbly new file mode 160000 index 0000000..be20f77 --- /dev/null +++ b/vendor/verbly @@ -0,0 +1 @@ +Subproject commit be20f774b7be28a6c8b5359351dc1907d7ac7da8 diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp new file mode 160000 index 0000000..57805df --- /dev/null +++ b/vendor/yaml-cpp @@ -0,0 +1 @@ +Subproject commit 57805dfd6a741e55477ea8d4d5b3b6f0272d1f0e diff --git a/wordplay.cpp b/wordplay.cpp new file mode 100644 index 0000000..74ac40d --- /dev/null +++ b/wordplay.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + srand(time(NULL)); + + YAML::Node config = YAML::LoadFile("config.yml"); + + twitCurl twitter; + twitter.getOAuth().setConsumerKey(config["consumer_key"].as()); + twitter.getOAuth().setConsumerSecret(config["consumer_secret"].as()); + twitter.getOAuth().setOAuthTokenKey(config["access_key"].as()); + twitter.getOAuth().setOAuthTokenSecret(config["access_secret"].as()); + + verbly::data database("data.sqlite3"); + + for (;;) + { + // Generate the most amazing jokes you've ever heard + auto adjq = database.adjectives().has_pronunciation(true).has_synonyms(true).random(true).limit(1).run(); + if (adjq.empty()) + { + continue; + } + + verbly::adjective rhmadj = adjq.front(); + + auto nounq = database.nouns().rhymes_with(rhmadj).not_derived_from(rhmadj).is_hyponym(true).random(true).limit(1).run(); + if (nounq.empty()) + { + continue; + } + + verbly::noun rhmnoun = nounq.front(); + + auto hypq = database.nouns().hypernym_of(rhmnoun).random(true).limit(1).run(); + if (hypq.empty()) + { + continue; + } + + verbly::noun hyp = hypq.front(); + + auto synq = database.adjectives().synonym_of(rhmadj).random(true).limit(1).run(); + if (synq.empty()) + { + continue; + } + + verbly::adjective syn = synq.front(); + + std::stringstream result; + if (syn.starts_with_vowel_sound()) + { + result << "What do you call an " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl; + } else { + result << "What do you call a " << syn.base_form() << " " << hyp.base_form() << "?" << std::endl; + } + + if (rhmadj.starts_with_vowel_sound()) + { + result << "An " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; + } else { + result << "A " << rhmadj.base_form() << " " << rhmnoun.base_form() << "!" << std::endl; + } + + std::string replyMsg; + if (twitter.statusUpdate(result.str())) + { + twitter.getLastWebResponse(replyMsg); + std::cout << "Twitter message: " << replyMsg << std::endl; + } else { + twitter.getLastCurlError(replyMsg); + std::cout << "Curl error: " << replyMsg << std::endl; + } + + std::cout << "Waiting" << std::endl; + + sleep(60 * 60); + } +} \ No newline at end of file -- cgit 1.4.1