Skip to content

Add the current nickname of a user in infraction search#508

Closed
kraktus wants to merge 7 commits into
python-discord:masterfrom
kraktus:nick_infraction_v2
Closed

Add the current nickname of a user in infraction search#508
kraktus wants to merge 7 commits into
python-discord:masterfrom
kraktus:nick_infraction_v2

Conversation

@kraktus
Copy link
Copy Markdown
Contributor

@kraktus kraktus commented Oct 9, 2019

If the user has not changed its nickname, display None, otherwise display its current nickname.

closes #337

If the user has not changed its nickname, display *None*, otherwise display its current nickname.
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

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

The nickname is supposed to be for the user, not the actor. To be clear, the user is the one which received the infraction. The actor is the one who gave out the infraction. You can see that the actor is already mentioned so there's no need to show their nickname anyway.

Also, I think it'd be better to replace the user's name with a nickname if it's available rather than adding it on a separate line.

@MarkKoz MarkKoz added a: moderation Related to community moderation functionality: (moderation, defcon, verification) type: enhancement labels Oct 9, 2019
@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 9, 2019

The nickname is supposed to be for the user, not the actor. To be clear, the user is the one which received the infraction. The actor is the one who gave out the infraction. You can see that the actor is already mentioned so there's no need to show their nickname anyway.

Also, I think it'd be better to replace the user's name with a nickname if it's available rather than adding it on a separate line.

Ok, because I muted myself during tests I didn't see the difference

@kraktus kraktus requested a review from MarkKoz October 9, 2019 17:44
Comment thread bot/cogs/moderation/management.py Outdated
Instead of using the methods `get_user` or `get_member`, use `<@id>` instead, which always works, and which is clickable. If the user has a local nickname, it will be shown up, otherwise it will be the username.
@kraktus kraktus requested a review from MarkKoz October 10, 2019 15:07
@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 10, 2019

I think using the <@id> is the best method because it always works and resolves and the issues raised.

Also I am pretty sure that actor.mention relies on it.

@kraktus kraktus changed the title Added a the current nickname of a user in infraction search Add the current nickname of a user in infraction search Oct 10, 2019
@jchristgit
Copy link
Copy Markdown
Contributor

Disagree about <@id> being the best method. It doesn't always work, as Discord's clients will often only load online users into the cache, which means that these will display as something like the following:

image

This is especially true on mobile.

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 12, 2019

Disagree about <@id> being the best method. It doesn't always work, as Discord's clients will often only load online users into the cache, which means that these will display as something like the following:

image

This is especially true on mobile.

Yes I thought that even if the user was not in the cache, clicking on the mention would load it, unfortunately it's not true. I will switch to fetch_user instead, even if I would have preferred not to relie on the API.

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 12, 2019

After some more tests, to use fetch_user I have to turn infraction_to_string into a async function which tons of errors. Do you have any idea to resolve them?

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 12, 2019

I don't really understand why actor is searched in a different way than user, so I leaved it the way it was, but instead of doing this:

        actor_id = infraction["actor"]
        guild = self.bot.get_guild(constants.Guild.id)
        actor = guild.get_member(actor_id)

I think this would be better:

       actor_id = infraction["actor"]
       actor = self.bot.get_user(actor_id)

I would be also more consistent.

@jchristgit no more use of <@id>

@jchristgit
Copy link
Copy Markdown
Contributor

@jchristgit no more use of <@id>

Using .mention is the same as building <@id> yourself though: https://github.com/Rapptz/discord.py/blob/c7a1f5e6e9f18fff3128d67b6d098a4ab842fcb7/discord/user.py#L204-L207

The only exception is that you're also fetching the user now which can make this command very slow due to the rate limiting that endpoint has set. get_user loads from cache.

I think the most simple approach to this is to:

  • Leave the current display of user#discrim as-is
  • Move the get_user call before the string
  • If the user's nickname != the user's username, display something like "{user} (nickname '{user}')" instead of the current "{user}" setup

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 12, 2019

Using .mention is the same as building <@id> yourself though: https://github.com/Rapptz/discord.py/blob/c7a1f5e6e9f18fff3128d67b6d098a4ab842fcb7/discord/user.py#L204-L207

Damn, how could I forget? I said it myself...

Also I am pretty sure that actor.mention relies on it.

The only exception is that you're also fetching the user now which can make this command very slow due to the rate limiting that endpoint has set. get_user loads from cache.

Fetching only if the user is not in the cache

If the user's nickname != the user's username, display something like "{user} (nickname '{user}')" instead of the current "{user}" setup

Well that's not what MarkKoz says:

Also, I think it'd be better to replace the user's name with a nickname if it's available rather than adding it on a separate line.

I agree with him because adding the nickname to the username will longer too much the line

Move the get_user call before the string

Already the case I think?

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 13, 2019

Simplest way to do this I think is not to worry about mentions at all, and display the infos as raw text. I will modify it tonight.

@SebastiaanZ
Copy link
Copy Markdown
Contributor

Hey, @kraktus, I was wondering, are you also a member of our Discord community? What's your handle on there?

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 13, 2019

@SebastiaanZ I changed it to take the same username as here: kraktus :)

If the user or the actor has a nickname, diplay it. Otherwise, display there username.
@MarkKoz
Copy link
Copy Markdown
Contributor

MarkKoz commented Oct 13, 2019

Well that's not what MarkKoz says:

Also, I think it'd be better to replace the user's name with a nickname if it's available rather than adding it on a separate line.

I agree with him because adding the nickname to the username will longer too much the line

Well, depends on what the staff deems to be useful information. I was thinking both the nickname and discriminator are not needed because the ID will always be shown anyway.

Comment thread bot/cogs/moderation/management.py Outdated
@kraktus kraktus requested a review from MarkKoz October 26, 2019 07:12
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to get back to you.

It is not adequate to simply log the exception and proceed because the object will still be None. Furthermore, the way nicknames are currently being fetched may raise AttributeError because the user or actor could be a discord.User instead of discord.Member at those points.

That being said, I've actually remembered that the infractions API has "extended" endpoints which are useful here because they will return full user information along with infractions (as opposed to just user IDs). The user information in the database is kept in sync. I believe the only case of it being out of sync would be the username (not the nickname) of a user who is not in the guild. This is because the bot's syncer cog cannot update the username until the user re-joins the guild. However, I do not think that is relevant since in all such cases the nickname would be available anyway and we prefer nicknames.

Using the get and fetch functions was getting too complicated; the extended endpoint seems like the better, cleaner approach. It should be a utility function in moderation/utils.py because it will get used twice here (for the user and actor) and will in the future be used elsewhere in the moderation cogs.

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Oct 31, 2019

@MarkKoz I honestly think that's out of reach for me, because I don't understand all the Api-related code of the repo and I've no idea where to begin to implement the requested function in utils.py.

@MarkKoz
Copy link
Copy Markdown
Contributor

MarkKoz commented Oct 31, 2019

@kraktus Are you still interested in trying? We can help you through it on Discord as needed. For starters, you could take a look at other code in the bot to see how requests to the API are made.

@kraktus
Copy link
Copy Markdown
Contributor Author

kraktus commented Nov 3, 2019

Unfortunately I won't have time, and after 7 commits didn't progress at all on the objective, I'm closing this PR.

@kraktus kraktus closed this Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: moderation Related to community moderation functionality: (moderation, defcon, verification)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide current nickname in embed for infraction search

5 participants