Implement commands in image captions
This commit is contained in:
parent
70f7dfcc85
commit
5812643e01
2 changed files with 25 additions and 11 deletions
|
@ -36,6 +36,7 @@ def twoExceptions(e, message):
|
||||||
def silence(bot, update):
|
def silence(bot, update):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def callback(bot, update):
|
def callback(bot, update):
|
||||||
args = update.callback_query.data.split()
|
args = update.callback_query.data.split()
|
||||||
|
|
||||||
|
@ -46,13 +47,27 @@ def callback(bot, update):
|
||||||
except:
|
except:
|
||||||
status = feature(bot, update)
|
status = feature(bot, update)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
|
||||||
update.callback_query.message.reply_text(bottools.strings.unknownCommand)
|
update.callback_query.message.reply_text(bottools.strings.unknownCommand)
|
||||||
return
|
return
|
||||||
|
|
||||||
if status:
|
if status:
|
||||||
tweetMessage(status, None, bot, callback = update.callback_query)
|
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):
|
def mentionHelper(bot, update):
|
||||||
args = update.message.text.split()
|
args = update.message.text.split()
|
||||||
|
|
||||||
|
@ -63,7 +78,6 @@ def mentionHelper(bot, update):
|
||||||
except:
|
except:
|
||||||
feature(bot, update)
|
feature(bot, update)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
|
||||||
update.message.reply_text(bottools.strings.unknownCommand)
|
update.message.reply_text(bottools.strings.unknownCommand)
|
||||||
|
|
||||||
# Actual methods:
|
# Actual methods:
|
||||||
|
@ -208,8 +222,8 @@ def switch(bot, update, args):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return getTwo(message).getTweet(getTweetID(args[1], cid))
|
return getTwo(message).getTweet(getTweetID(args[1], cid))
|
||||||
except Exception as e:
|
except:
|
||||||
logging.exception(e)
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message.reply_text(bottools.strings.noauth)
|
message.reply_text(bottools.strings.noauth)
|
||||||
|
@ -290,7 +304,7 @@ def explicitTweet(bot, update, args, reply = None):
|
||||||
else:
|
else:
|
||||||
out = mobj
|
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()
|
out.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -375,7 +389,7 @@ def retweet(bot, update, args):
|
||||||
def thread(bot, update, args):
|
def thread(bot, update, args):
|
||||||
message = update.message or update.callback_query.message
|
message = update.message or update.callback_query.message
|
||||||
tid = bottools.methods.getTweetID(args[0], message.chat_id)
|
tid = bottools.methods.getTweetID(args[0], message.chat_id)
|
||||||
two = getTwo(message.chat_id)
|
two = getTwo(message)
|
||||||
|
|
||||||
i = 0
|
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.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.captionHelper))
|
||||||
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.captionHelper))
|
||||||
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.captionHelper))
|
||||||
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.captionHelper))
|
||||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.document, bottools.methods.tweet))
|
|
||||||
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.location, bottools.methods.storeLocation))
|
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.MessageHandler(telegram.ext.Filters.command, bottools.methods.unknown))
|
||||||
|
|
||||||
updater.dispatcher.add_handler(telegram.ext.CallbackQueryHandler(bottools.methods.callback))
|
updater.dispatcher.add_handler(telegram.ext.CallbackQueryHandler(bottools.methods.callback))
|
||||||
|
|
Loading…
Reference in a new issue