Java Code Examples for net.dv8tion.jda.api.JDA#getShardInfo()

The following examples show how to use net.dv8tion.jda.api.JDA#getShardInfo() . 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: ShardWatcher.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
private void checkShards() {
    final ShardManager shardManager = SkyBot.getInstance().getShardManager();

    logger.debug("Checking shards");

    for (final JDA shard : shardManager.getShardCache()) {
        setJDAContext(shard);
        final ShardInfo info = shard.getShardInfo();
        final int shardId = info.getShardId();

        if (this.shardMap.get(shardId) < 1) {
           if (Settings.AUTO_REBOOT_SHARDS) {
               logger.warn("{} is down, rebooting it", info);
               // We need to make sure that there are no useless reboots
               shardManager.restart(shardId);
           } else {
               logger.warn("{} is possibly down", info);
           }
        }


        this.shardMap.put(shardId, -1);
    }

    logger.debug("Checking done");
}
 
Example 2
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 3
Source File: ShardWatcher.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void onGatewayPing(@Nonnull GatewayPingEvent event) {
        final JDA shard = event.getEntity();
        final ShardInfo info = shard.getShardInfo();

//        logger.debug("Ping event from {} ({})", info, event.getNewPing());

        this.shardMap.put(info.getShardId(), event.getNewPing());
    }
 
Example 4
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 5
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();
}