summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-12-02 00:09:13 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-12-02 00:09:13 -0500
commit8213a9d7f292f8d9c369ed17312194973b406601 (patch)
treeab93f51edb94f65e5c49e270d167ddce8f9c75c5
parenteee2c82d32174395c07dec8e3169a941c43287ff (diff)
downloadtoldya-8213a9d7f292f8d9c369ed17312194973b406601.tar.gz
toldya-8213a9d7f292f8d9c369ed17312194973b406601.tar.bz2
toldya-8213a9d7f292f8d9c369ed17312194973b406601.zip
Bot now respects deletion messages
-rw-r--r--toldya.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/toldya.cpp b/toldya.cpp index 285b82a..e152f05 100644 --- a/toldya.cpp +++ b/toldya.cpp
@@ -25,6 +25,7 @@ int main(int argc, char** argv)
25 }; 25 };
26 26
27 std::vector<twitter::tweet> potential; 27 std::vector<twitter::tweet> potential;
28 std::set<twitter::tweet_id> deletions;
28 std::mutex potential_mutex; 29 std::mutex potential_mutex;
29 30
30 twitter::client client(auth); 31 twitter::client client(auth);
@@ -51,7 +52,7 @@ int main(int argc, char** argv)
51 ) 52 )
52 { 53 {
53 std::lock_guard<std::mutex> potential_guard(potential_mutex); 54 std::lock_guard<std::mutex> potential_guard(potential_mutex);
54 std::cout << n.getTweet().getText() << std::endl; 55 std::cout << n.getTweet().getID() << ": " << n.getTweet().getText() << std::endl;
55 56
56 potential.push_back(std::move(n.getTweet())); 57 potential.push_back(std::move(n.getTweet()));
57 } 58 }
@@ -64,10 +65,16 @@ int main(int argc, char** argv)
64 { 65 {
65 std::cout << "Twitter error while following @" << n.getUser().getScreenName() << ": " << error.what() << std::endl; 66 std::cout << "Twitter error while following @" << n.getUser().getScreenName() << ": " << error.what() << std::endl;
66 } 67 }
68 } else if (n.getType() == twitter::notification::type::deletion)
69 {
70 std::lock_guard<std::mutex> potential_guard(potential_mutex);
71 std::cout << "Tweet " << n.getTweetID() << " was deleted." << std::endl;
72
73 deletions.insert(n.getTweetID());
67 } 74 }
68 }); 75 });
69 76
70 std::this_thread::sleep_for(std::chrono::minutes(1)); 77 std::this_thread::sleep_for(to_wait);
71 78
72 for (;;) 79 for (;;)
73 { 80 {
@@ -108,7 +115,7 @@ int main(int argc, char** argv)
108 std::cout << "Sleeping for " << (waitlen/60/60/24) << " days..." << std::endl; 115 std::cout << "Sleeping for " << (waitlen/60/60/24) << " days..." << std::endl;
109 } 116 }
110 117
111 std::this_thread::sleep_for(to_wait); 118 std::this_thread::sleep_for(std::chrono::minutes(1));
112 119
113 // Unfollow people who have unfollowed us 120 // Unfollow people who have unfollowed us
114 try 121 try
@@ -150,13 +157,16 @@ int main(int argc, char** argv)
150 std::vector<twitter::tweet> to_keep; 157 std::vector<twitter::tweet> to_keep;
151 for (auto& pt : potential) 158 for (auto& pt : potential)
152 { 159 {
153 if (old_friends_set.count(pt.getAuthor().getID()) == 0) 160 if (
161 (old_friends_set.count(pt.getAuthor().getID()) == 0) && // The author has not unfollowed
162 (deletions.count(pt.getID()) == 0)) // The tweet was not deleted
154 { 163 {
155 to_keep.push_back(std::move(pt)); 164 to_keep.push_back(std::move(pt));
156 } 165 }
157 } 166 }
158 167
159 potential = std::move(to_keep); 168 potential = std::move(to_keep);
169 deletions.clear();
160 } catch (const twitter::twitter_error& error) 170 } catch (const twitter::twitter_error& error)
161 { 171 {
162 std::cout << "Twitter error while getting friends/followers: " << error.what() << std::endl; 172 std::cout << "Twitter error while getting friends/followers: " << error.what() << std::endl;