Java Code Examples for net.dv8tion.jda.api.JDA#ShardInfo

The following examples show how to use net.dv8tion.jda.api.JDA#ShardInfo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BotListRequest.java    From Arraybot with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the body for the request.
 * The "{total}" and "{shard}" placeholders can only be used when the bot is sharded.
 * @return The body.
 */
private RequestBody getBody(JDA shard) {
    JDA.ShardInfo shardInfo = shard.getShardInfo();
    JSON json = new JSON();
    for(Parameter parameter : parameters) {
        String value = parameter.getValue()
                .replace("{guilds}", String.valueOf(shard.getGuilds().size()));
        value = value
                .replace("{total}", String.valueOf(shardInfo.getShardTotal()))
                .replace("{shard}", String.valueOf(shardInfo.getShardId()));
        Object object;
        if(UDatatypes.isInt(value)) {
            object = Integer.valueOf(value);
        } else {
            object = value;
        }
        json.put(parameter.getKey(), object);
    }
    return RequestBody.create(type, json.marshal());
}
 
Example 2
Source File: EventManager.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void handle(@Nonnull GenericEvent event) {
    final JDA.ShardInfo shardInfo = event.getJDA().getShardInfo();

    if (shouldFakeBlock) {
        //noinspection ConstantConditions
        if (shardInfo == null) {
            logger.warn(TextColor.RED + "Shard booting up (Event {})." + TextColor.RESET, event.getClass().getSimpleName());
            return;
        }

        if (restartingShard == -1 || restartingShard == shardInfo.getShardId()) {
            return;
        }
    }

    for (final EventListener listener : this.listeners) {
        try {
            listener.onEvent(event);
        }
        catch (Throwable thr) {
            Sentry.capture(thr);

            logger.error("Error while handling event {}({}); {}",
                event.getClass().getName(),
                listener.getClass().getSimpleName(),
                thr.getLocalizedMessage());
            logger.error("", thr);
        }
    }
}
 
Example 3
Source File: DiscordBotsGgStats.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public DiscordBotsGgStats(JDA shard) {
    JDA.ShardInfo info = shard.getShardInfo();
    shardId = info.getShardId();
    shardCount = info.getShardTotal();
    guildCount = shard.getGuildCache().size();
}
 
Example 4
Source File: DiscordBotsOrgStats.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public DiscordBotsOrgStats(JDA shard) {
    JDA.ShardInfo info = shard.getShardInfo();
    shardId = info.getShardId();
    shardTotal = info.getShardTotal();
    serverCount = shard.getGuildCache().size();
}
 
Example 5
Source File: VoiceDispatchInterceptor.java    From JDA with Apache License 2.0 4 votes vote down vote up
/**
 * Shortcut to access the shard info for this JDA instance
 *
 * @return The shard information, or null if this was not for a sharded client
 */
@Nullable
default JDA.ShardInfo getShardInfo()
{
    return getJDA().getShardInfo();
}
 
Example 6
Source File: WebSocketClient.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public JDA.ShardInfo getShardInfo()
{
    return api.getShardInfo();
}
 
Example 7
Source File: SessionController.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * The {@link net.dv8tion.jda.api.JDA.ShardInfo ShardInfo} for this request.
 * <br>Can be used for a priority system.
 *
 * @return The ShardInfo
 */
@Nonnull
JDA.ShardInfo getShardInfo();