aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts
diff options
context:
space:
mode:
authorGravatar Kieran Siek <[email protected]>2021-06-07 15:53:40 +0800
committerGravatar GitHub <[email protected]>2021-06-07 15:53:40 +0800
commit267fe2c8528ff95332fc268cc9ac53411e8034e7 (patch)
treea800f1ec03c6b11bbc2b410a4d61518fd2576e94 /bot/exts
parentmade minor typo changes (diff)
parentMerge pull request #770 from python-discord/docker-compose-restart-policy (diff)
Merge branch 'main' into master
Diffstat (limited to 'bot/exts')
-rw-r--r--bot/exts/pride/pride_anthem.py2
-rw-r--r--bot/exts/pride/pride_facts.py2
-rw-r--r--bot/exts/pride/pride_leader.py117
3 files changed, 119 insertions, 2 deletions
diff --git a/bot/exts/pride/pride_anthem.py b/bot/exts/pride/pride_anthem.py
index 4650595a..05286b3d 100644
--- a/bot/exts/pride/pride_anthem.py
+++ b/bot/exts/pride/pride_anthem.py
@@ -24,7 +24,7 @@ class PrideAnthem(commands.Cog):
If none can be found, it will log this as well as provide that information to the user.
"""
if not genre:
- return random.choice(self.anthems)
+ return random.choice(VIDEOS)
else:
songs = [song for song in VIDEOS if genre.casefold() in song["genre"]]
try:
diff --git a/bot/exts/pride/pride_facts.py b/bot/exts/pride/pride_facts.py
index 631e2e8b..63e33dda 100644
--- a/bot/exts/pride/pride_facts.py
+++ b/bot/exts/pride/pride_facts.py
@@ -57,7 +57,7 @@ class PrideFacts(commands.Cog):
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(self.facts[str(date.year)][date.day - 1]))
+ 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
diff --git a/bot/exts/pride/pride_leader.py b/bot/exts/pride/pride_leader.py
new file mode 100644
index 00000000..c3426ad1
--- /dev/null
+++ b/bot/exts/pride/pride_leader.py
@@ -0,0 +1,117 @@
+import json
+import logging
+import random
+from pathlib import Path
+from typing import Optional
+
+import discord
+from discord.ext import commands
+from fuzzywuzzy import fuzz
+
+from bot import bot
+from bot import constants
+
+log = logging.getLogger(__name__)
+
+PRIDE_RESOURCE = json.loads(Path("bot/resources/pride/prideleader.json").read_text("utf8"))
+MINIMUM_FUZZ_RATIO = 40
+
+
+class PrideLeader(commands.Cog):
+ """Gives information about Pride Leaders."""
+
+ def __init__(self, bot: bot.Bot):
+ self.bot = bot
+
+ def invalid_embed_generate(self, pride_leader: str) -> discord.Embed:
+ """
+ Generates Invalid Embed.
+
+ The invalid embed contains a list of closely matched names of the invalid pride
+ leader the user gave. If no closely matched names are found it would list all
+ the available pride leader names.
+
+ Wikipedia is a useful place to learn about pride leaders and we don't have all
+ the pride leaders, so the bot would add a field containing the wikipedia
+ command to execute.
+ """
+ embed = discord.Embed(
+ color=constants.Colours.soft_red
+ )
+ valid_names = []
+ pride_leader = pride_leader.title()
+ for name in PRIDE_RESOURCE:
+ if fuzz.ratio(pride_leader, name) >= MINIMUM_FUZZ_RATIO:
+ valid_names.append(name)
+
+ if not valid_names:
+ valid_names = ", ".join(PRIDE_RESOURCE)
+ error_msg = "Sorry your input didn't match any stored names, here is a list of available names:"
+ else:
+ valid_names = "\n".join(valid_names)
+ error_msg = "Did you mean?"
+
+ embed.description = f"{error_msg}\n```{valid_names}```"
+ embed.set_footer(text="To add more pride leaders, feel free to open a pull request!")
+
+ return embed
+
+ 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]
+
+ embed = discord.Embed(
+ title=name,
+ description=pride_leader["About"],
+ color=constants.Colours.blue
+ )
+ embed.add_field(
+ name="Known for",
+ value=pride_leader["Known for"],
+ inline=False
+ )
+ embed.add_field(
+ name="D.O.B and Birth place",
+ value=pride_leader["Born"],
+ inline=False
+ )
+ embed.add_field(
+ name="Awards and honors",
+ value=pride_leader["Awards"],
+ inline=False
+ )
+ embed.add_field(
+ name="For More Information",
+ value=f"Do `{constants.Client.prefix}wiki {name}`"
+ f" in <#{constants.Channels.community_bot_commands}>",
+ inline=False
+ )
+ embed.set_thumbnail(url=pride_leader["url"])
+ return embed
+
+ @commands.command(aliases=("pl", "prideleader"))
+ async def pride_leader(self, ctx: commands.Context, *, pride_leader_name: Optional[str]) -> None:
+ """
+ Information about a Pride Leader.
+
+ Returns information about the specified pride leader
+ and if there is no pride leader given, return a random pride leader.
+ """
+ if not pride_leader_name:
+ leader = random.choice(list(PRIDE_RESOURCE.values()))
+ else:
+ leader = PRIDE_RESOURCE.get(pride_leader_name.title())
+ if not leader:
+ log.trace(f"Got a Invalid pride leader: {pride_leader_name}")
+
+ embed = self.invalid_embed_generate(pride_leader_name)
+ await ctx.send(embed=embed)
+ return
+
+ embed = self.embed_builder(leader)
+ await ctx.send(embed=embed)
+
+
+def setup(bot: bot.Bot) -> None:
+ """Load the Pride Leader Cog."""
+ bot.add_cog(PrideLeader(bot))