Skip to content

Commit

Permalink
Reimplemented the request to GET a message by id
Browse files Browse the repository at this point in the history
  • Loading branch information
austinv11 committed Aug 23, 2016
1 parent d6a0aec commit 7934555
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/sx/blah/discord/util/MessageList.java
Expand Up @@ -334,7 +334,20 @@ public void clear() {
* @return The message object found, or null if nonexistent.
*/
public IMessage get(String id) {
return stream().filter((m) -> m.getID().equalsIgnoreCase(id)).findFirst().orElse(null);
IMessage message = stream().filter((m) -> m.getID().equalsIgnoreCase(id)).findFirst().orElse(null);

if (message == null && hasPermission && client.isReady())
try {
return DiscordUtils.getMessageFromJSON(client, channel,
DiscordUtils.GSON.fromJson(
client.REQUESTS.GET.makeRequest(
DiscordEndpoints.CHANNELS + channel.getID() + "/messages/" + id,
new BasicNameValuePair("content-type", "application/json"),
new BasicNameValuePair("authorization", client.getToken())),
MessageResponse.class));
} catch (Exception e) {}

return message;
}

/**
Expand Down

1 comment on commit 7934555

@phantamanta44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not put the second half of the function into the Optional#orElse() call?

Please sign in to comment.