Skip to content

Commit

Permalink
Use the Discord domain constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshix-1 committed May 9, 2020
1 parent afb71ea commit 2535246
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BotInviteBuilder {
* The base link of a bot invite.
*/
public static final String BASE_LINK =
"https://discord.com/oauth2/authorize?client_id=%s&scope=bot&permissions=%s";
"https://" + DiscordApi.DISCORD_DOMAIN + "oauth2/authorize?client_id=%s&scope=bot&permissions=%s";

/**
* The client id of the bot's application.
Expand Down
9 changes: 8 additions & 1 deletion javacord-api/src/main/java/org/javacord/api/DiscordApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@
* This class is the most important class for your bot, containing all important methods, like registering listener.
*/
public interface DiscordApi extends GloballyAttachableListenerManager {
/*
* The domain of Discord.
*/
public static final String DISCORD_DOMAIN = "discord.com";
public static final String DISCORD_CDN_DOMAIN = "cnd.discordapp.com";

/*
* The domain of Discord's CDN.
*/
public static final String DISCORD_CND_DOMAIN = "cnd.discordapp.com";

/**
* Gets the used token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ default String getReadableContent() {
*/
default URL getLink() throws AssertionError {
try {
return new URL("https://discord.com/channels/"
return new URL("https://" + DiscordApi.DISCORD_DOMAIN
+ getServer().map(DiscordEntity::getIdAsString).orElse("@me")
+ "/"
+ getChannel().getIdAsString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Optional<Integer> getHardcodedRatelimit() {
* @return The full url of the endpoint.
*/
public String getFullUrl(String... parameters) {
StringBuilder url = new StringBuilder("https://discord.com/api/v" + Javacord.DISCORD_API_VERSION + getEndpointUrl());
StringBuilder url = new StringBuilder("https://" + DiscordApi.DISCORD_DOMAIN + "/api/v" + Javacord.DISCORD_API_VERSION + getEndpointUrl());
url = new StringBuilder(String.format(url.toString(), (Object[]) parameters));
int parameterAmount = getEndpointUrl().split("%s").length - (getEndpointUrl().endsWith("%s") ? 0 : 1);
if (parameters.length > parameterAmount) {
Expand Down

0 comments on commit 2535246

Please sign in to comment.