chiark / gitweb /
Add a limit to tweet expansion recursion.
authorJonathan David Amery <jdamery+zgit@ysolde.ucam.org>
Tue, 14 Aug 2018 20:01:06 +0000 (21:01 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Tue, 21 Aug 2018 15:44:15 +0000 (16:44 +0100)
Signed-off-by: Matthew Vernon <matthewv@chiark.greenend.org.uk>
commands.py

index 431a113..fbffa9f 100755 (executable)
@@ -502,7 +502,7 @@ def twitterq(bot,cmd,nick,conn,public,twitapi):
     for stringout in stringsout:
         bot.automsg(public, nick, stringout)
   
-def getTweet(urlstring,twitapi,inclusion=False):
+def getTweet(urlstring,twitapi,inclusion=False,recurlvl=0):
   unobfuscate_urls=True
   expand_included_tweets=True
   stringsout=[]
@@ -578,12 +578,15 @@ def getTweet(urlstring,twitapi,inclusion=False):
 
         if expand_included_tweets:
             if rv.hostname == 'twitter.com' and re.search(r'status/\d+',rv.path):
-                quotedtweet = getTweet(toReplace, twitapi, inclusion=True) # inclusion parameter limits recursion.
-                if not quotedtweet:
-                    quotedtweet = [""]
-                quotedtweet[0] = "Q{ " + quotedtweet[0]
-                quotedtweet[-1] += " }"
-                stringsout = quotedtweet + stringsout
+                if recurlvl > 2
+                  stringsout = [ "{{ Recursion level too high }}" ] + stringsout
+                else:
+                  quotedtweet = getTweet(toReplace, twitapi, inclusion=True, recurlvl=recurlvl+1) # inclusion parameter limits recursion.
+                  if not quotedtweet:
+                      quotedtweet = [""]
+                  quotedtweet[0] = "Q{ " + quotedtweet[0]
+                  quotedtweet[-1] += " }"
+                  stringsout = quotedtweet + stringsout
 
         tweetText = tweetText.replace(url.url, toReplace)