summary refs log tree commit diff stats
path: root/support.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'support.cpp')
-rw-r--r--support.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/support.cpp b/support.cpp new file mode 100644 index 0000000..8dc6c4e --- /dev/null +++ b/support.cpp
@@ -0,0 +1,77 @@
1#include <verbly.h>
2#include <algorithm>
3#include <iostream>
4#include <random>
5#include <vector>
6#include <yaml-cpp/yaml.h>
7#include <twitter.h>
8#include "sentence.h"
9
10int main(int argc, char** argv)
11{
12 if (argc != 2)
13 {
14 std::cout << "usage: support [configfile]" << std::endl;
15 return -1;
16 }
17
18 std::string configfile(argv[1]);
19 YAML::Node config = YAML::LoadFile(configfile);
20
21 twitter::auth auth;
22 auth.setConsumerKey(config["consumer_key"].as<std::string>());
23 auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
24 auth.setAccessKey(config["access_key"].as<std::string>());
25 auth.setAccessSecret(config["access_secret"].as<std::string>());
26
27 twitter::client client(auth);
28
29 std::random_device randomDevice;
30 std::mt19937 rng{randomDevice()};
31
32 verbly::database database(config["verbly_datafile"].as<std::string>());
33 sentence generator(database, rng);
34
35 for (;;)
36 {
37 verbly::word adjective = database.words(
38 (verbly::notion::partOfSpeech == verbly::part_of_speech::adjective)
39 && (verbly::word::antiPertainyms %=
40 (verbly::word::forms(verbly::inflection::plural)))).first();
41
42 verbly::word noun = database.words(
43 (verbly::notion::partOfSpeech == verbly::part_of_speech::noun)
44 && (verbly::word::pertainyms %= adjective)
45 && (verbly::word::forms(verbly::inflection::plural))).first();
46
47 verbly::token action = {
48 "RT if you ARE",
49 verbly::token::punctuation(",", adjective),
50 "if you SUPPORT",
51 verbly::token::punctuation(",",
52 verbly::token(noun, verbly::inflection::plural)),
53 "or if you",
54 generator.generate()};
55
56 std::string result = action.compile();
57 if (result.length() <= 140)
58 {
59 std::cout << result << std::endl;
60
61 try
62 {
63 client.updateStatus(result);
64
65 std::cout << "Tweeted!" << std::endl;
66 } catch (const twitter::twitter_error& e)
67 {
68 std::cout << "Twitter error: " << e.what() << std::endl;
69 }
70
71 std::this_thread::sleep_for(std::chrono::hours(1));
72
73 std::cout << std::endl;
74 }
75 }
76}
77