From 57d849493bd2d9b8c3b165fc030aa6d9db2e6adf Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Mon, 26 Nov 2018 14:05:08 +0100 Subject: [PATCH] Make 'unbook' available for all The ability to unbook rooms should be accessible to all users. Change-Id: If747141f9cfc1cd74b542071a798cf94ff1db309 --- README.rst | 12 +++++++++--- ptgbot/bot.py | 17 ++++++++++++----- ptgbot/db.py | 6 ++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index cd25bc1..5c8f626 100644 --- a/README.rst +++ b/README.rst @@ -79,6 +79,15 @@ you can use book the room. Example usage:: you can use the ``now`` and ``next`` commands to communicate what topic is being discussed. +unbook +------ + +The ``unbook`` command is used to free up booked slots in the additional rooms. +You should generally not unbook a track without the consent of its track lead. +Example usage:: + + #vitrage unbook Missouri-MonAM + clean ----- @@ -127,9 +136,6 @@ You have to be a channel operator (+o) to use admin commands. ~clean TRACK [TRACK..] Removes active entries for specified track(s) -~unbook SLOTCODE - Removes any booking at the slot named SLOTCODE - ~newday Removes now/next/location entries, to be run at the start of a new day diff --git a/ptgbot/bot.py b/ptgbot/bot.py index f94aebf..8bd6c9b 100644 --- a/ptgbot/bot.py +++ b/ptgbot/bot.py @@ -140,8 +140,19 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.send(chan, "%s: Room %s is now booked on %s for %s" % (nick, room, timeslot, track)) else: - self.send(chan, "%s: invalid slot reference '%s'" % + self.send(chan, "%s: slot '%s' is invalid (or booked)" % (nick, params)) + elif adverb == 'unbook': + room, sep, timeslot = params.partition('-') + if self.data.is_slot_booked_for_track(track, room, timeslot): + self.data.unbook(room, timeslot) + self.send(chan, "%s: Room %s (previously booked for %s) " + "is now free on %s" % + (nick, room, track, timeslot)) + else: + self.send(chan, "%s: slot '%s' is invalid " + "(or not booked for %s)" % + (nick, params, track)) else: self.send(chan, "%s: unknown directive '%s'" % (nick, adverb)) self.usage(chan) @@ -163,10 +174,6 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.send(chan, "Done.") except Exception as e: self.send(chan, "Error loading DB: %s" % e) - elif command == 'unbook': - params = str.join(' ', words[1:]) - room, sep, timeslot = params.partition('-') - self.data.unbook(room, timeslot) elif command == 'newday': self.data.new_day_cleanup() elif command == 'requirevoice': diff --git a/ptgbot/db.py b/ptgbot/db.py index a90ac28..1846ee8 100644 --- a/ptgbot/db.py +++ b/ptgbot/db.py @@ -138,6 +138,12 @@ class PTGDataBase(): except KeyError: return False + def is_slot_booked_for_track(self, track, room, timeslot): + try: + return self.data['schedule'][room][timeslot] == track + except KeyError: + return False + def book(self, track, room, timeslot): self.data['schedule'][room][timeslot] = track self.save()