about summary refs log tree commit diff stats
path: root/snitch.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-05-20 16:27:58 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-05-20 16:27:58 -0400
commit7f90d586f1eeca0354b0e4500645e72b5b9f1021 (patch)
treea06ca9c9a7b31769abcaf298021e95f928e2e0f1 /snitch.cpp
parent3fa8e925133f380be11a8d8ce52cc34403f4f191 (diff)
downloadsnitch-7f90d586f1eeca0354b0e4500645e72b5b9f1021.tar.gz
snitch-7f90d586f1eeca0354b0e4500645e72b5b9f1021.tar.bz2
snitch-7f90d586f1eeca0354b0e4500645e72b5b9f1021.zip
Maintain a list of friends so that we can filter notifications
Diffstat (limited to 'snitch.cpp')
-rw-r--r--snitch.cpp50
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 }