Handle empty glossary correctly

This commit is contained in:
Luke Murphy 2021-01-16 12:30:37 +01:00
parent deeeaffd77
commit 313ec0dfa5
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 5 additions and 0 deletions

View File

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