From 27ff58c0e32f3f9c01751049ce32f3df494666fd Mon Sep 17 00:00:00 2001 From: Thorsten Date: Fri, 23 Jun 2023 21:19:09 +0200 Subject: [PATCH] add some machine learning --- distbot/plugins/didyouknow.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/distbot/plugins/didyouknow.py b/distbot/plugins/didyouknow.py index 738dd12..f3adbc5 100644 --- a/distbot/plugins/didyouknow.py +++ b/distbot/plugins/didyouknow.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import json import random from distbot.bot.worker import Worker @@ -20,6 +21,10 @@ class DidYouKnow(Worker): description = "smart bot" usage = "wusstest ihr schon." + def __init__(self, actionqueue): + super().__init__(actionqueue) + self.dynamic_db = "didyouknow.json" + answers = [ "Nö. Aber: ", "Olle Kamelle - ", @@ -29,7 +34,16 @@ class DidYouKnow(Worker): ] def parse_body(self, msg): - fact = random.choice(DB) + with open(self.dynamic_db, "r+") as fd: + try: + db = json.load(fd) + except Exception as e: + db = {"quotes": []} + fact = random.choice(DB + db["quotes"]) + db["quotes"].append(msg["body"]) + + json.dump(db, fd, indent=2) + answer = random.choice(self.answers) return Action(msg="{} {}".format(answer, fact)) -- 2.39.2