Skip to content

Commit

Permalink
Merge pull request #555 from Joshix-1/patch-1
Browse files Browse the repository at this point in the history
Change the occourences of discordapp.com to discord.com
  • Loading branch information
Bastian committed May 9, 2020
2 parents 4899ae9 + 121ac5c commit 52fc1e7
Show file tree
Hide file tree
Showing 28 changed files with 96 additions and 70 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://" + Javacord.DISCORD_DOMAIN + "/oauth2/authorize?client_id=%s&scope=bot&permissions=%s";

/**
* The client id of the bot's application.
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
14 changes: 12 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 @@ -31,6 +31,16 @@ public class Javacord {
*/
public static final Instant BUILD_TIMESTAMP;

/**
* The domain of Discord.
*/
public static final String DISCORD_DOMAIN = "discord.com";

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

/**
* The display version of the current Javacord version.
* If the current Javacord version is a release version, it is equal to {@link #VERSION}.
Expand Down Expand Up @@ -98,14 +108,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
@@ -1,6 +1,7 @@
package org.javacord.api.entity.message;

import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.UpdatableFromCache;
import org.javacord.api.entity.channel.ChannelType;
Expand Down Expand Up @@ -698,7 +699,7 @@ default String getReadableContent() {
*/
default URL getLink() throws AssertionError {
try {
return new URL("https://discordapp.com/channels/"
return new URL("https://" + Javacord.DISCORD_DOMAIN + "/channels/"
+ 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
@@ -1,6 +1,7 @@
package org.javacord.core.entity.activity;

import com.fasterxml.jackson.databind.JsonNode;
import org.javacord.api.Javacord;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.activity.ActivityAssets;
import org.javacord.core.entity.IconImpl;
Expand Down Expand Up @@ -41,9 +42,8 @@ public ActivityAssetsImpl(ActivityImpl activity, JsonNode data) {
@Override
public Optional<Icon> getLargeImage() {
return Optional.ofNullable(largeImage)
.flatMap(imageId -> activity.getApplicationId()
.map(applicationId -> String
.format("https://cdn.discordapp.com/app-assets/%s/%s.png", applicationId, imageId)))
.flatMap(imageId -> activity.getApplicationId().map(applicationId -> String.format(
"https://" + Javacord.DISCORD_CDN_DOMAIN + "/app-assets/%s/%s.png", applicationId, imageId)))
.map(url -> {
try {
return new URL(url);
Expand All @@ -62,9 +62,8 @@ public Optional<String> getLargeText() {
@Override
public Optional<Icon> getSmallImage() {
return Optional.ofNullable(smallImage)
.flatMap(imageId -> activity.getApplicationId()
.map(applicationId -> String
.format("https://cdn.discordapp.com/app-assets/%s/%s.png", applicationId, imageId)))
.flatMap(imageId -> activity.getApplicationId().map(applicationId -> String.format(
"https://" + Javacord.DISCORD_CDN_DOMAIN + "/app-assets/%s/%s.png", applicationId, imageId)))
.map(url -> {
try {
return new URL(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.Region;
Expand Down Expand Up @@ -140,10 +141,12 @@ public AuditLogEntryImpl(AuditLog auditLog, JsonNode data) {
break;
// Misc
case ICON:
change = iconChange("https://cdn.discordapp.com/icons/", type, oldValue, newValue);
change = iconChange(
"https://" + Javacord.DISCORD_CDN_DOMAIN + "/icons/", type, oldValue, newValue);
break;
case SPLASH:
change = iconChange("https://cdn.discordapp.com/splashes/", type, oldValue, newValue);
change = iconChange(
"https://" + Javacord.DISCORD_CDN_DOMAIN + "/splashes/", type, oldValue, newValue);
break;
case REGION:
Region oldRegion = Region.getRegionByKey(oldValue != null ? oldValue.asText() : "");
Expand Down Expand Up @@ -203,7 +206,7 @@ public AuditLogEntryImpl(AuditLog auditLog, JsonNode data) {
change = new AuditLogChangeImpl<>(type, oldPermissions, newPermissions);
break;
case AVATAR:
baseUrl = "https://cdn.discordapp.com/avatars/"
baseUrl = "https://" + Javacord.DISCORD_CDN_DOMAIN + "/avatars/"
+ getTarget().map(DiscordEntity::getIdAsString).orElse("0") + "/";
String oldUrl = oldValue != null ? (baseUrl + oldValue.asText()
+ (oldValue.asText().startsWith("a_") ? ".gif" : ".png")) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.channel.GroupChannel;
Expand Down Expand Up @@ -131,7 +132,8 @@ public Optional<Icon> getIcon() {
try {
return Optional.of(new IconImpl(
getApi(),
new URL("https://cdn.discordapp.com/channel-icons/" + getIdAsString() + "/" + iconId + ".png")));
new URL("https://" + Javacord.DISCORD_CDN_DOMAIN
+ "/channel-icons/" + getIdAsString() + "/" + iconId + ".png")));
} catch (MalformedURLException e) {
logger.warn("Seems like the url of the icon is malformed! Please contact the developer!", e);
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.emoji.CustomEmoji;
Expand Down Expand Up @@ -92,7 +93,8 @@ public String getName() {

@Override
public Icon getImage() {
String urlString = "https://cdn.discordapp.com/emojis/" + getIdAsString() + (isAnimated() ? ".gif" : ".png");
String urlString = "https://" + Javacord.DISCORD_CDN_DOMAIN
+ "/emojis/" + getIdAsString() + (isAnimated() ? ".gif" : ".png");
try {
return new IconImpl(getApi(), new URL(urlString));
} catch (MalformedURLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.logging.log4j.Logger;
import org.javacord.api.AccountType;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordClient;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Icon;
Expand Down Expand Up @@ -906,7 +907,8 @@ public Optional<Icon> getIcon() {
try {
return Optional.of(new IconImpl(
getApi(),
new URL("https://cdn.discordapp.com/icons/" + getIdAsString() + "/" + iconHash + ".png")));
new URL("https://" + Javacord.DISCORD_CDN_DOMAIN
+ "/icons/" + getIdAsString() + "/" + iconHash + ".png")));
} catch (MalformedURLException e) {
logger.warn("Seems like the url of the icon is malformed! Please contact the developer!", e);
return Optional.empty();
Expand All @@ -921,7 +923,8 @@ public Optional<Icon> getSplash() {
try {
return Optional.of(new IconImpl(
getApi(),
new URL("https://cdn.discordapp.com/splashes/" + getIdAsString() + "/" + splash + ".png")));
new URL("https://" + Javacord.DISCORD_CDN_DOMAIN
+ "/splashes/" + getIdAsString() + "/" + splash + ".png")));
} catch (MalformedURLException e) {
logger.warn("Seems like the url of the icon is malformed! Please contact the developer!", e);
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.channel.ChannelType;
import org.javacord.api.entity.channel.ServerChannel;
Expand Down Expand Up @@ -203,7 +204,7 @@ public Optional<Icon> getServerIcon() {
}
try {
return Optional.of(new IconImpl(
api, new URL("https://cdn.discordapp.com/icons/"
api, new URL("https://" + Javacord.DISCORD_CDN_DOMAIN + "/icons/"
+ Long.toUnsignedString(getServerId()) + "/" + serverIcon + ".png")));
} catch (MalformedURLException e) {
logger.warn("Seems like the url of the icon is malformed! Please contact the developer!", e);
Expand All @@ -218,7 +219,7 @@ public Optional<Icon> getServerSplash() {
}
try {
return Optional.of(new IconImpl(
api, new URL("https://cdn.discordapp.com/splashes/"
api, new URL("https://" + Javacord.DISCORD_CDN_DOMAIN + "/splashes/"
+ Long.toUnsignedString(getServerId()) + "/" + serverSplash + ".png")));
} catch (MalformedURLException e) {
logger.warn("Seems like the url of the icon is malformed! Please contact the developer!", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordClient;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Icon;
Expand Down Expand Up @@ -243,7 +244,7 @@ public UserStatus getStatusOnClient(DiscordClient client) {
* @return The avatar for the given details.
*/
public static Icon getAvatar(DiscordApi api, String avatarHash, String discriminator, long userId) {
StringBuilder url = new StringBuilder("https://cdn.discordapp.com/");
StringBuilder url = new StringBuilder("https://" + Javacord.DISCORD_CDN_DOMAIN + "/");
if (avatarHash == null) {
url.append("embed/avatars/")
.append(Integer.parseInt(discriminator) % 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.Javacord;
import org.javacord.api.entity.DiscordEntity;
import org.javacord.api.entity.Icon;
import org.javacord.api.entity.channel.TextChannel;
Expand Down Expand Up @@ -104,7 +105,7 @@ public Optional<String> getName() {
@Override
public Optional<Icon> getAvatar() {
if (avatarId != null) {
String url = "https://cdn.discordapp.com/avatars/" + getIdAsString() + "/" + avatarId
String url = "https://" + Javacord.DISCORD_CDN_DOMAIN + "/avatars/" + getIdAsString() + "/" + avatarId
+ (avatarId.startsWith("a_") ? ".gif" : ".png");
try {
return Optional.of(new IconImpl(getApi(), new URL(url)));
Expand Down

0 comments on commit 52fc1e7

Please sign in to comment.