Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discord] Add more badges (members/online/boosts) #9098

Closed
wants to merge 12 commits into from

Conversation

RedSparr0w
Copy link
Member

closes #4500

I've done some testing with the "approximate" values

Server Time This PR Online Widget Value Discord Online This PR Members Discord Members
PokéClicker 2023-04-16T23:16:10Z 9239 9154 unknown 36475 36475
PokéClicker 2023-04-16T23:18:13Z 9239 9071 unknown 36475 36475
PokéClicker 2023-04-16T23:20:53Z 9054 9054 unknown 36475 36475
Shields 2023-04-16T23:21:53Z 26 26 26 627 627
Shields 2023-04-16T23:23:23Z 27 27 27 627 627
GG 2023-04-16T23:24:26Z 94 94 94 365 365
Yuzu 2023-04-16T23:25:36Z 24822 24832 unknown 123637 unknown
Yuzu 2023-04-16T23:27:17Z 24804 24844 unknown 123637 unknown
Shiny Squad 2023-04-16T23:30:07Z 1651 1661 unknown 12381 12381
Shiny Squad 2023-04-16T23:31:13Z 1651 1664 unknown 12381 12381
Shiny Squad 2023-04-16T23:33:25Z 1651 1665 unknown 12381 12381
Shiny Squad 2023-04-16T23:35:45Z 1651 1652 unknown 12381 12381
Shiny Squad 2023-04-16T23:37:10Z 1658 1659 unknown 12381 12381
Shiny Squad 2023-04-16T23:42:55Z 1658 1658 unknown 12381 12381
Shiny Squad 2023-04-16T23:44:54Z 1650 1650 unknown 12381 12381
Discord developers 2023-04-16T23:34:03Z unknown 47305 40352 240312 unknown
Discord developers 2023-04-16T23:35:45Z unknown 47305 40302 240312 unknown
Discord developers 2023-04-16T23:37:10Z unknown 46803 40238 240314 unknown
Discord developers 2023-04-16T23:41:08Z unknown 46803 40238 240314 unknown
Discord developers 2023-04-16T23:44:54Z unknown 46803 40238 240314 unknown
Discord developers 2023-04-16T23:46:59Z unknown 46401 39822 240314 unknown

Seems like the values are cached for ~5 minutes or so, most are pretty close to the actual value, I think the online count within Discord may be off for the Discord Developers server due to some people not having completed the verification/screening process but still being in the server, so they will not show in the online list.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 16, 2023

Warnings
⚠️

📚 Remember to ensure any changes to config.private in services/discord/discord-online-with-total.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/discord/discord-online.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/discord/discord.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/discord/discord-boosts.service.js are reflected in the server secrets documentation

⚠️

📚 Remember to ensure any changes to config.private in services/discord/discord-members.service.js are reflected in the server secrets documentation

Messages
📖 ✨ Thanks for your contribution to Shields, @RedSparr0w!

Generated by 🚫 dangerJS against 7907340

@chris48s
Copy link
Member

👋 Long time no PRs

Looks like you've got a few failing tests.

@Av32000 is right that one of the issues is duplicate class names, but it looks like you've also got a failure on the discord auth tests.

@chris48s chris48s added the service-badge Accepted and actionable changes, features, and bugs label Apr 17, 2023
@RedSparr0w
Copy link
Member Author

Yeah, it's been a minute 😅

I'm not exactly sure what we are using the Discord auth for, as I don't think any of these endpoints require any auth AFAICT.

@chris48s
Copy link
Member

It is not required, but calling the discord API as an anonymous user has a low rate limit. Setting DISCORD_BOT_TOKEN gives you a higher rate limit.
https://github.com/badges/shields/blob/master/doc/server-secrets.md#discord

static auth = {
passKey: 'discord_bot_token',
authorizedOrigins: ['https://discord.com'],
isRequired: false,
}

this.authHelper.withBearerAuthHeader(

We have DISCORD_BOT_TOKEN token set in production and this may also be used by some self-hosting users.

@chris48s
Copy link
Member

Having had a quick look over this, a few more comments for when you revisit to look at the auth:

  • What's your thinking behind having both Discord and DiscordOnline? It seems like they are the same except one shows a less accurate number? Assuming that's right, I think we should drop the one that shows approximate_presence_count and just stick with the one that shows presence_count. I don't think we need both variants.
  • You've set all of these to use _cacheLength = 30. Probably copy & paste? We set this short custom cache length on the existing discord badge because it shows how many users are online now so it is more time-sensitive. Seems like boosts and members are less time-sensitive so they could just use the standard cache length for a chat badge. Also if the other one (online users out of total) is using values that are cached upstream for 5 mins, then we could cache that for longer too.
  • The existing discord badge is a bit of an odd one in that it shows chat | 123 online. I reckon for the boosts and members badges, boosts | 123 and members | 123 would be more in keeping with our usual style guide (left side of the badge should be a lowercase noun describing the meaning of the right-hand side) than chat | 123 boosts and chat | 123 members. For the online/members variant we can probably go with chat | 123/456 online to match the style of the existing one.

static category = 'chat'

static route = {
base: 'discord/online-count',
Copy link
Member

Choose a reason for hiding this comment

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

Today on "naming things is hard".. "online count" could equally describe either variant of this badge (chat | 123 online or chat | 123/456 online). Really the difference here is like "online" vs "online with total" - they're both a count. At the same time, I can't think of any better suggestion for nice way to succinctly express "online out of total" in a single url-friendly slug.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only thoughts on possible friendly names all relay the same sort of meaning
online-total - same as online
online-count - same as online
online-with-total - is probably fine, it's not too long IMO?

Copy link
Member

Choose a reason for hiding this comment

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

Recognize this option might add some internal complexity within the code, but from an end user perspective I wonder if it would be preferable to have the "with total" option provided as a boolean query parameter?

Not sure if that would be too inconsistent with existing badges, but seems like it would be an easier way for a user to build the badge from the frontend site.

Otherwise, I'd vote online-with-total

Comment on lines +54 to +68
async fetch({ inviteId }) {
const url = `https://discord.com/api/v9/invites/${inviteId}?with_counts=true`
return this._requestJson(
this.authHelper.withBearerAuthHeader(
{
url,
schema,
errorMessages: {
404: 'invalid server invite',
},
},
'Bot'
)
)
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems like there's some commonality/duplication across the new classes especially in these fetch functions. Probably worth hoisting that out into a Discord base class or a common helper function IMO

@PyvesB
Copy link
Member

PyvesB commented Aug 14, 2023

@RedSparr0w it would be great to get this landed, do you think you can spend some time to address the latest review comments?

@PyvesB
Copy link
Member

PyvesB commented Dec 31, 2023

Given that there hasn't been any activity for a while, I'm going to close this pull request. Feel free to ping us or reopen it if you get a chance to look into it again. 😉

If others think that repository level projects would be an option and want to pick this up, you can simply fetch the commits by running git fetch origin pull/9098/head:pr-9098. Change the implementation to target repository level projects and open a new pull request with a co-authored trailer included in the commit message to give attribution to the original author.

@PyvesB PyvesB closed this Dec 31, 2023
@chris48s
Copy link
Member

One other thing that has happened since this PR was opened is we've started logging 429s to sentry. We are seeing a lot of 429 calling https://discord.com even with the current badge we've got.

While we are still sometimes hitting the rate limit with just the 'members online now' badge, we probably don't want to add more badges and increase our traffic to the discord api.

@PyvesB
Copy link
Member

PyvesB commented Dec 31, 2023

We do have a point of contact and a special token for Discord if I recall correctly, we could ask for a rate limit increase.

@chris48s
Copy link
Member

Interesting. I had not really thought about where our discord token came from. I assumed we just had a free account.

Lets move this discussion to #9862 rather than the comments of a closed PR.

@PyvesB
Copy link
Member

PyvesB commented Jan 1, 2024

To further reassure whoever would want to pick this up, it's worth noting that the new badges in this PR uses a separate API endpoint, /invites, for which I had requested a separate rate limit at the time. We've technically got something like 250/5s requests for the /api/v6/invites/{id} endpoint which we've never tapped into. I'm not sure the same rate limit applies to the v9 version of the endpoint, but we could try it out, use the v6 version for the time being, or ask for the limits to be switched over to the newer version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Badge request: Discord online/total
5 participants