Add thread function

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-24 15:34:53 +01:00
parent 97958f2497
commit a12c5fa4ca
1 changed files with 31 additions and 0 deletions

View File

@ -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,