From: Jonathan David Amery Date: Tue, 14 Aug 2018 20:01:06 +0000 (+0100) Subject: Add a limit to tweet expansion recursion. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=commitdiff_plain;h=52578cad3e0bf3a4fb059c54b61ea430cce3c4da Add a limit to tweet expansion recursion. Signed-off-by: Matthew Vernon --- diff --git a/commands.py b/commands.py index 431a113..fbffa9f 100755 --- a/commands.py +++ b/commands.py @@ -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)