Implement commands in image captions
This commit is contained in:
parent
70f7dfcc85
commit
5812643e01
|
@ -36,6 +36,7 @@ def twoExceptions(e, message):
|
|||
def silence(bot, update):
|
||||
pass
|
||||
|
||||
|
||||
def callback(bot, update):
|
||||
args = update.callback_query.data.split()
|
||||
|
||||
|
@ -46,13 +47,27 @@ def callback(bot, update):
|
|||
except:
|
||||
status = feature(bot, update)
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
update.callback_query.message.reply_text(bottools.strings.unknownCommand)
|
||||
return
|
||||
|
||||
if status:
|
||||
tweetMessage(status, None, bot, callback = update.callback_query)
|
||||
|
||||
def captionHelper(bot, update):
|
||||
if update.message.caption.startswith("@%s /"):
|
||||
args = update.message.caption.split()[1:]
|
||||
else:
|
||||
args = update.message.caption.split()
|
||||
|
||||
try:
|
||||
feature = commands[args[0][1:]]
|
||||
try:
|
||||
status = feature(bot, update, args[1:])
|
||||
except:
|
||||
status = feature(bot, update)
|
||||
except:
|
||||
update.message.reply_text(bottools.strings.unknownCommand)
|
||||
|
||||
def mentionHelper(bot, update):
|
||||
args = update.message.text.split()
|
||||
|
||||
|
@ -63,7 +78,6 @@ def mentionHelper(bot, update):
|
|||
except:
|
||||
feature(bot, update)
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
update.message.reply_text(bottools.strings.unknownCommand)
|
||||
|
||||
# Actual methods:
|
||||
|
@ -208,8 +222,8 @@ def switch(bot, update, args):
|
|||
|
||||
try:
|
||||
return getTwo(message).getTweet(getTweetID(args[1], cid))
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
except:
|
||||
pass
|
||||
|
||||
else:
|
||||
message.reply_text(bottools.strings.noauth)
|
||||
|
@ -290,7 +304,7 @@ def explicitTweet(bot, update, args, reply = None):
|
|||
else:
|
||||
out = mobj
|
||||
|
||||
status = two.api.update_with_media(filename, update.message.caption, reply, file=out)
|
||||
status = two.api.update_with_media(filename, ' '.join(args), reply, file=out)
|
||||
out.close()
|
||||
|
||||
else:
|
||||
|
@ -375,7 +389,7 @@ def retweet(bot, update, args):
|
|||
def thread(bot, update, args):
|
||||
message = update.message or update.callback_query.message
|
||||
tid = bottools.methods.getTweetID(args[0], message.chat_id)
|
||||
two = getTwo(message.chat_id)
|
||||
two = getTwo(message)
|
||||
|
||||
i = 0
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ if __name__ == "__main__":
|
|||
|
||||
updater.dispatcher.add_handler(telegram.ext.RegexHandler("^@TweepBot \/.*", bottools.methods.mentionHelper))
|
||||
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, bottools.methods.tweet))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.photo, bottools.methods.tweet))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.sticker, bottools.methods.tweet))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.video, bottools.methods.tweet))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.document, bottools.methods.tweet))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.photo, bottools.methods.captionHelper))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.sticker, bottools.methods.captionHelper))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.video, bottools.methods.captionHelper))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.document, bottools.methods.captionHelper))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.location, bottools.methods.storeLocation))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, bottools.methods.tweet))
|
||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.command, bottools.methods.unknown))
|
||||
|
||||
updater.dispatcher.add_handler(telegram.ext.CallbackQueryHandler(bottools.methods.callback))
|
||||
|
|
Loading…
Reference in a new issue