diff --git a/modules/Twitter.py b/modules/Twitter.py index 3966e5a..7ad78d9 100644 --- a/modules/Twitter.py +++ b/modules/Twitter.py @@ -84,7 +84,7 @@ class Twitter(Module): if whats[1] == 'status' and len(whats) == 3: try: tweet = self.twit.GetStatus(whats[2]) - return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet)) + return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet=tweet, print_source=True)) except twitter.TwitterError as e: return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e)) elif whats[1] == 'user' and len(whats) == 3: @@ -92,11 +92,11 @@ class Twitter(Module): tweets = self.twit.GetUserTimeline(screen_name=whats[2], count=30, include_rts=True) if tweets: tweet = tweets[0] - return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet)) + return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet=tweet)) except twitter.TwitterError as e: return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e)) - def tweet_or_retweet_text(self, tweet): + def tweet_or_retweet_text(self, tweet, print_source=False): """ Return a string of the author and text body of a status, accounting for whether or not the fetched status is a @@ -105,9 +105,15 @@ class Twitter(Module): if tweet.retweeted_status: retweet = tweet.retweeted_status - return '(RT) %s: %s' % (retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore')) + if print_source: + return '%s (RT %s): %s' % (tweet.user.name.encode('utf-8', 'ignore'), retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore')) + else: + return '(RT %s): %s' % (retweet.user.name.encode('utf-8', 'ignore'), retweet.text.encode('utf-8', 'ignore')) else: - return '%s: %s' % (tweet.user.name.encode('utf-8', 'ignore'), tweet.text.encode('utf-8', 'ignore')) + if print_source: + return '%s: %s' % (tweet.user.name.encode('utf-8', 'ignore'), tweet.text.encode('utf-8', 'ignore')) + else: + return '%s' % (tweet.text.encode('utf-8', 'ignore')) # vi:tabstop=4:expandtab:autoindent # kate: indent-mode python;indent-width 4;replace-tabs on;