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

Option to use server ID too #12

Closed
MicaelJarniac opened this issue Jul 21, 2020 · 1 comment · Fixed by #13
Closed

Option to use server ID too #12

MicaelJarniac opened this issue Jul 21, 2020 · 1 comment · Fixed by #13
Assignees
Labels
enhancement New feature or request

Comments

@MicaelJarniac
Copy link

Although using invites directly is usually enough, I thought it'd be cool to also be able to use a server ID instead.

My main concern is that invites are not guaranteed to last long, and to actually generate an invite that doesn't expire, the user has to do some manual configuration of it, and even then, it's easy to accidentally delete an invite without even realizing the things it could have broken.

My suggestion is to allow the server ID to also be used to generate the widget, that way it's more resilient to accidents like deleting an invite or using one that expires.

The setup would be like so:

  1. Go to Server SettingsWidget
  2. Enable Server Widget
  3. Set Invite Channel to the desired channel

Once this is done, Discord will automatically generate an invite, and regenerate it once it expires or if it's deleted.

Invites

The invite on the top, created by "Information", is the automatically generated one.

To get the current invite by using the server ID, a request can be made to https://discordapp.com/api/guilds/<server-id>/widget.json with the corresponding <server-id>, and the response will look like so:

{
  "id": "<server-id>",
  "name": "My Server",
  "instant_invite": "https://discordapp.com/invite/<invite-code>",
  "channels": [...],
  "members": [...],
  "presence_count": 3
}

The key instant_invite has the full invite URL, and the invite code is the last portion of the URL.

This way, if a server has widgets enabled and an invite channel set, its server ID can be used to get the latest valid invite link.

@pedrofracassi
Copy link
Member

Should be pretty easy to implement. We can use a regular expression to check if what we have is an ID or not, and then proceed accordingly. Would require a second request to Discord, though.

I'll look into it tonight.

@pedrofracassi pedrofracassi added the enhancement New feature or request label Aug 21, 2020
@pedrofracassi pedrofracassi self-assigned this Aug 21, 2020
pedrofracassi added a commit that referenced this issue Aug 21, 2020
@Doges Doges closed this as completed in #13 Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants