leaguefacts randomness
This commit is contained in:
		
							
								
								
									
										10
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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(): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user