From 29cf1f1b08c8bbc84e04190f3ba1da8e7dbb854a Mon Sep 17 00:00:00 2001 From: JoshiCodes <55353244+JoshiCodes@users.noreply.github.com> Date: Sun, 11 Jun 2023 19:34:14 +0200 Subject: [PATCH] Added JavaDocs to RJA and modified the README.md --- README.md | 27 +----------------------- src/main/java/de/joshicodes/rja/RJA.java | 18 +++++++++++++++- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b202ab8..4268301 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ - [Maven](#maven)

- [Usage](#usage) -- [RestActions](#restactions) +- [RestActions](https://github.com/JoshiCodes/RJA/wiki/Usage#restactions) - [Sending Messages](#sending-messages) - [EventListeners](#eventlisteners) - [Caching](#caching) @@ -74,31 +74,6 @@ Message message = rja.retrieveMessage("channelId", "messageId").complete(); // R ``` -### RestActions -These methods usually make use of the `RestAction` class. RestActions are used to fetch and handle data async. -To get the data, you can use the `complete()` method, which *can* block the current thread until the data is fetched. -If you want to handle the data async, you can use the `queue()` method, which takes a `Consumer` as parameter. -The queue() method can also be called without any parameters or with two parameters, which are a `Consumer` and a `Consumer`. - -```java -RJA rja = builder.build(); - -// One Consumer, only for the user -rja.retrieveUser("userId").queue(user -> { - // do stuff with the user -}); - -// Two Consumers, one for the user and one for the exception -rja.retrieveUser("userId").queue(user -> { - // do stuff with the user -}, throwable -> { - // handle the exception -}); - -// Get the user sync -User user = rja.retrieveUser("userId").complete(); -``` - ### Sending Messages You can send Messages to every `GenericChannel` using `GenericChannel#sendMessage` or `GenericChannel#sendEmbeds`. Both of this Methods return a `MessageAction` which can be used to modify the message before sending it. diff --git a/src/main/java/de/joshicodes/rja/RJA.java b/src/main/java/de/joshicodes/rja/RJA.java index 1b58604..eb55e1c 100644 --- a/src/main/java/de/joshicodes/rja/RJA.java +++ b/src/main/java/de/joshicodes/rja/RJA.java @@ -169,12 +169,28 @@ public RestAction retrieveUser(String id) { }); } + /** + * Retrieves a member from the cache or the API. + * @param server The server the member is in. + * @param user The user of the member. + * @return The RestAction containing the member. Use {@link RestAction#complete()} or {@link RestAction#queue} to get the member. + */ public RestAction retrieveMember(final Server server, final User user) { return retrieveMember(server, user.getId()); } + /** + * Retrieves a member from the cache or the API. + * @param server The server the member is in. + * @param id The id of the member. + * @return The RestAction containing the member. Use {@link RestAction#complete()} or {@link RestAction#queue} to get the member. + */ public RestAction retrieveMember(final Server server, final String id) { - return new RestAction<>(this, () -> new FetchMemberRequest(server.getId(), id)); + final RJA rja = this; + return new SimpleRestAction<>(this, () -> { + if(memberCache.containsKey(id)) return memberCache.get(id); + else return new RestAction<>(rja, () -> new FetchMemberRequest(server.getId(), id)).complete(); + }); } /**