aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/holidays
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/holidays')
-rw-r--r--bot/exts/holidays/halloween/monstersurvey.py6
-rw-r--r--bot/exts/holidays/pride/pride_anthem.py2
-rw-r--r--bot/exts/holidays/pride/pride_facts.py67
-rw-r--r--bot/exts/holidays/pride/pride_leader.py2
-rw-r--r--bot/exts/holidays/valentines/be_my_valentine.py4
-rw-r--r--bot/exts/holidays/valentines/myvalenstate.py2
6 files changed, 31 insertions, 52 deletions
diff --git a/bot/exts/holidays/halloween/monstersurvey.py b/bot/exts/holidays/halloween/monstersurvey.py
index d129f3cc..fdc15e13 100644
--- a/bot/exts/holidays/halloween/monstersurvey.py
+++ b/bot/exts/holidays/halloween/monstersurvey.py
@@ -90,7 +90,7 @@ class MonsterSurvey(Cog):
@monster_group.command(
name="vote"
)
- async def monster_vote(self, ctx: Context, name: str = None) -> None:
+ async def monster_vote(self, ctx: Context, name: str | None = None) -> None:
"""
Cast a vote for a particular monster.
@@ -109,7 +109,7 @@ class MonsterSurvey(Cog):
name = name.lower()
vote_embed = Embed(
- name="Monster Voting",
+ title="Monster Voting",
color=0xFF6800
)
@@ -141,7 +141,7 @@ class MonsterSurvey(Cog):
@monster_group.command(
name="show"
)
- async def monster_show(self, ctx: Context, name: str = None) -> None:
+ async def monster_show(self, ctx: Context, name: str | None = None) -> None:
"""Shows the named monster. If one is not named, it sends the default voting embed instead."""
if name is None:
await ctx.invoke(self.monster_leaderboard)
diff --git a/bot/exts/holidays/pride/pride_anthem.py b/bot/exts/holidays/pride/pride_anthem.py
index c719e388..1f214fc0 100644
--- a/bot/exts/holidays/pride/pride_anthem.py
+++ b/bot/exts/holidays/pride/pride_anthem.py
@@ -32,7 +32,7 @@ class PrideAnthem(commands.Cog):
log.info("No videos for that genre.")
@commands.command(name="prideanthem", aliases=("anthem", "pridesong"))
- async def prideanthem(self, ctx: commands.Context, genre: str = None) -> None:
+ async def prideanthem(self, ctx: commands.Context, genre: str | None = None) -> None:
"""
Sends a message with a video of a random pride anthem.
diff --git a/bot/exts/holidays/pride/pride_facts.py b/bot/exts/holidays/pride/pride_facts.py
index f3ce50a9..5be1b085 100644
--- a/bot/exts/holidays/pride/pride_facts.py
+++ b/bot/exts/holidays/pride/pride_facts.py
@@ -4,7 +4,6 @@ import random
from datetime import UTC, datetime
from pathlib import Path
-import dateutil.parser
import discord
from discord.ext import commands
@@ -28,65 +27,45 @@ class PrideFacts(commands.Cog):
async def send_pride_fact_daily(self) -> None:
"""Background task to post the daily pride fact every day."""
channel = self.bot.get_channel(Channels.sir_lancebot_playground)
- await self.send_select_fact(channel, datetime.now(tz=UTC))
+ await self.send_select_fact(channel, datetime.now(tz=UTC).day)
- async def send_random_fact(self, ctx: commands.Context) -> None:
- """Provides a fact from any previous day, or today."""
- now = datetime.now(tz=UTC)
- 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]
+ async def send_select_fact(self, target: discord.abc.Messageable, day_num: int) -> None:
+ """Provides the fact for the specified day."""
try:
- await ctx.send(embed=self.make_embed(random.choice(previous_facts)))
+ await target.send(embed=self.get_fact_embed(day_num))
except IndexError:
- await ctx.send("No facts available")
-
- async def send_select_fact(self, target: discord.abc.Messageable, _date: str | datetime) -> None:
- """Provides the fact for the specified day, if the day is today, or is in the past."""
- now = datetime.now(tz=UTC)
- if isinstance(_date, str):
- try:
- date = dateutil.parser.parse(_date, dayfirst=False, yearfirst=False, fuzzy=True)
- except (ValueError, OverflowError) as err:
- await target.send(f"Error parsing date: {err}")
- return
- else:
- date = _date
- if date.year < now.year or (date.year == now.year and date.day <= now.day):
- try:
- await target.send(embed=self.make_embed(FACTS[str(date.year)][date.day - 1]))
- except KeyError:
- await target.send(f"The year {date.year} is not yet supported")
- return
- except IndexError:
- await target.send(f"Day {date.day} of {date.year} is not yet support")
- return
- else:
- await target.send("The fact for the selected day is not yet available.")
+ await target.send(f"Day {day_num} is not supported")
+ return
@commands.command(name="pridefact", aliases=("pridefacts",))
- async def pridefact(self, ctx: commands.Context, option: str = None) -> None:
+ async def pridefact(self, ctx: commands.Context, option: int | str | None = None) -> None:
"""
Sends a message with a pride fact of the day.
- If "random" is given as an argument, a random previous fact will be provided.
-
- If a date is given as an argument, and the date is in the past, the fact from that day
- will be provided.
+ "option" is an optional setting, which has two has two accepted values:
+ - "random": a random previous fact will be provided.
+ - If a option is a number (1-30), the fact for that given day of June is returned.
"""
if not option:
- await self.send_select_fact(ctx, datetime.now(tz=UTC))
+ await self.send_select_fact(ctx, datetime.now(tz=UTC).day)
+ elif isinstance(option, int):
+ await self.send_select_fact(ctx, option)
elif option.lower().startswith("rand"):
- await self.send_random_fact(ctx)
+ await ctx.send(embed=self.get_fact_embed())
else:
- await self.send_select_fact(ctx, option)
+ await ctx.send(f"Could not parse option {option}")
@staticmethod
- def make_embed(fact: str) -> discord.Embed:
- """Makes a nice embed for the fact to be sent."""
+ def get_fact_embed(day_num: int | None=None) -> discord.Embed:
+ """
+ Makes a embed for the fact on the given day_num to be sent.
+
+ if day_num is not set, a random fact is selected.
+ """
+ fact = FACTS[day_num-1] if day_num else random.choice(FACTS)
return discord.Embed(
colour=Colours.pink,
- title="Pride Fact!",
+ title=f"Day {day_num}'s pride fact!" if day_num else "Random pride fact!",
description=fact
)
diff --git a/bot/exts/holidays/pride/pride_leader.py b/bot/exts/holidays/pride/pride_leader.py
index b4a98892..9f01ebf9 100644
--- a/bot/exts/holidays/pride/pride_leader.py
+++ b/bot/exts/holidays/pride/pride_leader.py
@@ -57,7 +57,7 @@ class PrideLeader(commands.Cog):
def embed_builder(self, pride_leader: dict) -> discord.Embed:
"""Generate an Embed with information about a pride leader."""
- name = [name for name, info in PRIDE_RESOURCE.items() if info == pride_leader][0]
+ name = next(name for name, info in PRIDE_RESOURCE.items() if info == pride_leader)
embed = discord.Embed(
title=name,
diff --git a/bot/exts/holidays/valentines/be_my_valentine.py b/bot/exts/holidays/valentines/be_my_valentine.py
index c2dd8bb6..714d3884 100644
--- a/bot/exts/holidays/valentines/be_my_valentine.py
+++ b/bot/exts/holidays/valentines/be_my_valentine.py
@@ -44,7 +44,7 @@ class BeMyValentine(commands.Cog):
@commands.cooldown(1, 1800, commands.BucketType.user)
@commands.group(name="bemyvalentine", invoke_without_command=True)
async def send_valentine(
- self, ctx: commands.Context, user: discord.Member, *, valentine_type: str = None
+ self, ctx: commands.Context, user: discord.Member, *, valentine_type: str | None = None
) -> None:
"""
Send a valentine to a specified user with the lovefest role.
@@ -83,7 +83,7 @@ class BeMyValentine(commands.Cog):
@commands.cooldown(1, 1800, commands.BucketType.user)
@send_valentine.command(name="secret")
async def anonymous(
- self, ctx: commands.Context, user: discord.Member, *, valentine_type: str = None
+ self, ctx: commands.Context, user: discord.Member, *, valentine_type: str | None = None
) -> None:
"""
Send an anonymous Valentine via DM to to a specified user with the lovefest role.
diff --git a/bot/exts/holidays/valentines/myvalenstate.py b/bot/exts/holidays/valentines/myvalenstate.py
index fcef24bc..977b9665 100644
--- a/bot/exts/holidays/valentines/myvalenstate.py
+++ b/bot/exts/holidays/valentines/myvalenstate.py
@@ -39,7 +39,7 @@ class MyValenstate(commands.Cog):
return pre_row[-1]
@commands.command()
- async def myvalenstate(self, ctx: commands.Context, *, name: str = None) -> None:
+ async def myvalenstate(self, ctx: commands.Context, *, name: str | None = None) -> None:
"""Find the vacation spot(s) with the most matching characters to the invoking user."""
eq_chars = collections.defaultdict(int)
if name is None: