Pride Leader(pl)#485
Conversation
tagptroll1
left a comment
There was a problem hiding this comment.
I'll start out with these, probably going to need to do a 2nd take as the comments clutter up the view a bit for me.
|
|
||
|
|
||
| class PrideLeader(commands.Cog): | ||
| """Gives a Pride Leader Info.""" |
There was a problem hiding this comment.
| """Gives a Pride Leader Info.""" | |
| """Gives information about Pride Leaders.""" |
It's giving information about multiple leaders, not one. Maybe also a different name for "Pride Leaders", I'm unsure about what that means. Sounds like a cult, or regime in my opinion. "People of status in the Pride / LGBTQ Community" ?
| return embed | ||
|
|
||
| @commands.command(name="prideleader", aliases=['pl']) | ||
| async def pl(self, ctx: commands.Context, *, pride_leader_name: str = None) -> None: |
There was a problem hiding this comment.
Write out the function names.. please. It's still a function that needs to have a descriptive name. Line break it if it gets too long
You can also directly import Context and type ctx with that if you need more space.
Additionally, Instead of defaulting pride_leader_name to None, remove the default, and add an error handler for the command.
| if pride_leader_name is None: | ||
| log.trace("Name not provided by the user so selecting random from json.") | ||
| name_list = [name for name in self.pride.keys()] | ||
| pride_leader_name = random.choice(name_list) |
There was a problem hiding this comment.
Move to an error handler instead
There was a problem hiding this comment.
That way we can change it up if we don't want to randomize the result, and separates the logic
There was a problem hiding this comment.
I wnt to randomize for a reason so people can know about different LGBTQ+ leader
|
|
||
| @commands.command(name="prideleader", aliases=['pl']) | ||
| async def pl(self, ctx: commands.Context, *, pride_leader_name: str = None) -> None: | ||
| """Provides info about pride leader randomly without taking any args or by taking name.""" |
|
|
||
|
|
||
| def setup(bot: commands.Bot) -> None: | ||
| """Cog loader for drag queen name generator.""" |
| self.pride = self.load_json() | ||
|
|
||
| @staticmethod | ||
| def load_json() -> dict: | ||
| """Loads pride leader information from static json resource.""" | ||
| explanation_file = Path("bot/resources/pride/prideleader.json") | ||
| with explanation_file.open(encoding="utf8") as json_data: | ||
| pride = json.load(json_data) | ||
|
|
||
| return pride |
There was a problem hiding this comment.
I didn't see the method being used anywhere else, just do it all in the init. "Load_json" insn't really a descriptive name either. It could be any json
There was a problem hiding this comment.
its used in embed builder
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
Co-authored-by: Rohan Reddy Alleti <roalleti@gmail.com>
Co-authored-by: Rohan Reddy Alleti <rohanjnr44@gmail.com>
| if leader is None: | ||
| log.trace("Got invalid name.") | ||
| final_embed = self.invalid_embed_generate(pride_leader_name) |
There was a problem hiding this comment.
This check should be inside the previous else block as that is where you are validating the given name.
example:
@commands.command(name="prideleader", aliases=['pl'])
async def pride_leader(self, ctx: commands.Context, *, pride_leader_name: Optional[str]) -> None:
"""Provides info about pride leader by taking name as input or randomly without input."""
if pride_leader_name is None:
name_list = [name for name in self.pride]
leader = random.choice(name_list)
else:
leader = self.name_verifier(pride_leader_name)
if leader is None:
invalid_embed = self.invalid_embed_generate(pride_leader_name)
await ctx.send(embed=invalid_embed)
return
pride_leader_embed = self.embed_builder(leader)
await ctx.send(embed=pride_leader_embed)You can do something similar(do test it).
| valid_name.append(name) | ||
|
|
||
| if not valid_name: | ||
| valid_name = ", ".join(name for name in self.pride.keys()) |
There was a problem hiding this comment.
You can simply call join on the dict keys.
| valid_name = ", ".join(name for name in self.pride.keys()) | |
| valid_name = ", ".join(self.pride.keys()) |
| valid_name = ", ".join(name for name in self.pride.keys()) | ||
| error_msg = "Sorry your input didn't match any stored name, here is a list of available names" | ||
| else: | ||
| valid_name = "\n".join(name for name in valid_name) |
There was a problem hiding this comment.
Likewise here-
| valid_name = "\n".join(name for name in valid_name) | |
| valid_name = "\n".join(valid_name) |
| log.trace("Got Valid name.") | ||
| return leader_name | ||
|
|
||
| def invalid_embed_generate(self, pride_leader: str) -> discord.Embed: |
There was a problem hiding this comment.
Hey @Anubhav1603 ,
Would it be good, if we write a logging statement here, so that we can know which pride leaders are users interested in, and according to the requests, we could keep adding information to our prideleader.json file, making it more intelligent.
| valid_name = [] | ||
| pride_leader = pride_leader.title() | ||
| for name in self.pride: | ||
| if fuzz.ratio(pride_leader, name) >= 40: |
There was a problem hiding this comment.
Adding 40 as a class variable would be better, so it's easily modified from one place.
| embed.title = f'__{leader_name}__' | ||
| embed.description = self.pride[leader_name]["About"] | ||
| embed.add_field(name="__Known for__", value=self.pride[leader_name]["Known for"], inline=False) | ||
| embed.add_field(name="__D.O.B and Birth place__", value=self.pride[leader_name]["Born"], inline=False) | ||
| embed.add_field(name="__Awards and honors__", value=self.pride[leader_name]["Awards"], inline=False) |
There was a problem hiding this comment.
| embed.title = f'__{leader_name}__' | |
| embed.description = self.pride[leader_name]["About"] | |
| embed.add_field(name="__Known for__", value=self.pride[leader_name]["Known for"], inline=False) | |
| embed.add_field(name="__D.O.B and Birth place__", value=self.pride[leader_name]["Born"], inline=False) | |
| embed.add_field(name="__Awards and honors__", value=self.pride[leader_name]["Awards"], inline=False) | |
| embed.title = leader_name | |
| embed.description = self.pride[leader_name]["About"] | |
| embed.add_field(name="Known for", value=self.pride[leader_name]["Known for"], inline=False) | |
| embed.add_field(name="D.O.B and Birth place", value=self.pride[leader_name]["Born"], inline=False) | |
| embed.add_field(name="Awards and honors", value=self.pride[leader_name]["Awards"], inline=False) |
Underlines aren't needed, as the field titles and embed titles have different font sizes making them easily differentiable. Just like tagptroll1 mentioned
|
@Anubhav1603 will you be continuing this PR? |
|
If anyone would like to pick up this PR, feel free to do so. Author doesn't look to be active anymore. |
|
I have taken over this PR and will be opening a new one, mentioning changes requested here. We can close this one. |
Relevant Issues
Closes #208
Description
command can be invoked with pride_leader name or without name, if name is not provided then bot randomly picks name from json.
Screenshots
Did you:
pipenv lock?pipenv run lint)?