From a12c5fa4ca07610cf7ed51c8cf9a491dc7cd7a27 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 24 Mar 2017 15:34:53 +0100 Subject: [PATCH] Add thread function --- bottools/methods.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bottools/methods.py b/bottools/methods.py index 8cffde4..2dd4e6a 100644 --- a/bottools/methods.py +++ b/bottools/methods.py @@ -253,6 +253,32 @@ def retweet(bot, update, args): except tweepy.error.TweepError as e: bottools.methods.twoExceptions(e, message) +def thread(bot, update, args): + message = update.message or update.callback_query.message + tid = bottools.methods.getTweetID(args[0], message.chat_id) + + i = 0 + + try: + count = int(args[1]) + except: + count = 5 + + tweets = [twitools.getTweet(tid)] + + if tweets[-1].in_reply_to_status_id: + nexttid = tweets[-1].in_reply_to_status_id + + while i < count: + tweets += [twitools.getTweet(nexttid)] + if not tweets[-1].in_reply_to_status_id: + break + nexttid = tweets[-1].in_reply_to_status_id + i += 1 + + for tweet in tweets: + tweetMessage(tweet, update.message.chat_id, bot) + def like(bot, update, args): message = update.message or update.callback_query.message for tweet in args: @@ -292,6 +318,9 @@ def tweetMessage(status, cid, bot): telegram.InlineKeyboardButton("Quote",switch_inline_query_current_chat = "/quote %i " % i) ] + if status.in_reply_to_status_id: + buttons += [telegram.InlineKeyboardButton("View Thread", callback_data = "/thread %i" % i)] + rmu = telegram.InlineKeyboardMarkup(makeMenu(buttons)) bot.sendMessage(chat_id = cid, text = "Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)), reply_markup=rmu) @@ -410,6 +439,7 @@ commands = { "restart": restart, "retweet": retweet, "start": start, + "thread": thread, "timeline": timeline, "togglebroadcasts": togglebroadcasts, "togglementions": mentionstream, @@ -427,6 +457,7 @@ pargs = [ quote, reply, retweet, + thread, timeline, toggleTweet, explicitTweet,