From 52578cad3e0bf3a4fb059c54b61ea430cce3c4da Mon Sep 17 00:00:00 2001 From: Jonathan David Amery Date: Tue, 14 Aug 2018 21:01:06 +0100 Subject: [PATCH] Add a limit to tweet expansion recursion. Signed-off-by: Matthew Vernon --- commands.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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) -- 2.30.2