leaguefacts randomness

This commit is contained in:
xeals 2023-04-18 13:29:59 +10:00
parent 0d46b82beb
commit d6c249199d
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

10
bot.py
View File

@ -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():