tweepbot/bot.py

43 lines
1.5 KiB
Python
Raw Normal View History

2017-02-07 21:36:31 +00:00
#!/usr/bin/env python3
2017-02-08 12:06:17 +00:00
import dbtools, logging, setuptools, strings, 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
updater = telegram.ext.Updater(token=setuptools.token())
2017-02-07 21:54:22 +00:00
def start(bot, update):
update.message.reply_text(strings.start % (setuptools.botname(), setuptools.botname()))
2017-02-08 11:26:25 +00:00
def auth(bot, update):
update.message.reply_text("Ooops. Not implemented yet.")
2017-02-07 21:54:22 +00:00
2017-02-08 12:06:17 +00:00
def unauth(bot, update):
2017-02-08 12:12:05 +00:00
dbtools.dbHelper().deleteUser(update.message.chat_id)
update.message.reply_text(strings.unauth % setuptools.url())
2017-02-08 12:06:17 +00:00
2017-02-08 13:09:00 +00:00
def fish(bot, update):
update.message.reply_text("Yummy! Thanks! :3")
def tweet(bot, update):
update.message.reply_text("Ooops. Not implemented yet.")
2017-02-08 13:09:00 +00:00
2017-02-08 13:58:09 +00:00
def unknown(bot, update):
update.message.reply_text("Sorry, I didn't understand that command.")
2017-02-07 22:11:59 +00:00
updater.dispatcher.add_handler(telegram.ext.CommandHandler("start", start))
2017-02-08 11:26:25 +00:00
updater.dispatcher.add_handler(telegram.ext.CommandHandler("auth", auth))
2017-02-08 12:08:09 +00:00
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", unauth))
2017-02-08 13:09:00 +00:00
updater.dispatcher.add_handler(telegram.ext.CommandHandler("fish", fish))
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, tweet))
2017-02-08 13:58:09 +00:00
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.command, unknown))
updater.dispatcher.add_error_handler(log)
2017-02-07 21:54:22 +00:00
2017-02-08 13:16:04 +00:00
updater.start_polling()
updater.idle()