Make outgoing tweet notifications optional

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-24 22:24:55 +01:00
parent 97bfea2f24
commit 3537379e99
4 changed files with 28 additions and 2 deletions

View file

@ -82,6 +82,12 @@ def toggleTweet(bot, update):
update.message.reply_text(bottools.strings.toggleTweet % (bottools.strings.toggleTweetOn if dbtools.dbHelper().toggleTweet(update.message.chat_id) else bottools.strings.toggleTweetOff))
except tweepy.error.TweepError as e:
bottools.methods.twoExceptions(e, update.message)
def toggleConfirmations(bot, update):
try:
update.message.reply_text(bottools.strings.toggleConfirmations % (bottools.strings.toggleTweetOn if dbtools.dbHelper().toggleConfirmations(update.message.chat_id) else bottools.strings.toggleTweetOff))
except tweepy.error.TweepError as e:
bottools.methods.twoExceptions(e, update.message)
def unknown(bot, update):
update.message.reply_text(bottools.strings.unknownCommand)
@ -184,7 +190,8 @@ def explicitTweet(bot, update, args, reply = None):
else:
status = two.tweet(' '.join(args), reply)
bottools.methods.tweetMessage(status, update.message.chat_id, bot)
if dbtools.dbHelper().getCStatus(update.message.chat_id):
bottools.methods.tweetMessage(status, update.message.chat_id, bot)
except tweepy.error.TweepError as e:
bottools.methods.twoExceptions(e, update.message)
@ -484,7 +491,9 @@ commands = {
"thread": thread,
"timeline": timeline,
"togglebroadcasts": togglebroadcasts,
"toggleconfirmations": toggleConfirmations,
"togglementions": mentionstream,
"toggletweet": toggleTweet,
"tweet": explicitTweet,
"unauth": unauth,
"unfollow": unfollow,

View file

@ -36,6 +36,7 @@ Additionally, you will be able to use the following commands:
* /quote TWEET - Quote a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
* /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. If you do not include any mentions, I will take care of this for you.
* /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
* /toggleconfirmations - Turn on/off notifications about tweets you posted yourself.
* /togglementions - Turn on/off notifications when you are mentioned in a tweet.
* /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups.
* /tweet TEXT - Explicitly tweet TEXT even if automatic tweeting is off (/toggletweet).
@ -55,6 +56,9 @@ Have fun!'''
toggleBroadcasts = '''Broadcast notifications are now %s.'''
toggleConfirmations = '''Confirmations for outgoing tweets are now %s.'''
toggleTweet = '''Automatic tweeting is now %s.'''

View file

@ -144,6 +144,19 @@ class dbObject:
return self.getBStatus(cid)
def getCStatus(self, cid):
try:
self.executeQuery("SELECT confirmations FROM tokens WHERE cid = %i;" % int(cid))
return True if int(self.cur.fetchone()[0]) == 1 else False
except:
raise ValueError("No such user: %i" % int(cid))
def toggleConfirmations(self, cid):
self.executeQuery("UPDATE tokens SET confirmations = NOT confirmations WHERE cid = %i;" % int(cid))
self.commit()
return self.getCStatus(cid)
def getTStatus(self, cid):
try:
self.executeQuery("SELECT tweet FROM tokens WHERE cid = %i;" % int(cid))

View file

@ -65,7 +65,7 @@ if not db.isInitialized():
db.executeQuery("CREATE TABLE names(`id` TEXT NOT NULL, `name` TEXT NOT NULL, `since` INTEGER NOT NULL, `until` INTEGER, PRIMARY KEY(id, until));")
db.executeQuery("CREATE TABLE retweets(id INT PRIMARY KEY, author VARCHAR(30), created_at VARCHAR(30), text TEXT);")
db.executeQuery("CREATE TABLE lyrics(id INTEGER PRIMARY KEY AUTOINCREMENT, text VARCHAR(140) NOT NULL, ref INT NOT NULL default '0', tweet_id INT, active BOOLEAN default '0');")
db.executeQuery("CREATE TABLE tokens(`cid` INT PRIMARY KEY, `ato` TEXT, `ase` TEXT, `tweet` BOOLEAN DEFAULT 1, `fish` INT DEFAULT 0, `mentions` BOOLEAN DEFAULT 0, `broadcast` BOOLEAN DEFAULT 1);")
db.executeQuery("CREATE TABLE tokens(`cid` INT PRIMARY KEY, `ato` TEXT, `ase` TEXT, `tweet` BOOLEAN DEFAULT 1, `fish` INT DEFAULT 0, `mentions` BOOLEAN DEFAULT 0, `broadcast` BOOLEAN DEFAULT 1, `confirmations` BOOLEAN DEFAULT 1);")
db.executeQuery("CREATE TABLE timelines(`cid` INT, `nr` INT, `tid` INT, PRIMARY KEY(cid, nr));")
db.commit()