twitools/telegrambot.py
Klaus-Uwe Mitterer acfb985d87 Fix reply button
2017-03-24 01:48:40 +01:00

32 lines
1.5 KiB
Python
Executable file

#!/usr/bin/env python3
import bottools.methods, logging, setuptools, telegram.ext
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
def log(bot, update, error):
logger.warn("Error %s caused by '%s'" % (error, update))
if __name__ == "__main__":
updater = telegram.ext.Updater(token=setuptools.token())
for k, v in bottools.methods.commands.items():
updater.dispatcher.add_handler(telegram.ext.CommandHandler(k, v, pass_args = True if v in bottools.methods.pargs else False))
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.command, bottools.methods.unknown))
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.document, bottools.methods.tweet))
updater.dispatcher.add_handler(telegram.ext.CallbackQueryHandler(bottools.methods.callback))
updater.dispatcher.add_error_handler(log)
updater.start_polling()
updater.idle()