leaguefacts randomness
This commit is contained in:
parent
0d46b82beb
commit
d6c249199d
10
bot.py
10
bot.py
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from collections import deque
|
||||||
from discord.utils import setup_logging
|
from discord.utils import setup_logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import argparse
|
import argparse
|
||||||
@ -48,6 +49,7 @@ class BotClient(discord.Client):
|
|||||||
leaguefacts: Optional[list[str]] = None,
|
leaguefacts: Optional[list[str]] = None,
|
||||||
):
|
):
|
||||||
super().__init__(intents=intents)
|
super().__init__(intents=intents)
|
||||||
|
self._recentfacts = deque(maxlen=min(len(leaguefacts) - 1, 5))
|
||||||
self._leaguefacts = leaguefacts or []
|
self._leaguefacts = leaguefacts or []
|
||||||
self._leaguefacts.append(
|
self._leaguefacts.append(
|
||||||
f"I know {len(self._leaguefacts)} leaguefacts but you'll never see most of them."
|
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]:
|
def _select_leaguefact(self) -> Optional[str]:
|
||||||
if not self._leaguefacts:
|
if not self._leaguefacts:
|
||||||
return None
|
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():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user