Skip to content

Pride Leader(pl)#485

Closed
Anubhav1603 wants to merge 28 commits into
python-discord:masterfrom
Anubhav1603:prideleader
Closed

Pride Leader(pl)#485
Anubhav1603 wants to merge 28 commits into
python-discord:masterfrom
Anubhav1603:prideleader

Conversation

@Anubhav1603
Copy link
Copy Markdown
Contributor

@Anubhav1603 Anubhav1603 commented Oct 6, 2020

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

error
pride_leader
random_pride_leader

Did you:

  • Join the Python Discord Community?
  • If dependencies have been added or updated, run pipenv lock?
  • Lint your code (pipenv run lint)?
  • Set the PR to allow edits from contributors?

@Anubhav1603 Anubhav1603 requested a review from a team as a code owner October 6, 2020 12:35
@ghost ghost added the needs 2 approvals label Oct 6, 2020
@Akarys42 Akarys42 added hacktoberfest-accepted type: feature Relating to the functionality of the application. labels Oct 6, 2020
Copy link
Copy Markdown
Contributor

@tagptroll1 tagptroll1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bot/exts/pride/prideleader.py Outdated


class PrideLeader(commands.Cog):
"""Gives a Pride Leader Info."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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" ?

Comment thread bot/exts/pride/prideleader.py Outdated
Comment thread bot/exts/pride/prideleader.py Outdated
Comment thread bot/exts/pride/prideleader.py
Comment thread bot/exts/pride/prideleader.py
Comment thread bot/exts/pride/prideleader.py Outdated
return embed

@commands.command(name="prideleader", aliases=['pl'])
async def pl(self, ctx: commands.Context, *, pride_leader_name: str = None) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bot/exts/pride/prideleader.py Outdated
Comment on lines +72 to +75
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to an error handler instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way we can change it up if we don't want to randomize the result, and separates the logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wnt to randomize for a reason so people can know about different LGBTQ+ leader

Comment thread bot/exts/pride/prideleader.py Outdated

@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."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads weird

Comment thread bot/exts/pride/prideleader.py Outdated


def setup(bot: commands.Bot) -> None:
"""Cog loader for drag queen name generator."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment thread bot/exts/pride/prideleader.py Outdated
Comment on lines +19 to +28
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its used in embed builder

@ghost ghost added status: waiting for author Waiting for author to address a review or respond to a comment and removed needs 2 approvals labels Oct 6, 2020
Co-authored-by: Thomas Petersson <Thomas@petersson.priv.no>
@ghost ghost added needs 2 approvals and removed status: waiting for author Waiting for author to address a review or respond to a comment labels Oct 6, 2020
Anubhav1603 and others added 5 commits October 6, 2020 20:11
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>
Comment thread bot/exts/pride/prideleader.py Outdated
@ghost ghost added status: waiting for author Waiting for author to address a review or respond to a comment and removed needs 2 approvals labels Oct 7, 2020
Co-authored-by: Rohan Reddy Alleti <roalleti@gmail.com>
@ghost ghost removed the status: waiting for author Waiting for author to address a review or respond to a comment label Oct 7, 2020
Comment thread bot/exts/pride/prideleader.py Outdated
@ghost ghost added status: waiting for author Waiting for author to address a review or respond to a comment and removed needs 2 approvals labels Oct 15, 2020
Co-authored-by: Rohan Reddy Alleti <rohanjnr44@gmail.com>
@ghost ghost added needs 2 approvals and removed status: waiting for author Waiting for author to address a review or respond to a comment labels Oct 15, 2020
Comment on lines +80 to +82
if leader is None:
log.trace("Got invalid name.")
final_embed = self.invalid_embed_generate(pride_leader_name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply call join on the dict keys.

Suggested change
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here-

Suggested change
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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding 40 as a class variable would be better, so it's easily modified from one place.

Comment on lines +63 to +67
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@Xithrius
Copy link
Copy Markdown
Contributor

@Anubhav1603 will you be continuing this PR?

@Xithrius Xithrius added priority: 2 - normal area: backend Related to internal functionality and utilities status: waiting for author Waiting for author to address a review or respond to a comment status: stale Has had no activity for a while and removed priority: 2 - normal labels Feb 23, 2021
@Xithrius Xithrius added up for grabs Available for anyone to work on and removed hacktoberfest-accepted status: stale Has had no activity for a while status: waiting for author Waiting for author to address a review or respond to a comment labels Mar 6, 2021
@Xithrius
Copy link
Copy Markdown
Contributor

Xithrius commented Mar 6, 2021

If anyone would like to pick up this PR, feel free to do so. Author doesn't look to be active anymore.

@Shivansh-007 Shivansh-007 mentioned this pull request Mar 6, 2021
@Shivansh-007
Copy link
Copy Markdown
Contributor

I have taken over this PR and will be opening a new one, mentioning changes requested here.

We can close this one.

@Shivansh-007 Shivansh-007 mentioned this pull request Mar 8, 2021
2 tasks
@Xithrius Xithrius closed this Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Related to internal functionality and utilities type: feature Relating to the functionality of the application. up for grabs Available for anyone to work on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tech Leaders Pride

7 participants