]> git.aero2k.de Git - urlbot-v3.git/commitdiff
Fix Choose plugin crash when mampfdb.json is missing
authorThorsten <mail@aero2k.de>
Fri, 17 Jul 2026 20:23:29 +0000 (22:23 +0200)
committerThorsten <mail@aero2k.de>
Fri, 17 Jul 2026 20:23:29 +0000 (22:23 +0200)
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 <noreply@anthropic.com>
mampfdb.json [new file with mode: 0644]
src/distbot/plugins/basic.py

diff --git a/mampfdb.json b/mampfdb.json
new file mode 100644 (file)
index 0000000..aac3b74
--- /dev/null
@@ -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"
+  ]
+}
index 613f88653ea1ad5fb579176470c2f7206b8c715e..2ecde3d763a89e446b54421e6f9477e7acc79da5 100644 (file)
@@ -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?")