Add automatic tweet toggling

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-08 15:14:03 +01:00
parent 6ea970e1e4
commit 69159d9326
3 changed files with 25 additions and 0 deletions

9
bot.py
View file

@ -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))

View file

@ -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())

View file

@ -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: