diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-09-19 09:59:17 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-09-19 09:59:17 -0400 |
| commit | afbe0bd9678619fe1b022075615229c875c0b98a (patch) | |
| tree | c08a5524d7f83c14013d3f660e575fdd9e51750f /pokepronouns.cpp | |
| download | pokepronouns-afbe0bd9678619fe1b022075615229c875c0b98a.tar.gz pokepronouns-afbe0bd9678619fe1b022075615229c875c0b98a.tar.bz2 pokepronouns-afbe0bd9678619fe1b022075615229c875c0b98a.zip | |
Created bot
Diffstat (limited to 'pokepronouns.cpp')
| -rw-r--r-- | pokepronouns.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
| diff --git a/pokepronouns.cpp b/pokepronouns.cpp new file mode 100644 index 0000000..974889e --- /dev/null +++ b/pokepronouns.cpp | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <string> | ||
| 3 | #include <vector> | ||
| 4 | #include <map> | ||
| 5 | #include <twitter.h> | ||
| 6 | #include <random> | ||
| 7 | #include <chrono> | ||
| 8 | #include <thread> | ||
| 9 | #include <fstream> | ||
| 10 | #include <yaml-cpp/yaml.h> | ||
| 11 | |||
| 12 | int main(int argc, char** argv) | ||
| 13 | { | ||
| 14 | if (argc != 2) | ||
| 15 | { | ||
| 16 | std::cout << "usage: pokepronouns [configfile]" << std::endl; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | |||
| 20 | std::string configfile(argv[1]); | ||
| 21 | YAML::Node config = YAML::LoadFile(configfile); | ||
| 22 | |||
| 23 | twitter::auth auth; | ||
| 24 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | ||
| 25 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | ||
| 26 | auth.setAccessKey(config["access_key"].as<std::string>()); | ||
| 27 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | ||
| 28 | |||
| 29 | twitter::client client(auth); | ||
| 30 | |||
| 31 | std::vector<std::string> pokemon; | ||
| 32 | std::map<std::string, std::string> genders; | ||
| 33 | std::ifstream datafile(config["data"].as<std::string>()); | ||
| 34 | if (!datafile.is_open()) | ||
| 35 | { | ||
| 36 | std::cout << "Could not find data file." << std::endl; | ||
| 37 | return 1; | ||
| 38 | } | ||
| 39 | |||
| 40 | bool newgroup = true; | ||
| 41 | std::string line; | ||
| 42 | std::string curgroup; | ||
| 43 | while (getline(datafile, line)) | ||
| 44 | { | ||
| 45 | if (line.back() == '\r') | ||
| 46 | { | ||
| 47 | line.pop_back(); | ||
| 48 | } | ||
| 49 | |||
| 50 | int divider = line.find_first_of(","); | ||
| 51 | std::string name = line.substr(0, divider); | ||
| 52 | std::string gender = line.substr(divider + 2); | ||
| 53 | |||
| 54 | pokemon.push_back(name); | ||
| 55 | genders[name] = gender; | ||
| 56 | } | ||
| 57 | |||
| 58 | std::random_device randomDevice; | ||
| 59 | std::mt19937 rng{randomDevice()}; | ||
| 60 | std::uniform_int_distribution<int> dist(0, pokemon.size() - 1); | ||
| 61 | |||
| 62 | for (;;) | ||
| 63 | { | ||
| 64 | std::cout << "Generating tweet" << std::endl; | ||
| 65 | |||
| 66 | std::string choice = pokemon[dist(rng)]; | ||
| 67 | std::string gender = genders[choice]; | ||
| 68 | |||
| 69 | std::string result; | ||
| 70 | if (gender == "both") | ||
| 71 | { | ||
| 72 | result = "Because not all {POKE} are male, it is incorrect to refer to a generic {POKE} as \"he\". Only a specific {POKE} may be a \"he\"."; | ||
| 73 | } else if (gender == "male") | ||
| 74 | { | ||
| 75 | result = "As there are multiple {POKE}, it is incorrect to refer to a generic one as \"he\". It is acceptable to refer to a specific one as such."; | ||
| 76 | } else if (gender == "female") | ||
| 77 | { | ||
| 78 | result = "As there are multiple {POKE}, it is incorrect to refer to a generic one as \"she\". It is acceptable to refer to a specific one as such."; | ||
| 79 | } else if (gender == "male legend") | ||
| 80 | { | ||
| 81 | result = "Because {POKE} is legendary and gendered, it is acceptable to refer to it as \"he\"."; | ||
| 82 | } else if (gender == "female legend") | ||
| 83 | { | ||
| 84 | result = "Because {POKE} is legendary and gendered, it is acceptable to refer to it as \"she\"."; | ||
| 85 | } else if (gender == "genderless") | ||
| 86 | { | ||
| 87 | result = "{POKE} is genderless. It is incorrect to ever refer to it as \"he\" or \"she\"."; | ||
| 88 | } | ||
| 89 | |||
| 90 | int tknloc; | ||
| 91 | while ((tknloc = result.find("{POKE}")) != std::string::npos) | ||
| 92 | { | ||
| 93 | std::string token = result.substr(tknloc+1, result.find("}")-tknloc-1); | ||
| 94 | |||
| 95 | result.replace(tknloc, result.find("}")-tknloc+1, choice); | ||
| 96 | } | ||
| 97 | |||
| 98 | result.resize(140); | ||
| 99 | |||
| 100 | try | ||
| 101 | { | ||
| 102 | client.updateStatus(result); | ||
| 103 | } catch (const twitter::twitter_error& e) | ||
| 104 | { | ||
| 105 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
| 106 | } | ||
| 107 | |||
| 108 | std::cout << result << std::endl; | ||
| 109 | std::cout << "Waiting..." << std::endl; | ||
| 110 | |||
| 111 | std::this_thread::sleep_for(std::chrono::hours(11)); | ||
| 112 | |||
| 113 | std::cout << std::endl; | ||
| 114 | } | ||
| 115 | } | ||
