diff --git a/bot.py b/bot.py index 3511a7e..1b853ea 100755 --- a/bot.py +++ b/bot.py @@ -3,6 +3,10 @@ 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()) @@ -22,11 +26,17 @@ def fish(bot, update): def tweet(bot, update): update.message.reply_text("Ooops. Not implemented yet.") +def unknown(bot, update): + update.message.reply_text("Sorry, I didn't understand that command.") + updater.dispatcher.add_handler(telegram.ext.CommandHandler("start", start)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("auth", auth)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", unauth)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("fish", fish)) 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() diff --git a/setup.py b/setup.py index 7a34ba0..5854fa8 100755 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ if dbtype == dbtools.MYSQL: else: db = dbtools.dbObject(dbtype=dbtype, path=dbpath) if not db.isInitialized(): - db.executeQuery("CREATE TABLE tokens(`cid` INT PRIMARY KEY, `ato` TEXT, `ase` TEXT, `fish` INT DEFAULT 0);") + db.executeQuery("CREATE TABLE tokens(`cid` INT PRIMARY KEY, `ato` TEXT, `ase` TEXT, `tweet` BOOLEAN DEFAULT 1, `fish` INT DEFAULT 0);") db.commit() db.closeConnection()