# -*- coding: utf-8 -*-
+import json
import logging
-import time
-
import random
+import time
from distbot.bot.worker import Worker
from distbot.common import config
(('Yes.', 'Yeah!', 'Ok!', 'Aye!', 'Great!'), 6),
(('No.', 'Naah..', 'Meh.', 'Nay.', 'You stupid?'), 6),
(('Maybe.', 'Dunno.', 'I don\'t care.'), 3),
- (('Decision tree growing, check back in 20 years.', "OpSec, sorry"
+ (('Decision tree growing, check back in 20 years.', "OpSec, sorry",
"Can't tell right now.", "I need more information.", "Sorry, did you say something?"), 1)
)
+ with open("mampfdb.json", "r") as fd:
+ try:
+ mampfdb = json.load(fd)
+ except:
+ mampfdb = {}
+
+ def is_mampf(self, choice: str):
+ logger.debug(f"is {choice} mampf?")
+ if choice == "mampf":
+ return True
+ else:
+ choice = "nachtisch" if choice == "dessert" else choice
+ return choice.lower() in self.mampfdb
+
+ def choose_mampf(self, choice: str):
+ logger.debug(f"choosing mampf {choice}")
+ if choice == "mampf":
+ all_mampf = [item for entry in self.mampfdb.values() for item in entry]
+ logger.debug(f"all mampf: {all_mampf}")
+ return random.choice(all_mampf)
+ else:
+ choice = "nachtisch" if choice == "dessert" else choice
+ return random.choice(self.mampfdb.get(choice.lower()))
+
@staticmethod
def weighted_choice(choices):
total = sum(w for c, w in choices)
alternatives = words[1:]
logger.debug("Alternatives: %s", str(alternatives))
- # single or no choice
- if len(alternatives) < 2:
- return Action(msg='{}: {}'.format(sender, self.binary_choice(sudo=sudo)))
-
- elif 'choose' not in alternatives:
- choice = random.choice(alternatives)
- return Action(msg='{}: I prefer {}!'.format(sender, choice))
-
- def choose_between(options):
+ def choose_between(options: list[str]):
responses = []
current_choices = []
+ # TODO test that shit
for item in options:
if item == 'choose':
if len(current_choices) < 2:
responses.append(random.choice(current_choices))
return responses
- logger.debug('sent multiple random choices')
- return Action(msg='%s: My choices are: %s!' % (sender, ', '.join(choose_between(alternatives))))
+ # single or no choice
+ if len(alternatives) < 2:
+ if len(alternatives) == 1 and self.is_mampf(alternatives[0]):
+ mampf = self.choose_mampf(alternatives[0])
+ msg = [f"{sender}: {mampf}", f"{sender}: es gibt {mampf}", f"{sender}: du kriegst {mampf}",
+ f"{sender} macht für alle {mampf}", f"{mampf} für {sender}, 230V für mich", "nix gibts!"]
+ return Action(msg=random.choice(msg))
+ else:
+ return Action(msg='{}: {}'.format(sender, self.binary_choice(sudo=sudo)))
+ elif 'choose' not in alternatives:
+ choice = random.choice(alternatives)
+ return Action(msg='{}: I prefer {}!'.format(sender, choice))
+ else:
+ logger.debug('sent multiple random choices')
+ return Action(msg='%s: My choices are: %s!' % (sender, ', '.join(choose_between(alternatives))))
class Magic8Ball(Worker):