use of org.javacord.api.entity.Nameable in project Javacord by BtoBastian.
the class DiscordWebSocketAdapter method updateStatus.
/**
* Sends the update status packet.
*/
public void updateStatus() {
Optional<Activity> activity = api.getActivity();
ObjectNode updateStatus = JsonNodeFactory.instance.objectNode().put("op", GatewayOpcode.STATUS_UPDATE.getCode());
ObjectNode data = updateStatus.putObject("d").put("status", api.getStatus().getStatusString()).put("afk", false).putNull("since");
ObjectNode activityJson = data.putObject("game");
activityJson.put("name", activity.map(Nameable::getName).orElse(null));
activityJson.put("type", activity.flatMap(g -> {
int type = g.getType().getId();
if (type == 4) {
logger.warn("Can't set the activity to ActivityType.CUSTOM" + ", using ActivityType.PLAYING instead");
return Optional.empty();
} else {
return Optional.of(type);
}
}).orElse(0));
activity.flatMap(Activity::getStreamingUrl).ifPresent(url -> activityJson.put("url", url));
logger.debug("Updating status (content: {})", updateStatus);
sendTextFrame(updateStatus.toString());
}
Aggregations