diff --git a/README.rst b/README.rst index 5c8f626..6e7d88b 100644 --- a/README.rst +++ b/README.rst @@ -139,6 +139,13 @@ You have to be a channel operator (+o) to use admin commands. ~newday Removes now/next/location entries, to be run at the start of a new day +~motd LEVEL MESSAGE + Adds a message of the day on top of the rendered page. Level must be one of + info, success, warning or danger. + +~cleanmotd + Removes message of the day on top of the rendered page. + ~emptydb Resets the database entirely to minimal contents diff --git a/html/ptg.html b/html/ptg.html index 0328a30..a5ec4c6 100644 --- a/html/ptg.html +++ b/html/ptg.html @@ -8,7 +8,6 @@ -

OpenStack Project Teams Gathering

See what is being discussed currently at the PTG, and what's coming next.

@@ -30,6 +29,9 @@ } {{/each}} +{{#if motd.message}} +

+{{/if}}

Current discussion topics

diff --git a/ptgbot/bot.py b/ptgbot/bot.py index 8bd6c9b..51b63e2 100644 --- a/ptgbot/bot.py +++ b/ptgbot/bot.py @@ -176,6 +176,13 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.send(chan, "Error loading DB: %s" % e) elif command == 'newday': self.data.new_day_cleanup() + elif command == 'motd': + if len(words) < 3: + self.send(chan, "Not enough params (~motd LEVEL MESSAGE)") + return + self.data.motd(words[1], str.join(' ', words[2:])) + elif command == 'cleanmotd': + self.data.clean_motd() elif command == 'requirevoice': self.data.require_voice() elif command == 'alloweveryone': diff --git a/ptgbot/db.py b/ptgbot/db.py index 1846ee8..338b176 100644 --- a/ptgbot/db.py +++ b/ptgbot/db.py @@ -23,7 +23,8 @@ import random class PTGDataBase(): BASE = {'tracks': [], 'slots': {}, 'now': {}, 'next': {}, 'colors': {}, - 'location': {}, 'schedule': {}, 'voice': 0} + 'location': {}, 'schedule': {}, 'voice': 0, + 'motd': {'message': '', 'level': 'info'}} def __init__(self, config): self.filename = config['db_filename'] @@ -169,12 +170,21 @@ class PTGDataBase(): self.data['now'] = {} self.data['next'] = {} self.data['location'] = {} - self.save() + self.clean_motd() def empty(self): self.data = copy.deepcopy(self.BASE) self.save() + def motd(self, level, message): + if level in ['info', 'success', 'warning', 'danger']: + self.data['motd'] = {'level': level, 'message': message} + self.save() + + def clean_motd(self): + self.data['motd'] = {'level': '', 'message': ''} + self.save() + def save(self): timestamp = datetime.datetime.now() self.data['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format(timestamp)