diff options
| author | 2021-05-15 13:31:34 -0400 | |
|---|---|---|
| committer | 2021-05-15 13:31:34 -0400 | |
| commit | f8a179df350eb3abb7f3595aaff3dbca312f540c (patch) | |
| tree | 6868ae98b81b614f8d8d68f1a9bbc06c7cb94490 /bot/exts/pride/pride_facts.py | |
| parent | chore: Make all aliases in commands tuples (diff) | |
chore: Make things that are only used once constants
Diffstat (limited to 'bot/exts/pride/pride_facts.py')
| -rw-r--r-- | bot/exts/pride/pride_facts.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/bot/exts/pride/pride_facts.py b/bot/exts/pride/pride_facts.py index 5bea1d32..631e2e8b 100644 --- a/bot/exts/pride/pride_facts.py +++ b/bot/exts/pride/pride_facts.py @@ -15,21 +15,16 @@ from bot.utils.decorators import seasonal_task log = logging.getLogger(__name__) +FACTS = json.loads(Path("bot/resources/pride/facts.json").read_text("utf8")) + class PrideFacts(commands.Cog): """Provides a new fact every day during the Pride season!""" def __init__(self, bot: Bot): self.bot = bot - self.facts = self.load_facts() - self.daily_fact_task = self.bot.loop.create_task(self.send_pride_fact_daily()) - @staticmethod - def load_facts() -> dict: - """Loads a dictionary of years mapping to lists of facts.""" - return json.loads(Path("bot/resources/pride/facts.json").read_text("utf8")) - @seasonal_task(Month.JUNE) async def send_pride_fact_daily(self) -> None: """Background task to post the daily pride fact every day.""" @@ -41,8 +36,8 @@ class PrideFacts(commands.Cog): async def send_random_fact(self, ctx: commands.Context) -> None: """Provides a fact from any previous day, or today.""" now = datetime.utcnow() - previous_years_facts = (y for x, y in self.facts.items() if int(x) < now.year) - current_year_facts = self.facts.get(str(now.year), [])[:now.day] + previous_years_facts = (y for x, y in FACTS.items() if int(x) < now.year) + current_year_facts = FACTS.get(str(now.year), [])[:now.day] previous_facts = current_year_facts + [x for y in previous_years_facts for x in y] try: await ctx.send(embed=self.make_embed(random.choice(previous_facts))) |