Search in sources :

Example 1 with PresenceUpdateRequest

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));
}
Also used : User(sx.blah.discord.handle.impl.obj.User) PresenceUpdateRequest(sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest) Presence(sx.blah.discord.handle.impl.obj.Presence) PresenceUpdateEvent(sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent)

Example 2 with PresenceUpdateRequest

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;
}
Also used : EventDispatcher(sx.blah.discord.api.events.EventDispatcher) PresenceUpdateRequest(sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest) GatewayBotResponse(sx.blah.discord.api.internal.json.responses.GatewayBotResponse) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DiscordException(sx.blah.discord.util.DiscordException) DiscordClientImpl(sx.blah.discord.api.internal.DiscordClientImpl)

Aggregations

PresenceUpdateRequest (sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 EventDispatcher (sx.blah.discord.api.events.EventDispatcher)1 DiscordClientImpl (sx.blah.discord.api.internal.DiscordClientImpl)1 GatewayBotResponse (sx.blah.discord.api.internal.json.responses.GatewayBotResponse)1 PresenceUpdateEvent (sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent)1 Presence (sx.blah.discord.handle.impl.obj.Presence)1 User (sx.blah.discord.handle.impl.obj.User)1 DiscordException (sx.blah.discord.util.DiscordException)1