From d6c249199d28aa139d5fa644c66a9e9736b1f7c0 Mon Sep 17 00:00:00 2001 From: xeals Date: Tue, 18 Apr 2023 13:29:59 +1000 Subject: [PATCH] leaguefacts randomness --- bot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 3804997..6c262b9 100755 --- a/bot.py +++ b/bot.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from collections import deque from discord.utils import setup_logging from typing import Optional import argparse @@ -48,6 +49,7 @@ class BotClient(discord.Client): leaguefacts: Optional[list[str]] = None, ): super().__init__(intents=intents) + self._recentfacts = deque(maxlen=min(len(leaguefacts) - 1, 5)) self._leaguefacts = leaguefacts or [] self._leaguefacts.append( f"I know {len(self._leaguefacts)} leaguefacts but you'll never see most of them." @@ -88,7 +90,13 @@ class BotClient(discord.Client): def _select_leaguefact(self) -> Optional[str]: if not self._leaguefacts: return None - return random.choice(self._leaguefacts) + choice = None + while True: + choice = random.choice(self._leaguefacts) + if choice not in self._recentfacts: + break + self._recentfacts.append(choice) + return choice def main():