diff options
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | fruity.cpp | 132 | ||||
-rw-r--r-- | owo.cpp | 58 |
3 files changed, 137 insertions, 63 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 805e684..84e43d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -1,12 +1,12 @@ | |||
1 | cmake_minimum_required (VERSION 3.1) | 1 | cmake_minimum_required (VERSION 3.1) |
2 | project (owo) | 2 | project (fruity) |
3 | 3 | ||
4 | add_subdirectory(vendor/verbly) | 4 | add_subdirectory(vendor/verbly) |
5 | add_subdirectory(vendor/libtwittercpp) | 5 | add_subdirectory(vendor/libtwittercpp) |
6 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) | 6 | add_subdirectory(vendor/yaml-cpp EXCLUDE_FROM_ALL) |
7 | 7 | ||
8 | include_directories(vendor/verbly/lib vendor/libtwittercpp/src vendor/yaml-cpp/include) | 8 | include_directories(vendor/verbly/lib vendor/libtwittercpp/src vendor/yaml-cpp/include) |
9 | add_executable(owo owo.cpp) | 9 | add_executable(fruity fruity.cpp) |
10 | set_property(TARGET owo PROPERTY CXX_STANDARD 11) | 10 | set_property(TARGET fruity PROPERTY CXX_STANDARD 11) |
11 | set_property(TARGET owo PROPERTY CXX_STANDARD_REQUIRED ON) | 11 | set_property(TARGET fruity PROPERTY CXX_STANDARD_REQUIRED ON) |
12 | target_link_libraries(owo verbly twitter++ yaml-cpp) | 12 | target_link_libraries(fruity verbly twitter++ yaml-cpp) |
diff --git a/fruity.cpp b/fruity.cpp new file mode 100644 index 0000000..b88bde7 --- /dev/null +++ b/fruity.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | #include <yaml-cpp/yaml.h> | ||
2 | #include <iostream> | ||
3 | #include <sstream> | ||
4 | #include <twitter.h> | ||
5 | #include <verbly.h> | ||
6 | #include <chrono> | ||
7 | #include <thread> | ||
8 | #include <random> | ||
9 | |||
10 | int main(int argc, char** argv) | ||
11 | { | ||
12 | if (argc != 2) | ||
13 | { | ||
14 | std::cout << "usage: fruity [configfile]" << std::endl; | ||
15 | return -1; | ||
16 | } | ||
17 | |||
18 | std::random_device random_device; | ||
19 | std::mt19937 random_engine{random_device()}; | ||
20 | |||
21 | std::string configfile(argv[1]); | ||
22 | YAML::Node config = YAML::LoadFile(configfile); | ||
23 | |||
24 | twitter::auth auth; | ||
25 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | ||
26 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | ||
27 | auth.setAccessKey(config["access_key"].as<std::string>()); | ||
28 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | ||
29 | |||
30 | twitter::client client(auth); | ||
31 | |||
32 | verbly::data database {config["verbly_datafile"].as<std::string>()}; | ||
33 | |||
34 | verbly::noun fruit = database.nouns().with_wnid(113134947).run().front(); // fruit | ||
35 | verbly::noun plants = database.nouns().with_wnid(100017222).run().front(); // plant | ||
36 | verbly::noun drugs = database.nouns().with_wnid(103247620).run().front(); // drug | ||
37 | verbly::noun animals = database.nouns().with_wnid(100015388).run().front(); // animal | ||
38 | |||
39 | for (;;) | ||
40 | { | ||
41 | std::cout << "Generating tweet" << std::endl; | ||
42 | |||
43 | auto n1 = database.nouns().full_hyponym_of(fruit).random().limit(1).run(); | ||
44 | auto n1w = n1.front(); | ||
45 | auto n1hq = database.nouns().hypernym_of(n1w).limit(1).run(); | ||
46 | auto n1h = n1hq.front(); | ||
47 | |||
48 | std::list<std::string> tokens; | ||
49 | |||
50 | int choice = std::uniform_int_distribution<int>(0,2)(random_engine); | ||
51 | if (choice == 0) | ||
52 | { | ||
53 | auto descriptor = database.adjectives().is_pertainymic().random().limit(1).run(); | ||
54 | tokens.push_back(descriptor.front().base_form()); | ||
55 | } else if (choice == 1) | ||
56 | { | ||
57 | auto descriptor = database.adjectives().is_mannernymic().random().limit(1).run(); | ||
58 | tokens.push_back(descriptor.front().base_form()); | ||
59 | } | ||
60 | |||
61 | auto plantThing = database.nouns(); | ||
62 | choice = std::uniform_int_distribution<int>(0,4)(random_engine); | ||
63 | if (choice < 3) | ||
64 | { | ||
65 | if (choice == 0) | ||
66 | { | ||
67 | plantThing.full_hyponym_of(plants); | ||
68 | } else if (choice == 1) | ||
69 | { | ||
70 | plantThing.full_hyponym_of(drugs); | ||
71 | } else if (choice == 2) | ||
72 | { | ||
73 | plantThing.full_hyponym_of(animals); | ||
74 | } | ||
75 | |||
76 | plantThing.is_not_proper().with_complexity(1).random().limit(1); | ||
77 | tokens.push_back(plantThing.run().front().base_form()); | ||
78 | } | ||
79 | |||
80 | auto similar = database.nouns().full_hyponym_of(n1h).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); | ||
81 | if (!similar.empty()) | ||
82 | { | ||
83 | tokens.push_back(similar.front().base_form()); | ||
84 | } else { | ||
85 | auto different = database.nouns().full_hyponym_of(fruit).except(n1w).is_not_proper().with_complexity(1).random().limit(1).run(); | ||
86 | tokens.push_back(different.front().base_form()); | ||
87 | } | ||
88 | |||
89 | std::string fruitName = verbly::implode(std::begin(tokens), std::end(tokens), " "); | ||
90 | |||
91 | std::ostringstream result; | ||
92 | result << n1.front().base_form(); | ||
93 | result << "? "; | ||
94 | |||
95 | choice = std::uniform_int_distribution<int>(0,3)(random_engine); | ||
96 | if (choice == 0) | ||
97 | { | ||
98 | result << "Oh, you mean "; | ||
99 | result << fruitName; | ||
100 | } else if (choice == 1) | ||
101 | { | ||
102 | result << "Don't you mean "; | ||
103 | result << fruitName; | ||
104 | result << "?"; | ||
105 | } else if (choice == 2) | ||
106 | { | ||
107 | result << "You mean "; | ||
108 | result << fruitName; | ||
109 | result << "!"; | ||
110 | } else if (choice == 3) | ||
111 | { | ||
112 | result << "Pfft, everyone just calls it "; | ||
113 | result << fruitName; | ||
114 | result << " now"; | ||
115 | } | ||
116 | |||
117 | std::string tweet = result.str(); | ||
118 | tweet.resize(140); | ||
119 | |||
120 | try | ||
121 | { | ||
122 | client.updateStatus(tweet); | ||
123 | |||
124 | std::cout << tweet << std::endl; | ||
125 | } catch (const twitter::twitter_error& e) | ||
126 | { | ||
127 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
128 | } | ||
129 | |||
130 | std::this_thread::sleep_for(std::chrono::hours(1)); | ||
131 | } | ||
132 | } | ||
diff --git a/owo.cpp b/owo.cpp deleted file mode 100644 index f66e689..0000000 --- a/owo.cpp +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | #include <yaml-cpp/yaml.h> | ||
2 | #include <iostream> | ||
3 | #include <sstream> | ||
4 | #include <twitter.h> | ||
5 | #include <verbly.h> | ||
6 | #include <chrono> | ||
7 | #include <thread> | ||
8 | |||
9 | int main(int argc, char** argv) | ||
10 | { | ||
11 | if (argc != 2) | ||
12 | { | ||
13 | std::cout << "usage: owo [configfile]" << std::endl; | ||
14 | return -1; | ||
15 | } | ||
16 | |||
17 | std::string configfile(argv[1]); | ||
18 | YAML::Node config = YAML::LoadFile(configfile); | ||
19 | |||
20 | twitter::auth auth; | ||
21 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | ||
22 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | ||
23 | auth.setAccessKey(config["access_key"].as<std::string>()); | ||
24 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | ||
25 | |||
26 | twitter::client client(auth); | ||
27 | |||
28 | verbly::data database {config["verbly_datafile"].as<std::string>()}; | ||
29 | |||
30 | verbly::noun bp = database.nouns().with_wnid(105220461).run().front(); // body part | ||
31 | verbly::noun pp = database.nouns().with_wnid(104723816).run().front(); // quality | ||
32 | verbly::noun cp = database.nouns().with_wnid(103051540).run().front(); // clothing | ||
33 | verbly::filter<verbly::noun> filt {bp, pp, cp}; | ||
34 | filt.set_orlogic(true); | ||
35 | |||
36 | for (;;) | ||
37 | { | ||
38 | std::cout << "Generating tweet" << std::endl; | ||
39 | |||
40 | auto ns = database.nouns().full_hyponym_of(filt).is_not_proper().random().limit(1).run(); | ||
41 | verbly::noun n = ns.front(); | ||
42 | |||
43 | std::string result = "*notices ur " + n.base_form() + "* OwO whats this..?"; | ||
44 | result.resize(140); | ||
45 | |||
46 | try | ||
47 | { | ||
48 | client.updateStatus(result); | ||
49 | } catch (const twitter::twitter_error& e) | ||
50 | { | ||
51 | std::cout << "Twitter error: " << e.what() << std::endl; | ||
52 | } | ||
53 | |||
54 | std::cout << result << std::endl; | ||
55 | |||
56 | std::this_thread::sleep_for(std::chrono::hours(1)); | ||
57 | } | ||
58 | } | ||