use of sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest in project Discord4J by Discord4J.
the class ShardImpl method updatePresence.
private void updatePresence(StatusType status, ActivityType type, String text, String streamUrl) {
checkLoggedIn("update presence");
if (streamUrl != null) {
if (!DiscordUtils.STREAM_URL_PATTERN.matcher(streamUrl).matches()) {
throw new IllegalArgumentException("Stream URL must be a twitch.tv url.");
}
}
IUser ourUser = getClient().getOurUser();
IPresence oldPresence = ourUser.getPresence();
IPresence newPresence = new Presence(text, streamUrl, status, type);
if (!newPresence.equals(oldPresence)) {
((User) ourUser).setPresence(newPresence);
getClient().getDispatcher().dispatch(new PresenceUpdateEvent(ourUser, oldPresence, newPresence));
}
ws.send(GatewayOps.STATUS_UPDATE, new PresenceUpdateRequest(status, type, text, streamUrl));
}
use of sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest in project Discord4J by Discord4J.
the class ClientBuilder method build.
/**
* Creates a {@link IDiscordClient} with the configuration specified by this builder.
*
* @return The new client with the configuration specified by this builder.
*/
public IDiscordClient build() {
if (botToken == null)
throw new DiscordException("No login info present!");
if (withRecommendedShardCount && shard != null)
throw new DiscordException("Cannot use recommend shard count options with a specific shard!");
if (withRecommendedShardCount) {
GatewayBotResponse response = Requests.GENERAL_REQUESTS.GET.makeRequest(DiscordEndpoints.GATEWAY + "/bot", GatewayBotResponse.class, new BasicNameValuePair("Authorization", "Bot " + botToken), new BasicNameValuePair("Content-Type", "application/json"));
shardCount = response.shards;
}
final IDiscordClient client = new DiscordClientImpl(botToken, shard != null ? -1 : shardCount, isDaemon, maxMissedPings, maxReconnectAttempts, retryCount, maxCacheCount, provider, shard, backpressureHandler, minimumPoolSize, maximumPoolSize, overflowCapacity, eventThreadTimeout, eventThreadTimeoutUnit, new PresenceUpdateRequest(status, activity, text, streamUrl));
// Registers events as soon as client is initialized
final EventDispatcher dispatcher = client.getDispatcher();
iListeners.forEach(dispatcher::registerListener);
listeners.forEach(dispatcher::registerListener);
listenerClasses.forEach(dispatcher::registerListener);
return client;
}
Aggregations