# -*- coding: utf-8 -*-
+import json
import random
from distbot.bot.worker import 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 - ",
]
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))