From 69159d93268991f0870a489ea8ac47309a9dcf09 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 8 Feb 2017 15:14:03 +0100 Subject: [PATCH] Add automatic tweet toggling --- bot.py | 9 +++++++++ dbtools/__init__.py | 12 ++++++++++++ strings.py | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/bot.py b/bot.py index 1b853ea..56b9e93 100755 --- a/bot.py +++ b/bot.py @@ -23,9 +23,15 @@ def unauth(bot, update): def fish(bot, update): 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): + update.message.reply_text(strings.toggleTweet % ("on" if dbtools.dbHelper().toggleTweet(update.message.chat_id) else "off") + def unknown(bot, update): update.message.reply_text("Sorry, I didn't understand that command.") @@ -33,6 +39,9 @@ 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.CommandHandler("toggletweet", toggleTweet)) +updater.dispatcher.add_handler(telegram.ext.CommandHandler("tweet", explicitTweet)) + updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, tweet)) updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.command, unknown)) diff --git a/dbtools/__init__.py b/dbtools/__init__.py index eeca06a..137ddc3 100644 --- a/dbtools/__init__.py +++ b/dbtools/__init__.py @@ -85,6 +85,18 @@ class dbObject: except: return False + def toggleTweet(self, cid): + try: + self.executeQuery("UPDATE tokens SET tweet = NOT tweet WHERE cid = %i;" % int(cid)) + self.commit() + + self.executeQuery("SELECT tweet FROM tokens WHERE cid = %i;" % int(cid)) + + return True if self.cur.fetchone()[0] == 1 else False + + except: + raise ValueError("No such user: %i" % int(cid)) + def dbHelper(): if setuptools.dbtype() == SQLITE: return dbObject(dbtype=SQLITE, path=setuptools.dbpath()) diff --git a/strings.py b/strings.py index d16c75f..3c40adc 100644 --- a/strings.py +++ b/strings.py @@ -16,6 +16,10 @@ Additionally, you will be able to use the following commands: Have fun!''' + +toggleTweet = '''Automatic tweeting is now %s.''' + + unauth = '''You're leaving already? :( I hope you had a good time with me. If there is anything you would like to tell me or my developers, please drop us a note at: