Merge pull request #90 from Tenzer/better-repall
authorOrakaro <DTVD@users.noreply.github.com>
Sun, 8 Mar 2015 05:20:14 +0000 (14:20 +0900)
committerOrakaro <DTVD@users.noreply.github.com>
Sun, 8 Mar 2015 05:20:14 +0000 (14:20 +0900)
Better nick handling in 'repall'

rainbowstream/rainbow.py

index 5241f0d..742930e 100644 (file)
@@ -530,11 +530,13 @@ def reply_all():
     tid = c['tweet_dict'][id]
     original_tweet = t.statuses.show(id=tid)
     text = original_tweet['text']
-    owner = '@' + original_tweet['user']['screen_name']
-    nick_ary = ['@' + re.sub('[\W_]', '', w)
-                for w in text.split() if w.startswith('@')] + [owner]
+    nick_ary = [original_tweet['user']['screen_name']]
+    for user in list(original_tweet['entities']['user_mentions']):
+        if user['screen_name'] not in nick_ary \
+                and user['screen_name'] != g['original_name']:
+            nick_ary.append(user['screen_name'])
     status = ' '.join(g['stuff'].split()[1:])
-    status = ' '.join(nick_ary) + ' ' + str2u(status)
+    status = ' '.join(['@' + nick for nick in nick_ary]) + ' ' + str2u(status)
     t.statuses.update(status=status, in_reply_to_status_id=tid)