twitools/telegrambot.py
2017-03-26 20:30:51 +02:00

33 lines
1.6 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.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.command, bottools.methods.unknown))
updater.dispatcher.add_handler(telegram.ext.CallbackQueryHandler(bottools.methods.callback))
updater.dispatcher.add_error_handler(log)
updater.start_polling()
updater.idle()