Skip to content

Commit

Permalink
Update to new Discord domain
Browse files Browse the repository at this point in the history
This commit updates from the old discordapp.com domain to the new
discord.com domain. It also introduces constants for the Discord
domain and Discord's CDN domain.
  • Loading branch information
Joshix-1 authored and Bastian committed May 9, 2020
1 parent 5098a7a commit bc6b275
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 47 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://discordapp.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: 9 additions & 0 deletions javacord-api/src/main/java/org/javacord/api/DiscordApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +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";

/*
* 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 @@ -229,7 +229,7 @@ public AccountType getAccountType() {
*
* @param totalShards The total amount of shards. Sharding will be disabled if set to <code>1</code>.
* @return The current instance in order to chain call methods.
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">API docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#sharding">API docs</a>
*/
public DiscordApiBuilder setTotalShards(int totalShards) {
delegate.setTotalShards(totalShards);
Expand All @@ -254,7 +254,7 @@ public int getTotalShards() {
*
* @param currentShard The shard of this connection starting with <code>0</code>!
* @return The current instance in order to chain call methods.
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">API docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#sharding">API docs</a>
*/
public DiscordApiBuilder setCurrentShard(int currentShard) {
delegate.setCurrentShard(currentShard);
Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean isWaitingForServersOnStartup() {
* A shard only handles a subset of a bot's servers.
*
* @return A future with the current api builder.
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">API docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#sharding">API docs</a>
*/
public CompletableFuture<DiscordApiBuilder> setRecommendedTotalShards() {
return delegate.setRecommendedTotalShards().thenCompose(nothing -> CompletableFuture.completedFuture(this));
Expand Down
4 changes: 2 additions & 2 deletions javacord-api/src/main/java/org/javacord/api/Javacord.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public class Javacord {
/**
* The gateway version from Discord which we are using.
* A list with all gateway versions can be found
* <a href="https://discordapp.com/developers/docs/topics/gateway#gateways-gateway-versions">here</a>.
* <a href="https://discord.com/developers/docs/topics/gateway#gateways-gateway-versions">here</a>.
*/
public static final String DISCORD_GATEWAY_VERSION = "6";

/**
* The API version from Discord which we are using.
* A list with all API versions can be found
* <a href="https://discordapp.com/developers/docs/reference#api-versioning-api-versions">here</a>.
* <a href="https://discord.com/developers/docs/reference#api-versioning-api-versions">here</a>.
*/
public static final String DISCORD_API_VERSION = "6";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface DiscordEntity {
*
* @param entityId The entity it to calculate from.
* @return The creation date of the Discord entity.
* @see <a href="https://discordapp.com/developers/docs/reference#snowflake-ids">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/reference#snowflake-ids">Discord docs</a>
*/
static Instant getCreationTimestamp(long entityId) {
// The first 42 bits (of the total 64) are the timestamp
Expand All @@ -26,7 +26,7 @@ static Instant getCreationTimestamp(long entityId) {
* Gets the creation date of the Discord entity, calculated from the id.
*
* @return The creation date of the Discord entity.
* @see <a href="https://discordapp.com/developers/docs/reference#snowflake-ids">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/reference#snowflake-ids">Discord docs</a>
*/
default Instant getCreationTimestamp() {
return getCreationTimestamp(getId());
Expand All @@ -43,7 +43,7 @@ default Instant getCreationTimestamp() {
* Gets the id of Discord entity.
*
* @return The id of Discord entity.
* @see <a href="https://discordapp.com/developers/docs/reference#snowflake-ids">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/reference#snowflake-ids">Discord docs</a>
*/
long getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Represents a activity type.
*
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-types">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#activity-object-activity-types">Discord docs</a>
*/
public enum ActivityType {

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://discordapp.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 @@ -4,7 +4,7 @@
* A server becomes available event.
* Unavailability means, that a Discord server is down due to a temporary outage.
*
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
*/
public interface ServerBecomesAvailableEvent extends ServerEvent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A server becomes unavailable event.
* Unavailability means, that a Discord server is down due to a temporary outage.
*
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
*/
public interface ServerBecomesUnavailableEvent extends ServerEvent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* This listener listens to servers becoming available.
* Unavailability means, that a Discord server is down due to a temporary outage.
*
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
*/
@FunctionalInterface
public interface ServerBecomesAvailableListener extends GloballyAttachableListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* This listener listens to servers becoming unavailable.
* Unavailability means, that a Discord server is down due to a temporary outage.
*
* @see <a href="https://discordapp.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
* @see <a href="https://discord.com/developers/docs/topics/gateway#guild-unavailability">Discord docs</a>
*/
@FunctionalInterface
public interface ServerBecomesUnavailableListener extends ServerAttachableListener, GloballyAttachableListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public class DiscordRegexPattern {
+ "> # '>' \n");

/**
* A pattern which checks for message links (e.g. {@code https://discordapp.com/channels/@me/1234/5678}
* A pattern which checks for message links (e.g. {@code https://discord.com/channels/@me/1234/5678}
*/
public static final Pattern MESSAGE_LINK =
Pattern.compile("(?x) # enable comment mode \n"
+ "(?i) # ignore case \n"
+ "(?:https?+://)?+ # 'https://' or 'http://' or '' \n"
+ "\\Qdiscordapp.com/channels/\\E # 'discordapp.com/channels/' \n"
+ "(?:(?<server>[0-9]++)|@me) # '@me' or the server id as named group \n"
+ "/ # '/' \n"
+ "(?<channel>[0-9]++) # the textchannel id as named group \n"
+ "/ # '/' \n"
+ "(?<message>[0-9]++) # the message id as named group \n");
Pattern.compile("(?x) # enable comment mode \n"
+ "(?i) # ignore case \n"
+ "(?:https?+://)?+ # 'https://' or 'http://' or '' \n"
+ "discord(?:app)?+\\.com/channels/ # 'discord(app).com/channels/' \n"
+ "(?:(?<server>[0-9]++)|@me) # '@me' or the server id as named group \n"
+ "/ # '/' \n"
+ "(?<channel>[0-9]++) # the textchannel id as named group \n"
+ "/ # '/' \n"
+ "(?<message>[0-9]++) # the message id as named group \n");

/**
* You are not meant to create instances of this class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* An enum with all gateway opcode as defined by
* <a href="https://discordapp.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes">Discord</a>.
* <a href="https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes">Discord</a>.
*/
public enum GatewayOpcode {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* An enum with all voice gateway opcode as defined by
* <a href="https://discordapp.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-opcodes">Discord</a>.
* <a href="https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-opcodes">Discord</a>.
*/
public enum VoiceGatewayOpcode {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* An enum with all web socket close reasons as
* defined by <a href="https://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> (1000-2999),
* assigned by <a href="https://www.iana.org/assignments/websocket/websocket.xml">IANA</a> (3000-3999),
* assigned by <a href="https://discordapp.com/developers/docs/topics/gateway#disconnections">Discord</a> (4000-4998) or
* assigned by <a href="https://discord.com/developers/docs/topics/gateway#disconnections">Discord</a> (4000-4998) or
* self-assigned (4999).
*/
public enum WebSocketCloseCode {
Expand Down Expand Up @@ -143,25 +143,25 @@ public enum WebSocketCloseCode {

/**
* You sent an invalid
* <a href="https://discordapp.com/developers/docs/topics/gateway#payloads-and-opcodesspec.html">Gateway opcode</a>
* <a href="https://discord.com/developers/docs/topics/gateway#payloads-and-opcodesspec.html">Gateway opcode</a>
* or an invalid payload for an opcode. Don't do that!
*/
UNKNOWN_OPCODE(4001, Usage.BOTH),

/**
* You sent an invalid <a href="https://discordapp.com/developers/docs/topics/gateway#sending-payloads">payload</a>
* You sent an invalid <a href="https://discord.com/developers/docs/topics/gateway#sending-payloads">payload</a>
* to us. Don't do that!
*/
DECODE_ERROR(4002, Usage.NORMAL),

/**
* You sent us a payload prior to <a href="https://discordapp.com/developers/docs/topics/gateway#identify">
* You sent us a payload prior to <a href="https://discord.com/developers/docs/topics/gateway#identify">
* identifying</a>.
*/
NOT_AUTHENTICATED(4003, Usage.BOTH),

/**
* The account token sent with your <a href="https://discordapp.com/developers/docs/topics/gateway#identify">
* The account token sent with your <a href="https://discord.com/developers/docs/topics/gateway#identify">
* identify payload</a> is incorrect.
*/
AUTHENTICATION_FAILED(4004, Usage.BOTH),
Expand All @@ -177,7 +177,7 @@ public enum WebSocketCloseCode {
SESSION_NO_LONGER_VALID(4006, Usage.VOICE),

/**
* The sequence sent when <a href="https://discordapp.com/developers/docs/topics/gateway#resume">resuming</a>
* The sequence sent when <a href="https://discord.com/developers/docs/topics/gateway#resume">resuming</a>
* the session was invalid. Reconnect and start a new session.
*/
INVALID_SEQ(4007, Usage.NORMAL),
Expand All @@ -193,49 +193,49 @@ public enum WebSocketCloseCode {
SESSION_TIMEOUT(4009, Usage.BOTH),

/**
* You sent us an invalid <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard when
* You sent us an invalid <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard when
* identifying</a>.
*/
INVALID_SHARD(4010, Usage.NORMAL),

/**
* The session would have handled too many guilds - you are required to
* <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard</a>
* <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard</a>
* your connection in order to connect.
*/
SHARDING_REQUIRED(4011, Usage.NORMAL),

/**
* The session would have handled too many guilds - you are required to
* <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard</a>
* <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard</a>
* your connection in order to connect.
*/
SERVER_NOT_FOUND(4011, Usage.VOICE),

/**
* The session would have handled too many guilds - you are required to
* <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard</a>
* <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard</a>
* your connection in order to connect.
*/
UNKNOWN_PROTOCOL(4012, Usage.VOICE),

/**
* The session would have handled too many guilds - you are required to
* <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard</a>
* <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard</a>
* your connection in order to connect.
*/
DISCONNECTED(4014, Usage.VOICE),

/**
* The session would have handled too many guilds - you are required to
* <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard</a>
* <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard</a>
* your connection in order to connect.
*/
VOICE_SERVER_CRASHED(4015, Usage.VOICE),

/**
* The session would have handled too many guilds - you are required to
* <a href="https://discordapp.com/developers/docs/topics/gateway#sharding">shard</a>
* <a href="https://discord.com/developers/docs/topics/gateway#sharding">shard</a>
* your connection in order to connect.
*/
UNKNOWN_ENCRYPTION_MODE(4016, Usage.VOICE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum RestEndpoint {
CUSTOM_EMOJI("/guilds/%s/emojis", 0);

/**
* The endpoint url (only including the base, not the https://discordapp.com/api/vXYZ/ "prefix".
* The endpoint url (only including the base, not the https://discord.com/api/vXYZ/ "prefix".
*/
private final String endpointUrl;

Expand Down Expand Up @@ -107,7 +107,7 @@ public Optional<Integer> getMajorParameterPosition() {
}

/**
* Gets the endpoint url (only including the base, not the https://discordapp.com/api/vXYZ/ "prefix".
* Gets the endpoint url (only including the base, not the https://discord.com/api/vXYZ/ "prefix".
*
* @return The gateway url.
*/
Expand Down 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://discordapp.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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* An enum with all rest request result codes as defined by
* <a href="https://discordapp.com/developers/docs/topics/response-codes#json-error-response">Discord</a>.
* <a href="https://discord.com/developers/docs/topics/response-codes#json-error-response">Discord</a>.
*/
public enum RestRequestHttpResponseCode {

Expand Down Expand Up @@ -72,7 +72,7 @@ public enum RestRequestHttpResponseCode {
/**
* You've made too many requests.
*
* @see <a href="https://discordapp.com/developers/docs/topics/rate-limits#rate-limits">Rate Limits</a>
* @see <a href="https://discord.com/developers/docs/topics/rate-limits#rate-limits">Rate Limits</a>
*/
TOO_MANY_REQUESTS(429, "You've made too many requests"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* An enum with all rest request result codes as defined by
* <a href="https://discordapp.com/developers/docs/topics/response-codes#json-error-response">Discord</a>.
* <a href="https://discord.com/developers/docs/topics/response-codes#json-error-response">Discord</a>.
*/
public enum RestRequestResultErrorCode {

Expand Down
2 changes: 1 addition & 1 deletion javacord-core/src/test/resources/mockserver.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mockserver.sslSubjectAlternativeNameDomains = discordapp.com, gateway-url
mockserver.sslSubjectAlternativeNameDomains = discord.com, discordapp.com, gateway-url

0 comments on commit bc6b275

Please sign in to comment.