From 247c4e80f8030c11bfd1645ab02770db1284d819 Mon Sep 17 00:00:00 2001 From: Jeppe Toustrup Date: Thu, 26 Feb 2015 19:48:24 +0100 Subject: [PATCH] Improvements to nicks handling in 'repall' command: - Always have the owner of the tweet responding to first in the response - Never include the user's nick in the list - Make sure we don't have duplicate nicks All with the added bonus of avoiding regexing due to Twitter's entities list --- rainbowstream/rainbow.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 5241f0d..8dbd89c 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -530,11 +530,14 @@ 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 tweet['entities']['user_mentions']: + if user['screen_name'] not in nick_ary: + nick_ary.append(user['screen_name']) + if g['original_name'] in nick_ary: + nick_ary.remove(g['original_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) -- 2.25.1