summaryrefslogtreecommitdiffstats
path: root/kalauerbot/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'kalauerbot/bot.py')
-rw-r--r--kalauerbot/bot.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/kalauerbot/bot.py b/kalauerbot/bot.py
index 912584a..de95ade 100644
--- a/kalauerbot/bot.py
+++ b/kalauerbot/bot.py
@@ -104,8 +104,15 @@ class Kalauerbot(MatrixBot):
weights.append(entity['weight'])
log.debug(names)
log.debug(weights)
- db["__chosen__"] = chosen = random.choices(names,weights=weights)[0]
- say(f"{chosen} was chosen to be the next kalauer könig, congratulations!")
+ chosen = random.choices(names,weights=weights)[0]
+ chosen_weight = db[chosen]['weight']
+ all_weight = sum(weights)
+ prob = round(chosen_weight / all_weight * 100,1)
+ crosscheck = random.choices(names,weights=weights,k=100000)
+ say(f"{chosen} was chosen with a probability of {prob}% to be the next kalauer könig, congratulations!\n" +
+ f"cross-check: { crosscheck.count(chosen):,} out of 100,000 rolls were {chosen}")
+
+ db["__chosen__"] = chosen
self.save_db()
elif command in ["!who","!wer", "!current"]:
@@ -147,10 +154,11 @@ class Kalauerbot(MatrixBot):
say(f"the name '{name}' does not exist in the database, add the user before demanding a kalauer from him")
self.save_db()
elif command == "!list":
+ all_weight = sum([db[a]["weight"] for a in db if a != "__chosen__"])
txt = "Kalauer roster:\n\n"
for name,entry in db.items():
if name == '__chosen__': continue
- txt += f"* {name} - {entry['weight']} weight - {entry['total']} total {'(active)' if entry['active'] else '(inactive)'}\n"
+ txt += f"* {name} - {entry['weight']} weight ({round(entry['weight']/all_weight * 100,1)}%) - {entry['total']} total {'(active)' if entry['active'] else '(inactive)'}\n"
say(txt)
elif command == "!kill":
name = args.strip()