twitools/bot.py
2017-02-08 15:23:15 +01:00

57 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python3
import dbtools, logging, setuptools, strings, 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))
updater = telegram.ext.Updater(token=setuptools.token())
def start(bot, update):
update.message.reply_text(strings.start % (setuptools.botname(), setuptools.botname()))
def auth(bot, update):
update.message.reply_text("Ooops. Not implemented yet.")
def unauth(bot, update):
dbtools.dbHelper().deleteUser(update.message.chat_id)
update.message.reply_text(strings.unauth % setuptools.url())
def fish(bot, update):
dbtools.dbHelper().addFish(update.message.chat_id)
update.message.reply_text("Yummy! Thanks! :3")
def explicitTweet(bot, update):
update.message.reply_text("Ooops. Not implemented yet.")
def tweet(bot, update):
update.message.reply_text("Ooops. Not implemented yet.")
def toggleTweet(bot, update):
try:
update.message.reply_text(strings.toggleTweet % ("on" if dbtools.dbHelper().toggleTweet(update.message.chat_id) else "off"))
except:
update.message.reply_text(strings.noauth)
def unknown(bot, update):
update.message.reply_text("Sorry, I didn't understand that command.")
updater.dispatcher.add_handler(telegram.ext.CommandHandler("auth", auth))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("fish", fish))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("help", start))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("start", start))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("toggletweet", toggleTweet))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("tweet", explicitTweet))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", unauth))
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, tweet))
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.command, unknown))
updater.dispatcher.add_error_handler(log)
updater.start_polling()
updater.idle()