From 313ec0dfa5bb617753d0662d78bed345facf30b3 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 16 Jan 2021 12:30:37 +0100 Subject: [PATCH] Handle empty glossary correctly --- xbotlib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xbotlib.py b/xbotlib.py index 7a80182..1751dcb 100644 --- a/xbotlib.py +++ b/xbotlib.py @@ -451,6 +451,10 @@ class GlossBot(Bot): def rand(self, **kwargs): """List a random entry.""" + if not self.db.keys(): + self.reply("Glossary is empty", **kwargs) + return + entry = choice(self.db.keys()) self.reply(f"{entry} - {self.db[entry]}", **kwargs) @@ -458,6 +462,7 @@ class GlossBot(Bot): """List all entries.""" if not self.db.keys(): self.reply("Glossary is empty", **kwargs) + return for entry in self.db.keys(): self.reply(f"{entry} - {self.db[entry]}", **kwargs)