Browse Source

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
changes/47/620047/1
Thierry Carrez 1 year ago
parent
commit
3b59f982f8
4 changed files with 29 additions and 3 deletions
  1. +7
    -0
      README.rst
  2. +3
    -1
      html/ptg.html
  3. +7
    -0
      ptgbot/bot.py
  4. +12
    -2
      ptgbot/db.py

+ 7
- 0
README.rst View File

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


+ 3
- 1
html/ptg.html View File

@@ -8,7 +8,6 @@
<link rel="stylesheet" href="bootstrap-3.3.7.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>

<div class="container">
<h2>OpenStack Project Teams Gathering</h2>
<p>See what is being discussed currently at the PTG, and what's coming next.<p>
@@ -30,6 +29,9 @@
}
{{/each}}
</style>
{{#if motd.message}}
<div class="alert alert-{{motd.level}}" role="alert">{{motd.message}}</div>
{{/if}}
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Current discussion topics</h3></div>
<table class="table">

+ 7
- 0
ptgbot/bot.py View File

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

+ 12
- 2
ptgbot/db.py View File

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

Loading…
Cancel
Save