about summary refs log tree commit diff stats
path: root/wordplay.cpp
blob: dedd812b78a8c6367ee89925b029df3ebaac4f1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <yaml-cpp/yaml.h>
#include <string>
#include <iostream>
#include <list>
#include <algorithm>
#include <twitter.h>
#include <verbly.h>
#include <chrono>
#include <thread>

int main(int argc, char** argv)
{
  YAML::Node config = YAML::LoadFile("config.yml");
    
  twitter::auth auth;
  auth.setConsumerKey(config["consumer_key"].as<std::string>());
  auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
  auth.setAccessKey(config["access_key"].as<std::string>());
  auth.setAccessSecret(config["access_secret"].as<std::string>());
  
  twitter::client client(auth);
  
  verbly::data database("data.sqlite3");
  
  for (;;)
  {
    // Generate the most amazing jokes you've ever heard
    auto adjq = database.adjectives().has_rhyming_noun().has_synonyms().random().limit(1).run();
    if (adjq.empty())
    {
      continue;
    }
    
    verbly::adjective rhmadj = adjq.front();
    
    auto nounq = database.nouns().rhymes_with(rhmadj).is_hyponym().random().limit(1).run();
    if (nounq.empty())
    {
      continue;
    }
    
    verbly::noun rhmnoun = nounq.front();
    
    auto hypq = database.nouns().hypernym_of(rhmnoun).random().limit(1).run();
    if (hypq.empty())
    {
      continue;
    }
    
    verbly::noun hyp = hypq.front();
    
    auto synq = database.adjectives().synonym_of(rhmadj).random().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;
    }
    
    try
    {
      client.updateStatus(result.str());
      
      std::cout << "Tweeted!" << std::endl;
    } catch (const twitter::twitter_error& e)
    {
      std::cout << "Twitter error: " << e.what() << std::endl;
    }

    std::cout << "Waiting..." << std::endl;
    
    std::this_thread::sleep_for(std::chrono::hours(1));
  }
}