From 4b2fd438e3a788e7ff07cc1f49fd0d91d7d1e068 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 5 Sep 2016 09:37:21 -0400 Subject: Forked chemist to make a simpler text substitution bot --- .gitmodules | 9 +- CMakeLists.txt | 18 ++-- data.txt | 260 --------------------------------------------------- vendor/libtwittercpp | 1 + vendor/twitcurl | 1 - vendor/verbly | 1 - vendor/yaml-cpp | 2 +- yandere.cpp | 194 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 206 insertions(+), 280 deletions(-) delete mode 100644 data.txt create mode 160000 vendor/libtwittercpp delete mode 160000 vendor/twitcurl delete mode 160000 vendor/verbly create mode 100644 yandere.cpp diff --git a/.gitmodules b/.gitmodules index 08a42de..78fd03a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ -[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 +[submodule "vendor/libtwittercpp"] + path = vendor/libtwittercpp + url = https://github.com/hatkirby/libtwittercpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d19b9..94776f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,13 @@ cmake_minimum_required (VERSION 3.1) -project (chemist) +project (yandere) set(CMAKE_BUILD_TYPE Debug) -find_package(PkgConfig) -pkg_check_modules(sqlite3 sqlite3 REQUIRED) - -add_subdirectory(vendor/twitcurl/libtwitcurl) -add_subdirectory(vendor/verbly) +add_subdirectory(vendor/libtwittercpp) add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) -include_directories(vendor/twitcurl/libtwitcurl ${sqlite3_INCLUDE_DIR} vendor/verbly/lib vendor/yaml-cpp/include) -add_executable(chemist chemist.cpp) -set_property(TARGET chemist PROPERTY CXX_STANDARD 11) -set_property(TARGET chemist PROPERTY CXX_STANDARD_REQUIRED ON) -target_link_libraries(chemist verbly ${sqlite3_LIBRARIES} yaml-cpp twitcurl curl) +include_directories(vendor/libtwittercpp/src vendor/yaml-cpp/include) +add_executable(yandere yandere.cpp) +set_property(TARGET yandere PROPERTY CXX_STANDARD 11) +set_property(TARGET yandere PROPERTY CXX_STANDARD_REQUIRED ON) +target_link_libraries(yandere yaml-cpp twitter++) diff --git a/data.txt b/data.txt deleted file mode 100644 index 8535d4e..0000000 --- a/data.txt +++ /dev/null @@ -1,260 +0,0 @@ -MAIN -{PRIMARY} {SECONDARY} - -PRIMARY -{NAME} is {CLASS:indefinite} commonly used to treat {SYNDROME}. -{NAME} is {CLASS:indefinite} primarily used for {SYNDROME}. -{NAME} is {CLASS:indefinite} prescribed for {SYNDROME}. -{NAME} is {CLASS:indefinite} approved for treatment of {SYNDROME}, and {SYNDROME}. -{NAME} is {CLASS:indefinite} used for {SYNDROME} and {SYNDROME}. -{NAME} is {CLASS:indefinite} used with {EXISTENT} to treat {syndrome}. -{NAME} is {CLASS:indefinite} used in cases of {EXISTENT} overdose. -{NAME} is {CLASS:indefinite} used recreationally as {CLASS:indefinite}. -{NAME} is {CLASS:indefinite} used recreationally for {verbing}. - -SECONDARY -Developed due to the Great {Noun} Epidemic of {year} in {Region}. -Frequently prescribed off-label for {SYNDROME}. -Sometimes used for {SYNDROME} because of its {verbing} effect. -Illegal to own in the US because of its {verbing} effect. -Developed in {year} to replace {EXISTENT}. -Overtook {EXISTENT} due to its {adjective} effect. -Synthesized by {FamousName} in {year} in a {verbing} accident. -Used mainly in {year}, before {EXISTENT} became popular. -Only legal in {Region} because of its {verbing} effect. - -SYNDROME -irritable {noun} syndrome -{adjective} {noun} syndrome -severe {noun} -major {adjective} disorder -{adjective} {noun} disorder -obsessive {noun} disorder -clinical {noun} -{adjective} personality disorder -respiratory {adjective} disease -{bodypart} cancer -restless {bodypart} -{bodypart} failure -congenital {noun} disease -{FamousName}'s disease -{adjective} fever -hypo{noun}ism - -CLASS -analgesic -painkiller -anaesthetic -antihistamine -anticonvulsant -antiepileptic -antidepressant -antimigraine -antipsychotic -benzodiazepine -antiparkinsonian -immunosuppressive -antianaemia -anticoagulant -blood thinner -antiarrhythmic -antithrombotic -antifungal -anti-infective -anti-inflammatory -disinfectant -antiseptic -antiemetic -diuretic -opiod painkiller -antiulcer -laxative -sedative -hormone -estrogen -androgen -contraceptive -ovulation inducer -thyroid stimulant -antithyroid -insulin -vaccine -oxytocin -SSRI -anxiolytic -antipanic agent -tricyclic -MAOI -SNRI -antiandrogen -psychedelic -vitamin -probiotic -antibiotic -antiviral drug -stimulant -depressant -aphrodisiac - -EXISTENT -fluoxetine -Prozac -sertraline -Zoloft -escitalopram -Lexapro -venlafaxine -Effexor -aripiprazole -Abilify -alprazolam -Xanax -diazepam -Valium -lamotrigine -Lamictal -gabapentin -Neurontin -acetaminophen -Tylenol -ibuprofin -Advil -lurasidone -Latuda -lithium -activated charcoal -estradiol -AndroGel -ziprasidone -Geodon -risperidone -Risperdal -quetiapine -Seroquel -Cymbalta -duloxetine -bupropion -Welbutrin -buspirone -Buspar -oxycontin -Oxycodone -Concerta -methylphenidate -Ritalin -Vyvanse -lisdexamfetamine -Adderall -epinephrine -adrenaline -testosterone gel -Cialis -Viagra -heroin -morphine -crystal meth - -NAME -{PRENAME}{NAMEMID}{NAMEIFX} - -PRENAME -Oxy -Ari -Zi -Quetia -Mor -Her -Cia -Via -He -Con -Flu -Ser -Es -Ven -Al -Dia -Lamo -Gaba -Aceta -Ibu -Lura -Ris -Li -Estra -Du -Bus -Epin -Co -Lido -Pro -Pri -Bu -Levo -Ro -Me -Dibu -Des -Ha - -NAMEMID -pipra -pi -to -stero -cer -oxe -tra -cita -lo -la -fa -pra -zo -ze -tri -pen -mino -pro -si -peri -thi -loxe -con -epher -piva -bupi -va -piva -flu -oxy -{NAMEMID}{NAMEMID} -{NAMEMID}{NAMEMID} - -NAMEIFX -zole -ne -tine -lin -tamine -gra -phine -ta -line -pram -xine -lam -pam -gine -tin -phen -fin -done -um -diol -tin -rone -ine -caine -rane -ide \ No newline at end of file diff --git a/vendor/libtwittercpp b/vendor/libtwittercpp new file mode 160000 index 0000000..6c9f541 --- /dev/null +++ b/vendor/libtwittercpp @@ -0,0 +1 @@ +Subproject commit 6c9f541f34c58ac817f88ffb5e069b929bbbc274 diff --git a/vendor/twitcurl b/vendor/twitcurl deleted file mode 160000 index 6659e86..0000000 --- a/vendor/twitcurl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6659e86de7481e50977b7569c75138f7f69ad3c7 diff --git a/vendor/verbly b/vendor/verbly deleted file mode 160000 index 965a320..0000000 --- a/vendor/verbly +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 965a3206df834f846f2c560438c80a707dcee4cb diff --git a/vendor/yaml-cpp b/vendor/yaml-cpp index 34bd1a7..519d33f 160000 --- a/vendor/yaml-cpp +++ b/vendor/yaml-cpp @@ -1 +1 @@ -Subproject commit 34bd1a7083e5875e6a4b2d4f61c0b356cc5d53fc +Subproject commit 519d33fea3fbcbe7e1f89f97ee0fa539cec33eb7 diff --git a/yandere.cpp b/yandere.cpp new file mode 100644 index 0000000..01b0dca --- /dev/null +++ b/yandere.cpp @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +std::string implode(InputIterator first, InputIterator last, std::string delimiter) +{ + std::stringstream result; + + for (InputIterator it = first; it != last; it++) + { + if (it != first) + { + result << delimiter; + } + + result << *it; + } + + return result.str(); +} + +template +Container split(std::string input, std::string delimiter) +{ + Container result; + + while (!input.empty()) + { + int divider = input.find(delimiter); + if (divider == std::string::npos) + { + result.push_back(input); + + input = ""; + } else { + result.push_back(input.substr(0, divider)); + + input = input.substr(divider+delimiter.length()); + } + } + + return result; +} + +int main(int argc, char** argv) +{ + srand(time(NULL)); + rand(); rand(); rand(); rand(); + + YAML::Node config = YAML::LoadFile("config.yml"); + + 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::map> groups; + std::ifstream datafile("data.txt"); + if (!datafile.is_open()) + { + std::cout << "Could not find data.txt" << std::endl; + return 1; + } + + bool newgroup = true; + std::string line; + std::string curgroup; + while (getline(datafile, line)) + { + if (line.back() == '\r') + { + line.pop_back(); + } + + if (newgroup) + { + curgroup = line; + newgroup = false; + } else { + if (line.empty()) + { + newgroup = true; + } else { + groups[curgroup].push_back(line); + } + } + } + + for (;;) + { + std::cout << "Generating tweet" << std::endl; + std::string action = "{MAIN}"; + int tknloc; + while ((tknloc = action.find("{")) != std::string::npos) + { + std::string token = action.substr(tknloc+1, action.find("}")-tknloc-1); + std::string modifier; + int modloc; + if ((modloc = token.find(":")) != std::string::npos) + { + modifier = token.substr(modloc+1); + token = token.substr(0, modloc); + } + + int eqloc; + std::string eqvarname; + if ((eqloc = token.find("=")) != std::string::npos) + { + eqvarname = token.substr(0, eqloc); + token = token.substr(eqloc+1); + } + + std::string canontkn; + std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) { + return std::toupper(ch); + }); + + std::string result; + if (canontkn == "\\N") + { + result = "\n"; + } else { + auto group = groups[canontkn]; + result = group[rand() % group.size()]; + } + + if (!eqvarname.empty()) + { + groups[eqvarname].push_back(result); + } + + if (modifier == "indefinite") + { + if ((result.length() > 1) && (isupper(result[0])) && (isupper(result[1]))) + { + result = "an " + result; + } else if ((result[0] == 'a') || (result[0] == 'e') || (result[0] == 'i') || (result[0] == 'o') || (result[0] == 'u')) + { + result = "an " + result; + } else { + result = "a " + result; + } + } + + std::string finalresult; + if (islower(token[0])) + { + std::transform(std::begin(result), std::end(result), std::back_inserter(finalresult), [] (char ch) { + return std::tolower(ch); + }); + } else if (isupper(token[0]) && !isupper(token[1])) + { + auto words = split>(result, " "); + for (auto& word : words) + { + word[0] = std::toupper(word[0]); + } + + finalresult = implode(std::begin(words), std::end(words), " "); + } else { + finalresult = result; + } + + action.replace(tknloc, action.find("}")-tknloc+1, finalresult); + } + + 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(1)); + + std::cout << std::endl; + } +} -- cgit 1.4.1