diff options
| -rw-r--r-- | snitch.cpp | 50 |
1 files changed, 32 insertions, 18 deletions
| diff --git a/snitch.cpp b/snitch.cpp index 3fcb3d0..cd5153b 100644 --- a/snitch.cpp +++ b/snitch.cpp | |||
| @@ -23,30 +23,44 @@ int main(int argc, char** argv) | |||
| 23 | img_file.close(); | 23 | img_file.close(); |
| 24 | 24 | ||
| 25 | twitter::client client(auth); | 25 | twitter::client client(auth); |
| 26 | std::set<twitter::user_id> streamed_friends; | ||
| 26 | client.setUserStreamNotifyCallback([&] (twitter::notification n) { | 27 | client.setUserStreamNotifyCallback([&] (twitter::notification n) { |
| 27 | if (n.getType() == twitter::notification::type::tweet) | 28 | if (n.getType() == twitter::notification::type::friends) |
| 28 | { | 29 | { |
| 29 | std::string orig = n.getTweet().getText(); | 30 | streamed_friends = n.getFriends(); |
| 30 | std::string canonical; | 31 | } else if (n.getType() == twitter::notification::type::follow) |
| 31 | std::transform(std::begin(orig), std::end(orig), std::back_inserter(canonical), [] (char ch) { | 32 | { |
| 32 | return std::tolower(ch); | 33 | streamed_friends.insert(n.getUserID()); |
| 33 | }); | 34 | } else if (n.getType() == twitter::notification::type::unfollow) |
| 34 | 35 | { | |
| 35 | if (canonical.find("calling the cops") != std::string::npos) | 36 | streamed_friends.erase(n.getUserID()); |
| 37 | } else if (n.getType() == twitter::notification::type::tweet) | ||
| 38 | { | ||
| 39 | // Only monitor people you are following | ||
| 40 | if (streamed_friends.count(n.getTweet().getAuthor().getID()) == 1) | ||
| 36 | { | 41 | { |
| 37 | std::cout << "Calling the cops on @" << n.getTweet().getAuthor().getScreenName() << std::endl; | 42 | std::string orig = n.getTweet().getText(); |
| 38 | 43 | std::string canonical; | |
| 39 | long media_id; | 44 | std::transform(std::begin(orig), std::end(orig), std::back_inserter(canonical), [] (char ch) { |
| 40 | twitter::response resp = client.uploadMedia("image/jpeg", (const char*) img_buf, img_len, media_id); | 45 | return std::tolower(ch); |
| 41 | if (resp != twitter::response::ok) | 46 | }); |
| 47 | |||
| 48 | if (canonical.find("calling the cops") != std::string::npos) | ||
| 42 | { | 49 | { |
| 43 | std::cout << "Twitter error while uploading image: " << resp << std::endl; | 50 | std::cout << "Calling the cops on @" << n.getTweet().getAuthor().getScreenName() << std::endl; |
| 44 | } else { | 51 | |
| 45 | twitter::tweet tw; | 52 | long media_id; |
| 46 | resp = client.updateStatus("@" + n.getTweet().getAuthor().getScreenName(), tw, n.getTweet(), {media_id}); | 53 | twitter::response resp = client.uploadMedia("image/jpeg", (const char*) img_buf, img_len, media_id); |
| 47 | if (resp != twitter::response::ok) | 54 | if (resp != twitter::response::ok) |
| 48 | { | 55 | { |
| 49 | std::cout << "Twitter error while tweeting: " << resp << std::endl; | 56 | std::cout << "Twitter error while uploading image: " << resp << std::endl; |
| 57 | } else { | ||
| 58 | twitter::tweet tw; | ||
| 59 | resp = client.updateStatus("@" + n.getTweet().getAuthor().getScreenName(), tw, n.getTweet(), {media_id}); | ||
| 60 | if (resp != twitter::response::ok) | ||
| 61 | { | ||
| 62 | std::cout << "Twitter error while tweeting: " << resp << std::endl; | ||
| 63 | } | ||
| 50 | } | 64 | } |
| 51 | } | 65 | } |
| 52 | } | 66 | } |
