From d77e66b1f472d9a126efee7f09a33e991dc76b90 Mon Sep 17 00:00:00 2001 From: okx-code Date: Tue, 23 Oct 2018 11:28:51 +0100 Subject: [PATCH 1/2] refactoring & add lombok --- .gitignore | 6 ++ build.gradle | 10 +- gradlew | 0 .../api/client/DiscordBotListAPI.java | 44 +++++++-- .../discordbots/api/client/entity/Bot.java | 97 +------------------ .../api/client/entity/BotStats.java | 3 +- .../discordbots/api/client/entity/Result.java | 30 ++---- .../api/client/entity/SimpleUser.java | 22 +---- .../discordbots/api/client/entity/User.java | 36 +------ .../discordbots/api/client/entity/Vote.java | 24 +---- .../api/client/entity/VotingMultiplier.java | 8 +- .../client/impl/DiscordBotListAPIImpl.java | 9 +- 12 files changed, 77 insertions(+), 212 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 gradlew diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc96c42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea/ +*.iws +*.iml +out/ +.gradle/ +build/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3f9d2fb..52bfbae 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,9 @@ -group 'org.discordbots' +plugins { + id 'java' + id 'net.ltgt.apt' version '0.10' +} -apply plugin: 'java' +group 'org.discordbots' repositories { mavenCentral() @@ -15,4 +18,7 @@ dependencies { compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' compile group: 'com.fatboyindustrial.gson-javatime-serialisers', name: 'gson-javatime-serialisers', version: '1.1.1' + + compileOnly 'org.projectlombok:lombok:1.18.2' + apt 'org.projectlombok:lombok:1.18.2' } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java b/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java index 1dbd21c..39c67d6 100644 --- a/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java +++ b/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java @@ -5,27 +5,58 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CompletionStage; public interface DiscordBotListAPI { CompletionStage setStats(int shardId, int shardTotal, int serverCount); CompletionStage setStats(List shardServerCounts); + + /** + * Sets the server count for your bot to display publicly. + * Provide a gap between calls or your API usage may be restricted + * @param serverCount the amount of servers your bot is in + */ CompletionStage setStats(int serverCount); - CompletionStage getStats(String botId); + CompletionStage getStats(); + + /** + * Gets the last 1000 votes only + * @return a list of users who have voted for the bot in the past 24 hours. + */ + CompletionStage> getVoters(); - @Deprecated - CompletionStage> getVoters(String botId); + /** + * checks if a user has voted for the bot in the past 24 hours + * @param userId the user to see if they have voted + * @return whether the user has voted + */ CompletionStage hasVoted(String userId); CompletionStage getBots(Map search, int limit, int offset); CompletionStage getBots(Map search, int limit, int offset, String sort); CompletionStage getBots(Map search, int limit, int offset, String sort, List fields); + + /** + * https://discordbots.org/api/docs#bots + * @return a {@link Bot} object about the current bot + */ + CompletionStage getBot(); + + /** + * Returns information on the bot with the given ID. + * @return a {@link Bot} object about the given botId + */ CompletionStage getBot(String botId); CompletionStage getUser(String userId); + /** + * @return the current voting multiplier. + * Determines if it is the weekend or not. + */ CompletionStage getVotingMultiplier(); class Builder { @@ -45,11 +76,8 @@ public Builder botId(String botId) { } public DiscordBotListAPI build() { - if(token == null) - throw new IllegalArgumentException("The provided token cannot be null!"); - - if(botId == null) - throw new IllegalArgumentException("The provided bot ID cannot be null!"); + Objects.requireNonNull(token, "The provided token cannot be null!"); + Objects.requireNonNull(botId, "The provided bot ID cannot be null!"); return new DiscordBotListAPIImpl(token, botId); } diff --git a/src/main/java/org/discordbots/api/client/entity/Bot.java b/src/main/java/org/discordbots/api/client/entity/Bot.java index 0576dd9..155a695 100644 --- a/src/main/java/org/discordbots/api/client/entity/Bot.java +++ b/src/main/java/org/discordbots/api/client/entity/Bot.java @@ -1,10 +1,12 @@ package org.discordbots.api.client.entity; import com.google.gson.annotations.SerializedName; +import lombok.Getter; import java.time.OffsetDateTime; import java.util.List; +@Getter public class Bot { private String id; @@ -46,99 +48,4 @@ public class Bot { private int points; private boolean legacy; - - - - public String getId() { - return id; - } - - public String getClientId() { - return clientId; - } - - public String getUsername() { - return username; - } - - public String getDiscriminator() { - return discriminator; - } - - public String getAvatar() { - return avatar; - } - - public String getDefaultAvatar() { - return defaultAvatar; - } - - public String getPrefix() { - return prefix; - } - - public String getInvite() { - return invite; - } - - public String getWebsite() { - return website; - } - - public String getVanity() { - return vanity; - } - - public String getSupport() { - return support; - } - - public List getTags() { - return tags; - } - - public String getLongDescription() { - return longDescription; - } - - public String getShortDescription() { - return shortDescription; - } - - public String getBetaDescription() { - return betaDescription; - } - - public boolean isCertified() { - return certified; - } - - public OffsetDateTime getApprovalTime() { - return approvalTime; - } - - public long getServerCount() { - return serverCount; - } - - public List getGuilds() { - return guilds; - } - - public List getShards() { - return shards; - } - - public int getMonthlyPoints() { - return monthlyPoints; - } - - public int getPoints() { - return points; - } - - public boolean isLegacy() { - return legacy; - } - } diff --git a/src/main/java/org/discordbots/api/client/entity/BotStats.java b/src/main/java/org/discordbots/api/client/entity/BotStats.java index 209edfd..10a3f8c 100644 --- a/src/main/java/org/discordbots/api/client/entity/BotStats.java +++ b/src/main/java/org/discordbots/api/client/entity/BotStats.java @@ -1,6 +1,7 @@ package org.discordbots.api.client.entity; import com.google.gson.annotations.SerializedName; +import lombok.Getter; import java.util.Collections; import java.util.List; @@ -8,9 +9,9 @@ public class BotStats { @SerializedName("server_count") + @Getter private int serverCount; private List shards; - public int getServerCount() { return serverCount; } public List getShards() { return Collections.unmodifiableList(shards); } } diff --git a/src/main/java/org/discordbots/api/client/entity/Result.java b/src/main/java/org/discordbots/api/client/entity/Result.java index 1dd0130..181135b 100644 --- a/src/main/java/org/discordbots/api/client/entity/Result.java +++ b/src/main/java/org/discordbots/api/client/entity/Result.java @@ -1,32 +1,16 @@ package org.discordbots.api.client.entity; +import lombok.Getter; + import java.util.List; +@Getter public class Result { private List results; - private int limit, offset, count, total; - - - - public List getResults() { - return results; - } - - public int getLimit() { - return limit; - } - - public int getOffset() { - return offset; - } - - public int getCount() { - return count; - } - - public int getTotal() { - return total; - } + private int limit; + private int offset; + private int count; + private int total; } diff --git a/src/main/java/org/discordbots/api/client/entity/SimpleUser.java b/src/main/java/org/discordbots/api/client/entity/SimpleUser.java index 562f0ed..b43afb9 100644 --- a/src/main/java/org/discordbots/api/client/entity/SimpleUser.java +++ b/src/main/java/org/discordbots/api/client/entity/SimpleUser.java @@ -1,5 +1,8 @@ package org.discordbots.api.client.entity; +import lombok.Getter; + +@Getter public class SimpleUser { private String id; @@ -7,23 +10,4 @@ public class SimpleUser { private String discriminator; private String avatar; - - - - public String getId() { - return id; - } - - public String getUsername() { - return username; - } - - public String getDiscriminator() { - return discriminator; - } - - public String getAvatar() { - return avatar; - } - } diff --git a/src/main/java/org/discordbots/api/client/entity/User.java b/src/main/java/org/discordbots/api/client/entity/User.java index bfed556..b137975 100644 --- a/src/main/java/org/discordbots/api/client/entity/User.java +++ b/src/main/java/org/discordbots/api/client/entity/User.java @@ -1,7 +1,9 @@ package org.discordbots.api.client.entity; import com.google.gson.annotations.SerializedName; +import lombok.Getter; +@Getter public class User extends SimpleUser { @SerializedName("defAvatar") @@ -12,38 +14,4 @@ public class User extends SimpleUser { private Social social; - - - public String getDefaultAvatar() { - return defaultAvatar; - } - - public boolean isAdmin() { - return admin; - } - - public boolean isMod() { - return mod; - } - - public boolean isWebMod() { - return webMod; - } - - public boolean isArtist() { - return artist; - } - - public boolean isCertifiedDev() { - return certifiedDev; - } - - public boolean isSupporter() { - return supporter; - } - - public Social getSocial() { - return social; - } - } diff --git a/src/main/java/org/discordbots/api/client/entity/Vote.java b/src/main/java/org/discordbots/api/client/entity/Vote.java index 047f6de..19bbf45 100644 --- a/src/main/java/org/discordbots/api/client/entity/Vote.java +++ b/src/main/java/org/discordbots/api/client/entity/Vote.java @@ -1,7 +1,9 @@ package org.discordbots.api.client.entity; import com.google.gson.annotations.SerializedName; +import lombok.Getter; +@Getter public class Vote { @SerializedName("bot") @@ -16,26 +18,4 @@ public class Vote { @SerializedName("isWeekend") private boolean weekend; - - - public String getBotId() { - return botId; - } - - public String getUserId() { - return userId; - } - - public String getType() { - return type; - } - - public String getQuery() { - return query; - } - - public boolean isWeekend() { - return weekend; - } - } diff --git a/src/main/java/org/discordbots/api/client/entity/VotingMultiplier.java b/src/main/java/org/discordbots/api/client/entity/VotingMultiplier.java index 6f927fe..b44cf65 100644 --- a/src/main/java/org/discordbots/api/client/entity/VotingMultiplier.java +++ b/src/main/java/org/discordbots/api/client/entity/VotingMultiplier.java @@ -1,16 +1,12 @@ package org.discordbots.api.client.entity; import com.google.gson.annotations.SerializedName; +import lombok.Getter; +@Getter public class VotingMultiplier { @SerializedName("is_weekend") private boolean weekend; - - - public boolean isWeekend() { - return weekend; - } - } diff --git a/src/main/java/org/discordbots/api/client/impl/DiscordBotListAPIImpl.java b/src/main/java/org/discordbots/api/client/impl/DiscordBotListAPIImpl.java index c36fb2c..1536475 100644 --- a/src/main/java/org/discordbots/api/client/impl/DiscordBotListAPIImpl.java +++ b/src/main/java/org/discordbots/api/client/impl/DiscordBotListAPIImpl.java @@ -84,7 +84,7 @@ private CompletionStage setStats(JSONObject jsonBody) { return post(url, jsonBody, Void.class); } - public CompletionStage getStats(String botId) { + public CompletionStage getStats() { HttpUrl url = baseUrl.newBuilder() .addPathSegment("bots") .addPathSegment(botId) @@ -94,7 +94,7 @@ public CompletionStage getStats(String botId) { return get(url, BotStats.class); } - public CompletionStage> getVoters(String botId) { + public CompletionStage> getVoters() { HttpUrl url = baseUrl.newBuilder() .addPathSegment("bots") .addPathSegment(botId) @@ -109,6 +109,11 @@ public CompletionStage> getVoters(String botId) { }); } + @Override + public CompletionStage getBot() { + return getBot(botId); + } + public CompletionStage getBot(String botId) { HttpUrl url = baseUrl.newBuilder() .addPathSegment("bots") From dacb3e03d5db9317742f82460c51dc382dbdec34 Mon Sep 17 00:00:00 2001 From: okx-code Date: Tue, 23 Oct 2018 11:31:32 +0100 Subject: [PATCH 2/2] improve getvoters warning --- src/main/java/org/discordbots/api/client/DiscordBotListAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java b/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java index 39c67d6..f878612 100644 --- a/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java +++ b/src/main/java/org/discordbots/api/client/DiscordBotListAPI.java @@ -23,7 +23,7 @@ public interface DiscordBotListAPI { CompletionStage getStats(); /** - * Gets the last 1000 votes only + * If you have more than 1000 votes every month, do not use this method * @return a list of users who have voted for the bot in the past 24 hours. */ CompletionStage> getVoters();