Add emergency messages (~motd and ~cleanmotd)

Add admin command to add (and clean) a message of the day (motd)
to the rendered page. Can be used for emergency messages (using
level 'danger') or more general information.

Change-Id: Ie84d1a826c2f84a7ccdafd08176eef9aa2c5a3f1
This commit is contained in:
Thierry Carrez 2018-11-26 14:34:31 +01:00
parent 57d849493b
commit 3b59f982f8
4 changed files with 29 additions and 3 deletions

View File

@ -139,6 +139,13 @@ You have to be a channel operator (+o) to use admin commands.
~newday ~newday
Removes now/next/location entries, to be run at the start of a new day 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 ~emptydb
Resets the database entirely to minimal contents Resets the database entirely to minimal contents

View File

@ -8,7 +8,6 @@
<link rel="stylesheet" href="bootstrap-3.3.7.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="bootstrap-3.3.7.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h2>OpenStack Project Teams Gathering</h2> <h2>OpenStack Project Teams Gathering</h2>
<p>See what is being discussed currently at the PTG, and what's coming next.<p> <p>See what is being discussed currently at the PTG, and what's coming next.<p>
@ -30,6 +29,9 @@
} }
{{/each}} {{/each}}
</style> </style>
{{#if motd.message}}
<div class="alert alert-{{motd.level}}" role="alert">{{motd.message}}</div>
{{/if}}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Current discussion topics</h3></div> <div class="panel-heading"><h3 class="panel-title">Current discussion topics</h3></div>
<table class="table"> <table class="table">

View File

@ -176,6 +176,13 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot):
self.send(chan, "Error loading DB: %s" % e) self.send(chan, "Error loading DB: %s" % e)
elif command == 'newday': elif command == 'newday':
self.data.new_day_cleanup() 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': elif command == 'requirevoice':
self.data.require_voice() self.data.require_voice()
elif command == 'alloweveryone': elif command == 'alloweveryone':

View File

@ -23,7 +23,8 @@ import random
class PTGDataBase(): class PTGDataBase():
BASE = {'tracks': [], 'slots': {}, 'now': {}, 'next': {}, 'colors': {}, BASE = {'tracks': [], 'slots': {}, 'now': {}, 'next': {}, 'colors': {},
'location': {}, 'schedule': {}, 'voice': 0} 'location': {}, 'schedule': {}, 'voice': 0,
'motd': {'message': '', 'level': 'info'}}
def __init__(self, config): def __init__(self, config):
self.filename = config['db_filename'] self.filename = config['db_filename']
@ -169,12 +170,21 @@ class PTGDataBase():
self.data['now'] = {} self.data['now'] = {}
self.data['next'] = {} self.data['next'] = {}
self.data['location'] = {} self.data['location'] = {}
self.save() self.clean_motd()
def empty(self): def empty(self):
self.data = copy.deepcopy(self.BASE) self.data = copy.deepcopy(self.BASE)
self.save() 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): def save(self):
timestamp = datetime.datetime.now() timestamp = datetime.datetime.now()
self.data['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format(timestamp) self.data['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format(timestamp)