plugins/twitter: pick a random search result for hashtags

This commit is contained in:
Ryan Hitchman 2013-09-20 17:35:42 -07:00
parent 4fd611da09
commit a97715d5c0
1 changed files with 4 additions and 0 deletions

View File

@ -17,6 +17,7 @@ def twitter(inp, api_key=None):
getting_id = False
doing_search = False
index_specified = False
if re.match(r'^\d+$', inp):
getting_id = True
@ -25,6 +26,7 @@ def twitter(inp, api_key=None):
try:
inp, index = re.split('\s+', inp, 1)
index = int(index)
index_specified = True
except ValueError:
index = 0
if index < 0:
@ -58,6 +60,8 @@ def twitter(inp, api_key=None):
if doing_search:
try:
tweet = tweet["statuses"]
if not index_specified:
index = random.randint(0, len(tweet) - 1)
except KeyError:
return 'error: no results'