only show twitter url when one was not provided initially

This commit is contained in:
jesopo 2019-10-08 14:21:15 +01:00
parent 37e375c31f
commit 1b3ee1cb89
2 changed files with 9 additions and 5 deletions

View file

@ -166,7 +166,8 @@ class Module(ModuleManager.BaseModule):
tweet = self._from_username(target) tweet = self._from_username(target)
if tweet: if tweet:
tweet_str = format._tweet(self.exports, event["server"], tweet) tweet_str = format._tweet(self.exports, event["server"], tweet,
from_url=not url_match==None)
event["stdout"].write(tweet_str) event["stdout"].write(tweet_str)
else: else:
event["stderr"].write("Invalid tweet identifiers provided") event["stderr"].write("Invalid tweet identifiers provided")
@ -183,6 +184,7 @@ class Module(ModuleManager.BaseModule):
tweet_id = event["match"].group(1) tweet_id = event["match"].group(1)
tweet = self._from_id(tweet_id) tweet = self._from_id(tweet_id)
if tweet: if tweet:
tweet_str = format._tweet(self.exports, event["server"], tweet) tweet_str = format._tweet(self.exports, event["server"], tweet,
from_url=True)
event["stdout"].write(tweet_str) event["stdout"].write(tweet_str)

View file

@ -6,7 +6,7 @@ def _timestamp(dt):
since, unit = utils.time_unit(seconds_since) since, unit = utils.time_unit(seconds_since)
return "%s %s ago" % (since, unit) return "%s %s ago" % (since, unit)
def _tweet(exports, server, tweet): def _tweet(exports, server, tweet, from_url):
linked_id = tweet.id linked_id = tweet.id
username = tweet.user.screen_name username = tweet.user.screen_name
@ -17,8 +17,10 @@ def _tweet(exports, server, tweet):
tweet_link = "https://twitter.com/%s/status/%s" % (username, tweet_link = "https://twitter.com/%s/status/%s" % (username,
linked_id) linked_id)
short_url = exports.get_one("shorturl")(server, tweet_link) short_url = ""
short_url = " - %s" % short_url if short_url else "" if not from_url:
short_url = exports.get_one("shorturl")(server, tweet_link)
short_url = " - %s" % short_url if short_url else ""
created_at = _timestamp(tweet.created_at) created_at = _timestamp(tweet.created_at)
# having to use hasattr here is nasty. # having to use hasattr here is nasty.