Add distinct broadcast and emergency methods
This commit is contained in:
parent
66ae28d589
commit
a50b0c08b0
|
@ -249,6 +249,14 @@ def mentionstream(bot, update):
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
bottools.methods.twoExceptions(e, update.message)
|
bottools.methods.twoExceptions(e, update.message)
|
||||||
|
|
||||||
|
# Admin interaction
|
||||||
|
|
||||||
|
def togglebroadcasts(bot, update):
|
||||||
|
try:
|
||||||
|
update.message.reply_text(bottools.strings.toggleBroadcasts % (bottools.strings.toggleTweetOn if dbtools.dbHelper().toggleBroadcasts(update.message.chat_id) else bottools.strings.toggleTweetOff))
|
||||||
|
except tweepy.error.TweepError as e:
|
||||||
|
bottools.methods.twoExceptions(e, update.message)
|
||||||
|
|
||||||
# Administrator
|
# Administrator
|
||||||
|
|
||||||
def isadmin(message):
|
def isadmin(message):
|
||||||
|
@ -266,6 +274,13 @@ def restart(bot, update):
|
||||||
bottools.methods.unknown(bot, update)
|
bottools.methods.unknown(bot, update)
|
||||||
|
|
||||||
def broadcast(bot, update, args):
|
def broadcast(bot, update, args):
|
||||||
|
if bottools.methods.isadmin(update.message):
|
||||||
|
for u in dbtools.dbHelper().broadcastUsers():
|
||||||
|
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
||||||
|
else:
|
||||||
|
bottools.methods.unknown(bot, update)
|
||||||
|
|
||||||
|
def emergency(bot, update, args):
|
||||||
if bottools.methods.isadmin(update.message):
|
if bottools.methods.isadmin(update.message):
|
||||||
for u in dbtools.dbHelper().allUsers():
|
for u in dbtools.dbHelper().allUsers():
|
||||||
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
bot.sendMessage(chat_id = u, text = ' '.join(args))
|
||||||
|
|
|
@ -44,11 +44,16 @@ Additionally, you will be able to use the following commands:
|
||||||
|
|
||||||
If you have any further questions about these commands, I'll try to help you. Just use /help COMMAND for that. For instance, "/help timeline" will show you further details about the /timeline command.
|
If you have any further questions about these commands, I'll try to help you. Just use /help COMMAND for that. For instance, "/help timeline" will show you further details about the /timeline command.
|
||||||
|
|
||||||
|
Every once in a while, I may want to tell you about new features. If you don't want to receive these messages, you can opt out using /togglebroadcasts. Please note that you will still receive urgent notices if necessary.
|
||||||
|
|
||||||
In case you ever wish to leave, you can use /logout. Of course, you're always welcome to login again after that.
|
In case you ever wish to leave, you can use /logout. Of course, you're always welcome to login again after that.
|
||||||
|
|
||||||
Have fun!'''
|
Have fun!'''
|
||||||
|
|
||||||
|
|
||||||
|
toggleBroadcasts = '''Broadcast notifications are now %s.'''
|
||||||
|
|
||||||
|
|
||||||
toggleTweet = '''Automatic tweeting is now %s.'''
|
toggleTweet = '''Automatic tweeting is now %s.'''
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,12 +131,23 @@ class dbObject:
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def getBStatus(self, cid):
|
||||||
|
try:
|
||||||
|
self.executeQuery("SELECT broadcast 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 toggleBroadcasts(self, cid):
|
||||||
|
self.executeQuery("UPDATE tokens SET broadcast = NOT broadcast WHERE cid = %i;" % int(cid))
|
||||||
|
self.commit()
|
||||||
|
|
||||||
|
return self.getBStatus(cid)
|
||||||
|
|
||||||
def getTStatus(self, cid):
|
def getTStatus(self, cid):
|
||||||
try:
|
try:
|
||||||
self.executeQuery("SELECT tweet FROM tokens WHERE cid = %i;" % int(cid))
|
self.executeQuery("SELECT tweet FROM tokens WHERE cid = %i;" % int(cid))
|
||||||
|
|
||||||
return True if int(self.cur.fetchone()[0]) == 1 else False
|
return True if int(self.cur.fetchone()[0]) == 1 else False
|
||||||
|
|
||||||
except:
|
except:
|
||||||
raise ValueError("No such user: %i" % int(cid))
|
raise ValueError("No such user: %i" % int(cid))
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -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 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 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 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);")
|
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 timelines(`cid` INT, `nr` INT, `tid` INT, PRIMARY KEY(cid, nr));")
|
db.executeQuery("CREATE TABLE timelines(`cid` INT, `nr` INT, `tid` INT, PRIMARY KEY(cid, nr));")
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,9 @@ if __name__ == "__main__":
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("retweet", bottools.methods.retweet, pass_args=True))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("retweet", bottools.methods.retweet, pass_args=True))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("start", bottools.methods.start))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("start", bottools.methods.start))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("timeline", bottools.methods.timeline, pass_args=True))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("timeline", bottools.methods.timeline, pass_args=True))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("toggletweet", bottools.methods.toggleTweet))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("togglebroadcasts", bottools.methods.togglebroadcasts))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("togglementions", bottools.methods.mentionstream))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("togglementions", bottools.methods.mentionstream))
|
||||||
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("toggletweet", bottools.methods.toggleTweet))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("tweet", bottools.methods.explicitTweet, pass_args=True))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("tweet", bottools.methods.explicitTweet, pass_args=True))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", bottools.methods.unauth))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", bottools.methods.unauth))
|
||||||
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unfollow", bottools.methods.unfollow, pass_args=True))
|
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unfollow", bottools.methods.unfollow, pass_args=True))
|
||||||
|
|
Loading…
Reference in a new issue