From ed9ab0c7a75ae2b227f26ea3e8346c85779663cd Mon Sep 17 00:00:00 2001 From: Thorsten Date: Fri, 17 Jul 2026 22:23:29 +0200 Subject: [PATCH] Fix Choose plugin crash when mampfdb.json is missing open() raised an uncaught FileNotFoundError at class-definition time, which is never caught by Worker.callback and crashed the whole worker process on any deployment that hadn't manually placed the file (e.g. munin, a fresh clone). Also ship mampfdb.json itself so the food-choice feature works instead of silently falling back to an empty dict. Co-Authored-By: Claude Sonnet 5 --- mampfdb.json | 57 ++++++++++++++++++++++++++++++++++++ src/distbot/plugins/basic.py | 8 ++--- 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 mampfdb.json diff --git a/mampfdb.json b/mampfdb.json new file mode 100644 index 0000000..aac3b74 --- /dev/null +++ b/mampfdb.json @@ -0,0 +1,57 @@ +{ + "frühstück": [ + "Brot", + "Brötchen", + "Pizza von gestern", + "Kuchen", + "Müsli", + "Haferschleim", + "kommerzielles Zuckerweizengericht", + "Pfannkuchen" + ], + "mittagessen": [ + "Stück Fleisch", + "Stück Fisch", + "Bratwurst", + "Nudelauflauf", + "Kartoffelauflauf", + "Eintopf", + "Suppe", + "Pasta mit Pesto", + "Lasagne", + "Käsekeks", + "Brot", + "Curry", + "Pommes", + "Backkartoffeln", + "Currywurst", + "Salat", + "Pfannkuchen", + "Flammkuchen" + ], + "abendessen": [ + "Brot", + "Brötchen", + "Sandwich", + "Suppe", + "Pfannkuchen" + ], + "nachtisch": [ + "Eis", + "Kuchen", + "Quark", + "Pudding", + "Mousse", + "Obst", + "Brokkoli", + "Milchreis", + "Griesbrei", + "Keks", + "Crème Brûlée", + "Jokurt", + "Crêpe", + "Tiramisu", + "Mus", + "Waffeln" + ] +} diff --git a/src/distbot/plugins/basic.py b/src/distbot/plugins/basic.py index 613f886..2ecde3d 100644 --- a/src/distbot/plugins/basic.py +++ b/src/distbot/plugins/basic.py @@ -249,11 +249,11 @@ class Choose(Worker): "Can't tell right now.", "I need more information.", "Sorry, did you say something?"), 1) ) - with open("mampfdb.json", "r") as fd: - try: + try: + with open("mampfdb.json", "r") as fd: mampfdb = json.load(fd) - except: - mampfdb = {} + except (OSError, json.JSONDecodeError): + mampfdb = {} def is_mampf(self, choice: str): logger.debug(f"is {choice} mampf?") -- 2.47.3