twitools/telegrambot.py

33 lines
1.6 KiB
Python
Raw Normal View History

2017-02-07 21:36:31 +00:00
#!/usr/bin/env python3
import bottools.methods, logging, setuptools, telegram.ext
2017-02-07 21:36:31 +00:00
2017-02-07 22:11:59 +00:00
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
2017-02-08 13:58:09 +00:00
logger = logging.getLogger(__name__)
def log(bot, update, error):
logger.warn("Error %s caused by '%s'" % (error, update))
2017-02-07 22:11:59 +00:00
if __name__ == "__main__":
updater = telegram.ext.Updater(token=setuptools.token())
2017-03-24 00:48:40 +00:00
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))
2017-03-22 00:53:51 +00:00
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))
2017-03-26 18:30:51 +00:00
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))
2017-02-08 13:58:09 +00:00
2017-03-24 00:48:40 +00:00
updater.dispatcher.add_handler(telegram.ext.CallbackQueryHandler(bottools.methods.callback))
updater.dispatcher.add_error_handler(log)
2017-02-07 21:54:22 +00:00
updater.start_polling()
updater.idle()