From c93cab2d738ebc7037fcb424a11d4a4f8e42f666 Mon Sep 17 00:00:00 2001 From: mego Date: Sun, 2 Jul 2023 01:33:36 +0300 Subject: [PATCH] 1. Some Fix --- pom.xml | 2 +- .../api/impl/BotiCordAPIImpl.java | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 03effa8..a66d11e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.boticordjava.api boticordjava - 5.1 + 5.2 16 diff --git a/src/main/java/org/boticordjava/api/impl/BotiCordAPIImpl.java b/src/main/java/org/boticordjava/api/impl/BotiCordAPIImpl.java index 1e00083..04047a6 100644 --- a/src/main/java/org/boticordjava/api/impl/BotiCordAPIImpl.java +++ b/src/main/java/org/boticordjava/api/impl/BotiCordAPIImpl.java @@ -51,7 +51,7 @@ public class BotiCordAPIImpl implements BotiCordAPI { private final String searchURL = "https://api.boticord.top/search/"; private final Gson gson; private final String token; - private final String searchApiKey; + private String searchApiKey = null; private final boolean devMode; protected BotiCordAPIImpl(String token, boolean devMode) { @@ -74,13 +74,6 @@ public LocalDateTime deserialize(JsonElement json, Type type, JsonDeserializatio } }).setPrettyPrinting().create(); - - try { - this.searchApiKey = getSearchApiKey().getKey(); - } catch (UnsuccessfulHttpException e) { - throw new RuntimeException(e); - } - } private SearchApiKey getSearchApiKey() throws UnsuccessfulHttpException { @@ -129,9 +122,19 @@ public ServerInfo getServerInfo(@NotNull String serverId) throws UnsuccessfulHtt return get(url, new DefaultResponseTransformer<>(gson, ServerInfo.class)).getResult(); } + private void getApiSearchKey() { + try { + if (searchApiKey == null) { + this.searchApiKey = getSearchApiKey().getKey(); + } + } catch (UnsuccessfulHttpException e) { + throw new RuntimeException(e); + } + } + @Override public List searchServers(@NotNull String text) throws MeilisearchException, IllegalArgumentException, JsonProcessingException { - if (searchApiKey == null) throw new IllegalArgumentException("SearchApiKey is NULL!"); + getApiSearchKey(); Client client = new Client(new Config(searchURL, searchApiKey)); Index index = client.index("servers"); SearchResult searchResult = index.search(text); @@ -148,7 +151,7 @@ public List searchServers(@NotNull String text) throws Meilisearc @Override public List searchBots(@NotNull String text) throws MeilisearchException, IllegalArgumentException, JsonProcessingException { - if (searchApiKey == null) throw new IllegalArgumentException("SearchApiKey is NULL!"); + getApiSearchKey(); Client client = new Client(new Config(searchURL, searchApiKey)); Index index = client.index("bots"); SearchResult searchResult = index.search(text); @@ -166,7 +169,7 @@ public List searchBots(@NotNull String text) throws MeilisearchExcep @Override public List searchUserComments(@NotNull String resourceId) throws MeilisearchException, IllegalArgumentException, JsonProcessingException { - if (searchApiKey == null) throw new IllegalArgumentException("SearchApiKey is NULL!"); + getApiSearchKey(); Client client = new Client(new Config(searchURL, searchApiKey)); String format = String.format("resource = %s", resourceId); String[] filter = new String[]{format};