diff options
Diffstat (limited to 'bot/exts/valentines')
| -rw-r--r-- | bot/exts/valentines/be_my_valentine.py | 70 | ||||
| -rw-r--r-- | bot/exts/valentines/lovecalculator.py | 28 | ||||
| -rw-r--r-- | bot/exts/valentines/movie_generator.py | 14 | ||||
| -rw-r--r-- | bot/exts/valentines/myvalenstate.py | 30 | ||||
| -rw-r--r-- | bot/exts/valentines/pickuplines.py | 23 | ||||
| -rw-r--r-- | bot/exts/valentines/savethedate.py | 17 | ||||
| -rw-r--r-- | bot/exts/valentines/valentine_zodiac.py | 52 | ||||
| -rw-r--r-- | bot/exts/valentines/whoisvalentine.py | 29 |
8 files changed, 122 insertions, 141 deletions
diff --git a/bot/exts/valentines/be_my_valentine.py b/bot/exts/valentines/be_my_valentine.py index 09591cf8..8b522a72 100644 --- a/bot/exts/valentines/be_my_valentine.py +++ b/bot/exts/valentines/be_my_valentine.py @@ -1,13 +1,13 @@ import logging import random -from json import load +from json import loads from pathlib import Path from typing import Tuple import discord from discord.ext import commands -from discord.ext.commands.cooldowns import BucketType +from bot.bot import Bot from bot.constants import Channels, Colours, Lovefest, Month from bot.utils.decorators import in_month from bot.utils.extensions import invoke_help_command @@ -20,7 +20,7 @@ HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_hea class BeMyValentine(commands.Cog): """A cog that sends Valentines to other users!""" - def __init__(self, bot: commands.Bot): + def __init__(self, bot: Bot): self.bot = bot self.valentines = self.load_json() @@ -28,9 +28,7 @@ class BeMyValentine(commands.Cog): def load_json() -> dict: """Load Valentines messages from the static resources.""" p = Path("bot/resources/valentines/bemyvalentine_valentines.json") - with p.open(encoding="utf8") as json_data: - valentines = load(json_data) - return valentines + return loads(p.read_text("utf8")) @in_month(Month.FEBRUARY) @commands.group(name="lovefest") @@ -50,8 +48,8 @@ class BeMyValentine(commands.Cog): async def add_role(self, ctx: commands.Context) -> None: """Adds the lovefest role.""" user = ctx.author - role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id) - if Lovefest.role_id not in [role.id for role in ctx.message.author.roles]: + role = ctx.guild.get_role(Lovefest.role_id) + if role not in ctx.author.roles: await user.add_roles(role) await ctx.send("The Lovefest role has been added !") else: @@ -61,15 +59,15 @@ class BeMyValentine(commands.Cog): async def remove_role(self, ctx: commands.Context) -> None: """Removes the lovefest role.""" user = ctx.author - role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id) - if Lovefest.role_id not in [role.id for role in ctx.message.author.roles]: + role = ctx.guild.get_role(Lovefest.role_id) + if role not in ctx.author.roles: await ctx.send("You dont have the lovefest role.") else: await user.remove_roles(role) - await ctx.send("The lovefest role has been successfully removed !") + await ctx.send("The lovefest role has been successfully removed!") - @commands.cooldown(1, 1800, BucketType.user) - @commands.group(name='bemyvalentine', invoke_without_command=True) + @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 ) -> None: @@ -101,14 +99,14 @@ class BeMyValentine(commands.Cog): valentine, title = self.valentine_check(valentine_type) embed = discord.Embed( - title=f'{emoji_1} {title} {user.display_name} {emoji_2}', - description=f'{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**', + title=f"{emoji_1} {title} {user.display_name} {emoji_2}", + description=f"{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**", color=Colours.pink ) await channel.send(user.mention, embed=embed) - @commands.cooldown(1, 1800, BucketType.user) - @send_valentine.command(name='secret') + @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 ) -> None: @@ -136,8 +134,8 @@ class BeMyValentine(commands.Cog): valentine, title = self.valentine_check(valentine_type) embed = discord.Embed( - title=f'{emoji_1}{title} {user.display_name}{emoji_2}', - description=f'{valentine} \n **{emoji_2}From anonymous{emoji_1}**', + title=f"{emoji_1}{title} {user.display_name}{emoji_2}", + description=f"{valentine} \n **{emoji_2}From anonymous{emoji_1}**", color=Colours.pink ) await ctx.message.delete() @@ -151,21 +149,17 @@ class BeMyValentine(commands.Cog): def valentine_check(self, valentine_type: str) -> Tuple[str, str]: """Return the appropriate Valentine type & title based on the invoking user's input.""" if valentine_type is None: - valentine, title = self.random_valentine() + return self.random_valentine() - elif valentine_type.lower() in ['p', 'poem']: - valentine = self.valentine_poem() - title = 'A poem dedicated to' + elif valentine_type.lower() in ["p", "poem"]: + return self.valentine_poem(), "A poem dedicated to" - elif valentine_type.lower() in ['c', 'compliment']: - valentine = self.valentine_compliment() - title = 'A compliment for' + elif valentine_type.lower() in ["c", "compliment"]: + return self.valentine_compliment(), "A compliment for" else: # in this case, the user decides to type his own valentine. - valentine = valentine_type - title = 'A message for' - return valentine, title + return valentine_type, "A message for" @staticmethod def random_emoji() -> Tuple[str, str]: @@ -176,26 +170,24 @@ class BeMyValentine(commands.Cog): def random_valentine(self) -> Tuple[str, str]: """Grabs a random poem or a compliment (any message).""" - valentine_poem = random.choice(self.valentines['valentine_poems']) - valentine_compliment = random.choice(self.valentines['valentine_compliments']) + valentine_poem = random.choice(self.valentines["valentine_poems"]) + valentine_compliment = random.choice(self.valentines["valentine_compliments"]) random_valentine = random.choice([valentine_compliment, valentine_poem]) if random_valentine == valentine_poem: - title = 'A poem dedicated to' + title = "A poem dedicated to" else: - title = 'A compliment for ' + title = "A compliment for " return random_valentine, title def valentine_poem(self) -> str: """Grabs a random poem.""" - valentine_poem = random.choice(self.valentines['valentine_poems']) - return valentine_poem + return random.choice(self.valentines["valentine_poems"]) def valentine_compliment(self) -> str: """Grabs a random compliment.""" - valentine_compliment = random.choice(self.valentines['valentine_compliments']) - return valentine_compliment + return random.choice(self.valentines["valentine_compliments"]) -def setup(bot: commands.Bot) -> None: - """Be my Valentine Cog load.""" +def setup(bot: Bot) -> None: + """Load the Be my Valentine Cog.""" bot.add_cog(BeMyValentine(bot)) diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index 966acc82..b10b7bca 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -11,20 +11,18 @@ from discord import Member from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content +from bot.bot import Bot + log = logging.getLogger(__name__) -with Path("bot/resources/valentines/love_matches.json").open(encoding="utf8") as file: - LOVE_DATA = json.load(file) - LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items()) +LOVE_DATA = json.loads(Path("bot/resources/valentines/love_matches.json").read_text("utf8")) +LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items()) class LoveCalculator(Cog): """A cog for calculating the love between two people.""" - def __init__(self, bot: commands.Bot): - self.bot = bot - - @commands.command(aliases=('love_calculator', 'love_calc')) + @commands.command(aliases=("love_calculator", "love_calc")) @commands.cooldown(rate=1, per=5, type=commands.BucketType.user) async def love(self, ctx: commands.Context, who: Union[Member, str], whom: Union[Member, str] = None) -> None: """ @@ -62,7 +60,7 @@ class LoveCalculator(Cog): # Make sure user didn't provide something silly such as 10 spaces if not (who and whom): - raise BadArgument('Arguments be non-empty strings.') + raise BadArgument("Arguments must be non-empty strings.") # Hash inputs to guarantee consistent results (hashing algorithm choice arbitrary) # @@ -79,20 +77,20 @@ class LoveCalculator(Cog): # We only need the dict, so we can ditch the first element _, data = LOVE_DATA[index] - status = random.choice(data['titles']) + status = random.choice(data["titles"]) embed = discord.Embed( title=status, - description=f'{who} \N{HEAVY BLACK HEART} {whom} scored {love_percent}%!\n\u200b', + description=f"{who} \N{HEAVY BLACK HEART} {whom} scored {love_percent}%!\n\u200b", color=discord.Color.dark_magenta() ) embed.add_field( - name='A letter from Dr. Love:', - value=data['text'] + name="A letter from Dr. Love:", + value=data["text"] ) await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: - """Love calculator Cog load.""" - bot.add_cog(LoveCalculator(bot)) +def setup(bot: Bot) -> None: + """Load the Love calculator Cog.""" + bot.add_cog(LoveCalculator()) diff --git a/bot/exts/valentines/movie_generator.py b/bot/exts/valentines/movie_generator.py index 4df9e0d5..0fc5edb4 100644 --- a/bot/exts/valentines/movie_generator.py +++ b/bot/exts/valentines/movie_generator.py @@ -6,6 +6,8 @@ from urllib import parse import discord from discord.ext import commands +from bot.bot import Bot + TMDB_API_KEY = environ.get("TMDB_API_KEY") log = logging.getLogger(__name__) @@ -14,7 +16,7 @@ log = logging.getLogger(__name__) class RomanceMovieFinder(commands.Cog): """A Cog that returns a random romance movie suggestion to a user.""" - def __init__(self, bot: commands.Bot): + def __init__(self, bot: Bot): self.bot = bot @commands.command(name="romancemovie") @@ -52,13 +54,15 @@ class RomanceMovieFinder(commands.Cog): embed.set_thumbnail(url="https://i.imgur.com/LtFtC8H.png") await ctx.send(embed=embed) except KeyError: - warning_message = "A KeyError was raised while fetching information on the movie. The API service" \ - " could be unavailable or the API key could be set incorrectly." + warning_message = ( + "A KeyError was raised while fetching information on the movie. The API service" + " could be unavailable or the API key could be set incorrectly." + ) embed = discord.Embed(title=warning_message) log.warning(warning_message) await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: - """Romance movie Cog load.""" +def setup(bot: Bot) -> None: + """Load the Romance movie Cog.""" bot.add_cog(RomanceMovieFinder(bot)) diff --git a/bot/exts/valentines/myvalenstate.py b/bot/exts/valentines/myvalenstate.py index 01801847..52a61011 100644 --- a/bot/exts/valentines/myvalenstate.py +++ b/bot/exts/valentines/myvalenstate.py @@ -7,20 +7,17 @@ from random import choice import discord from discord.ext import commands +from bot.bot import Bot from bot.constants import Colours log = logging.getLogger(__name__) -with open(Path("bot/resources/valentines/valenstates.json"), "r", encoding="utf8") as file: - STATES = json.load(file) +STATES = json.loads(Path("bot/resources/valentines/valenstates.json").read_text("utf8")) class MyValenstate(commands.Cog): """A Cog to find your most likely Valentine's vacation destination.""" - def __init__(self, bot: commands.Bot): - self.bot = bot - def levenshtein(self, source: str, goal: str) -> int: """Calculates the Levenshtein Distance between source and goal.""" if len(source) < len(goal): @@ -46,12 +43,12 @@ class MyValenstate(commands.Cog): """Find the vacation spot(s) with the most matching characters to the invoking user.""" eq_chars = collections.defaultdict(int) if name is None: - author = ctx.message.author.name.lower().replace(' ', '') + author = ctx.author.name.lower().replace(" ", "") else: - author = name.lower().replace(' ', '') + author = name.lower().replace(" ", "") for state in STATES.keys(): - lower_state = state.lower().replace(' ', '') + lower_state = state.lower().replace(" ", "") eq_chars[state] = self.levenshtein(author, lower_state) matches = [x for x, y in eq_chars.items() if y == min(eq_chars.values())] @@ -60,27 +57,26 @@ class MyValenstate(commands.Cog): embed_title = "But there are more!" if len(matches) > 1: - leftovers = f"{', '.join(matches[:len(matches)-2])}, and {matches[len(matches)-1]}" + leftovers = f"{', '.join(matches[:-2])}, and {matches[-1]}" embed_text = f"You have {len(matches)} more matches, these being {leftovers}." elif len(matches) == 1: embed_title = "But there's another one!" - leftovers = str(matches) - embed_text = f"You have another match, this being {leftovers}." + embed_text = f"You have another match, this being {matches[0]}." else: embed_title = "You have a true match!" embed_text = "This state is your true Valenstate! There are no states that would suit" \ " you better" embed = discord.Embed( - title=f'Your Valenstate is {valenstate} \u2764', - description=f'{STATES[valenstate]["text"]}', + title=f"Your Valenstate is {valenstate} \u2764", + description=STATES[valenstate]["text"], colour=Colours.pink ) embed.add_field(name=embed_title, value=embed_text) embed.set_image(url=STATES[valenstate]["flag"]) - await ctx.channel.send(embed=embed) + await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: - """Valenstate Cog load.""" - bot.add_cog(MyValenstate(bot)) +def setup(bot: Bot) -> None: + """Load the Valenstate Cog.""" + bot.add_cog(MyValenstate()) diff --git a/bot/exts/valentines/pickuplines.py b/bot/exts/valentines/pickuplines.py index 74c7e68b..00741a72 100644 --- a/bot/exts/valentines/pickuplines.py +++ b/bot/exts/valentines/pickuplines.py @@ -1,25 +1,22 @@ import logging import random -from json import load +from json import loads from pathlib import Path import discord from discord.ext import commands +from bot.bot import Bot from bot.constants import Colours log = logging.getLogger(__name__) -with open(Path("bot/resources/valentines/pickup_lines.json"), "r", encoding="utf8") as f: - pickup_lines = load(f) +PICKUP_LINES = loads(Path("bot/resources/valentines/pickup_lines.json").read_text("utf8")) class PickupLine(commands.Cog): """A cog that gives random cheesy pickup lines.""" - def __init__(self, bot: commands.Bot): - self.bot = bot - @commands.command() async def pickupline(self, ctx: commands.Context) -> None: """ @@ -27,18 +24,18 @@ class PickupLine(commands.Cog): Note that most of them are very cheesy. """ - random_line = random.choice(pickup_lines['lines']) + random_line = random.choice(PICKUP_LINES["lines"]) embed = discord.Embed( - title=':cheese: Your pickup line :cheese:', - description=random_line['line'], + title=":cheese: Your pickup line :cheese:", + description=random_line["line"], color=Colours.pink ) embed.set_thumbnail( - url=random_line.get('image', pickup_lines['placeholder']) + url=random_line.get("image", PICKUP_LINES["placeholder"]) ) await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: - """Pickup lines Cog load.""" - bot.add_cog(PickupLine(bot)) +def setup(bot: Bot) -> None: + """Load the Pickup lines Cog.""" + bot.add_cog(PickupLine()) diff --git a/bot/exts/valentines/savethedate.py b/bot/exts/valentines/savethedate.py index ac38d279..ffe559d6 100644 --- a/bot/exts/valentines/savethedate.py +++ b/bot/exts/valentines/savethedate.py @@ -1,31 +1,28 @@ import logging import random -from json import load +from json import loads from pathlib import Path import discord from discord.ext import commands +from bot.bot import Bot from bot.constants import Colours log = logging.getLogger(__name__) HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -with open(Path("bot/resources/valentines/date_ideas.json"), "r", encoding="utf8") as f: - VALENTINES_DATES = load(f) +VALENTINES_DATES = loads(Path("bot/resources/valentines/date_ideas.json").read_text("utf8")) class SaveTheDate(commands.Cog): """A cog that gives random suggestion for a Valentine's date.""" - def __init__(self, bot: commands.Bot): - self.bot = bot - @commands.command() async def savethedate(self, ctx: commands.Context) -> None: """Gives you ideas for what to do on a date with your valentine.""" - random_date = random.choice(VALENTINES_DATES['ideas']) + random_date = random.choice(VALENTINES_DATES["ideas"]) emoji_1 = random.choice(HEART_EMOJIS) emoji_2 = random.choice(HEART_EMOJIS) embed = discord.Embed( @@ -36,6 +33,6 @@ class SaveTheDate(commands.Cog): await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: - """Save the date Cog Load.""" - bot.add_cog(SaveTheDate(bot)) +def setup(bot: Bot) -> None: + """Load the Save the date Cog.""" + bot.add_cog(SaveTheDate()) diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index 2696999f..d862ee63 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -9,19 +9,19 @@ from typing import Tuple, Union import discord from discord.ext import commands +from bot.bot import Bot from bot.constants import Colours log = logging.getLogger(__name__) -LETTER_EMOJI = ':love_letter:' +LETTER_EMOJI = ":love_letter:" HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] class ValentineZodiac(commands.Cog): """A Cog that returns a counter compatible zodiac sign to the given user's zodiac sign.""" - def __init__(self, bot: commands.Bot): - self.bot = bot + def __init__(self): self.zodiacs, self.zodiac_fact = self.load_comp_json() @staticmethod @@ -29,14 +29,14 @@ class ValentineZodiac(commands.Cog): """Load zodiac compatibility from static JSON resource.""" explanation_file = Path("bot/resources/valentines/zodiac_explanation.json") compatibility_file = Path("bot/resources/valentines/zodiac_compatibility.json") - with explanation_file.open(encoding="utf8") as json_data: - zodiac_fact = json.load(json_data) - for zodiac_data in zodiac_fact.values(): - zodiac_data['start_at'] = datetime.fromisoformat(zodiac_data['start_at']) - zodiac_data['end_at'] = datetime.fromisoformat(zodiac_data['end_at']) - with compatibility_file.open(encoding="utf8") as json_data: - zodiacs = json.load(json_data) + zodiac_fact = json.loads(explanation_file.read_text("utf8")) + + for zodiac_data in zodiac_fact.values(): + zodiac_data["start_at"] = datetime.fromisoformat(zodiac_data["start_at"]) + zodiac_data["end_at"] = datetime.fromisoformat(zodiac_data["end_at"]) + + zodiacs = json.loads(compatibility_file.read_text("utf8")) return zodiacs, zodiac_fact @@ -62,10 +62,10 @@ class ValentineZodiac(commands.Cog): log.trace("Making zodiac embed.") embed.title = f"__{zodiac}__" embed.description = self.zodiac_fact[zodiac]["About"] - embed.add_field(name='__Motto__', value=self.zodiac_fact[zodiac]["Motto"], inline=False) - embed.add_field(name='__Strengths__', value=self.zodiac_fact[zodiac]["Strengths"], inline=False) - embed.add_field(name='__Weaknesses__', value=self.zodiac_fact[zodiac]["Weaknesses"], inline=False) - embed.add_field(name='__Full form__', value=self.zodiac_fact[zodiac]["full_form"], inline=False) + embed.add_field(name="__Motto__", value=self.zodiac_fact[zodiac]["Motto"], inline=False) + embed.add_field(name="__Strengths__", value=self.zodiac_fact[zodiac]["Strengths"], inline=False) + embed.add_field(name="__Weaknesses__", value=self.zodiac_fact[zodiac]["Weaknesses"], inline=False) + embed.add_field(name="__Full form__", value=self.zodiac_fact[zodiac]["full_form"], inline=False) embed.set_thumbnail(url=self.zodiac_fact[zodiac]["url"]) else: embed = self.generate_invalidname_embed(zodiac) @@ -79,7 +79,7 @@ class ValentineZodiac(commands.Cog): log.trace("Zodiac name sent.") return zodiac_name - @commands.group(name='zodiac', invoke_without_command=True) + @commands.group(name="zodiac", invoke_without_command=True) async def zodiac(self, ctx: commands.Context, zodiac_sign: str) -> None: """Provides information about zodiac sign by taking zodiac sign name as input.""" final_embed = self.zodiac_build_embed(zodiac_sign) @@ -93,9 +93,9 @@ class ValentineZodiac(commands.Cog): month = month.capitalize() try: month = list(calendar.month_abbr).index(month[:3]) - log.trace('Valid month name entered by user') + log.trace("Valid month name entered by user") except ValueError: - log.info('Invalid month name entered by user') + log.info("Invalid month name entered by user") await ctx.send(f"Sorry, but `{month}` is not a valid month name.") return if (month == 1 and 1 <= date <= 19) or (month == 12 and 22 <= date <= 31): @@ -109,14 +109,14 @@ class ValentineZodiac(commands.Cog): final_embed = discord.Embed() final_embed.color = Colours.soft_red final_embed.description = f"Zodiac sign could not be found because.\n```{e}```" - log.info(f'Error in "zodiac date" command:\n{e}.') + log.info(f"Error in 'zodiac date' command:\n{e}.") else: final_embed = self.zodiac_build_embed(zodiac_sign_based_on_date) await ctx.send(embed=final_embed) log.trace("Embed from date successfully sent.") - @zodiac.command(name="partnerzodiac", aliases=['partner']) + @zodiac.command(name="partnerzodiac", aliases=("partner",)) async def partner_zodiac(self, ctx: commands.Context, zodiac_sign: str) -> None: """Provides a random counter compatible zodiac sign to the given user's zodiac sign.""" embed = discord.Embed() @@ -128,12 +128,12 @@ class ValentineZodiac(commands.Cog): emoji2 = random.choice(HEART_EMOJIS) embed.title = "Zodiac Compatibility" embed.description = ( - f'{zodiac_sign.capitalize()}{emoji1}{compatible_zodiac["Zodiac"]}\n' - f'{emoji2}Compatibility meter : {compatible_zodiac["compatibility_score"]}{emoji2}' + f"{zodiac_sign.capitalize()}{emoji1}{compatible_zodiac['Zodiac']}\n" + f"{emoji2}Compatibility meter : {compatible_zodiac['compatibility_score']}{emoji2}" ) embed.add_field( - name=f'A letter from Dr.Zodiac {LETTER_EMOJI}', - value=compatible_zodiac['description'] + name=f"A letter from Dr.Zodiac {LETTER_EMOJI}", + value=compatible_zodiac["description"] ) else: embed = self.generate_invalidname_embed(zodiac_sign) @@ -141,6 +141,6 @@ class ValentineZodiac(commands.Cog): log.trace("Embed from date successfully sent.") -def setup(bot: commands.Bot) -> None: - """Valentine zodiac Cog load.""" - bot.add_cog(ValentineZodiac(bot)) +def setup(bot: Bot) -> None: + """Load the Valentine zodiac Cog.""" + bot.add_cog(ValentineZodiac()) diff --git a/bot/exts/valentines/whoisvalentine.py b/bot/exts/valentines/whoisvalentine.py index 0ff9186c..211b1f27 100644 --- a/bot/exts/valentines/whoisvalentine.py +++ b/bot/exts/valentines/whoisvalentine.py @@ -6,47 +6,44 @@ from random import choice import discord from discord.ext import commands +from bot.bot import Bot from bot.constants import Colours log = logging.getLogger(__name__) -with open(Path("bot/resources/valentines/valentine_facts.json"), "r", encoding="utf8") as file: - FACTS = json.load(file) +FACTS = json.loads(Path("bot/resources/valentines/valentine_facts.json").read_text("utf8")) class ValentineFacts(commands.Cog): """A Cog for displaying facts about Saint Valentine.""" - def __init__(self, bot: commands.Bot): - self.bot = bot - - @commands.command(aliases=('whoisvalentine', 'saint_valentine')) + @commands.command(aliases=("whoisvalentine", "saint_valentine")) async def who_is_valentine(self, ctx: commands.Context) -> None: """Displays info about Saint Valentine.""" embed = discord.Embed( title="Who is Saint Valentine?", - description=FACTS['whois'], + description=FACTS["whois"], color=Colours.pink ) embed.set_thumbnail( - url='https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Saint_Valentine_-_' - 'facial_reconstruction.jpg/1024px-Saint_Valentine_-_facial_reconstruction.jpg' + url="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Saint_Valentine_-_" + "facial_reconstruction.jpg/1024px-Saint_Valentine_-_facial_reconstruction.jpg" ) - await ctx.channel.send(embed=embed) + await ctx.send(embed=embed) @commands.command() async def valentine_fact(self, ctx: commands.Context) -> None: """Shows a random fact about Valentine's Day.""" embed = discord.Embed( - title=choice(FACTS['titles']), - description=choice(FACTS['text']), + title=choice(FACTS["titles"]), + description=choice(FACTS["text"]), color=Colours.pink ) - await ctx.channel.send(embed=embed) + await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: - """Who is Valentine Cog load.""" - bot.add_cog(ValentineFacts(bot)) +def setup(bot: Bot) -> None: + """Load the Who is Valentine Cog.""" + bot.add_cog(ValentineFacts()) |