Search in sources :

Example 1 with JDA

use of net.dv8tion.jda.core.JDA in project MantaroBot by Mantaro.

the class MantaroShard method updateStatus.

void updateStatus() {
    Runnable changeStatus = () -> {
        AtomicInteger users = new AtomicInteger(0), guilds = new AtomicInteger(0);
        if (MantaroBot.getInstance() != null) {
            Arrays.stream(MantaroBot.getInstance().getShards()).map(MantaroShard::getJDA).forEach(jda -> {
                users.addAndGet(jda.getUsers().size());
                guilds.addAndGet(jda.getGuilds().size());
            });
        }
        String newStatus = random(SPLASHES.get(), RANDOM).replace("%ramgb%", String.valueOf(((long) (Runtime.getRuntime().maxMemory() * 1.2D)) >> 30L)).replace("%usercount%", users.toString()).replace("%guildcount%", guilds.toString()).replace("%shardcount%", String.valueOf(getTotalShards())).replace("%prettyusercount%", pretty(users.get())).replace("%prettyguildcount%", pretty(guilds.get()));
        getJDA().getPresence().setGame(Game.of(config().get().prefix + "help | " + newStatus + " | [" + getId() + "]"));
        log.debug("Changed status to: " + newStatus);
    };
    changeStatus.run();
    Async.task("Splash Thread", changeStatus, 600, TimeUnit.SECONDS);
}
Also used : LoginException(javax.security.auth.login.LoginException) Arrays(java.util.Arrays) Getter(lombok.Getter) Async(br.com.brjdevs.java.utils.async.Async) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) Unirest(com.mashape.unirest.http.Unirest) RateLimitedException(net.dv8tion.jda.core.exceptions.RateLimitedException) JSONObject(org.json.JSONObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Holder(br.com.brjdevs.java.utils.holding.objects.Holder) JDA(net.dv8tion.jda.core.JDA) Delegate(lombok.experimental.Delegate) SimpleFileDataManager(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager) Config(net.kodehawa.mantarobot.data.Config) CommandListener(net.kodehawa.mantarobot.core.listeners.command.CommandListener) MantaroData.config(net.kodehawa.mantarobot.data.MantaroData.config) Logger(org.slf4j.Logger) InteractiveOperations(net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations) Game(net.dv8tion.jda.core.entities.Game) JDABuilder(net.dv8tion.jda.core.JDABuilder) MantaroListener(net.kodehawa.mantarobot.core.listeners.MantaroListener) AccountType(net.dv8tion.jda.core.AccountType) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) MantaroEventManager(net.kodehawa.mantarobot.core.MantaroEventManager) TimeUnit(java.util.concurrent.TimeUnit) DataManager(net.kodehawa.mantarobot.utils.data.DataManager) List(java.util.List) CollectionUtils.random(br.com.brjdevs.java.utils.collections.CollectionUtils.random) Carbonitex(net.kodehawa.mantarobot.services.Carbonitex) NativeAudioSendFactory(com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with JDA

use of net.dv8tion.jda.core.JDA in project MantaroBot by Mantaro.

the class MantaroListener method logStatusChange.

private void logStatusChange(StatusChangeEvent event) {
    JDA jda = event.getJDA();
    if (jda.getShardInfo() == null)
        return;
    if (event.getStatus().equals(JDA.Status.CONNECTED)) {
        MantaroBot.getInstance().getStatsClient().increment("shard.connect");
        MantaroBot.getInstance().getStatsClient().recordEvent(com.timgroup.statsd.Event.builder().withTitle("shard.connected").withText("Shard connected").withDate(new Date()).build());
    }
    log.info(String.format("Shard #%d: Changed from %s to %s", jda.getShardInfo().getShardId(), event.getOldStatus(), event.getStatus()));
}
Also used : JDA(net.dv8tion.jda.core.JDA) Date(java.util.Date)

Example 3 with JDA

use of net.dv8tion.jda.core.JDA in project FlareBot by FlareBot.

the class StatusCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    int quaterShards = Getters.getShards().size() / 4;
    double ping = Getters.getShards().stream().mapToLong(JDA::getPing).average().orElse(-1);
    int deadShard = 0;
    int reconnecting = 0;
    int connecting = 0;
    int noVoiceConnections = 0;
    int highResponseTime = 0;
    for (int shardId = 0; shardId < Getters.getShards().size(); shardId++) {
        JDA jda = ShardUtils.getShardById(shardId);
        if (jda == null) {
            connecting++;
            continue;
        }
        boolean reconnect = ShardUtils.isReconnecting(shardId);
        if (ShardUtils.isDead(shardId))
            deadShard++;
        if (reconnect)
            reconnecting++;
        if (jda.getVoiceChannelCache().stream().noneMatch(vc -> vc.getMembers().contains(vc.getGuild().getSelfMember())))
            noVoiceConnections++;
        if (ShardUtils.getLastEventTime(shardId) >= 1500 && !reconnect)
            highResponseTime++;
    }
    StringBuilder sb = new StringBuilder();
    if (reconnecting > Math.min(quaterShards, 10))
        sb.append("⚠ WARNING: A lot of shards are currently reconnecting! This could mean the bot is unable to be " + "used on several thousand servers for a few minutes! (").append(reconnecting).append(" shards reconnecting)").append("\n");
    if (highResponseTime > Math.min(quaterShards, 20))
        sb.append("⚠ WARNING: We seem to be experiencing a high event time on quite a few shards, this is usually " + "down to discord not wanting to co-op with us :( please be patient while these ").append(highResponseTime).append(" shards go back to normal!").append("\n");
    if (deadShard > 5)
        sb.append(" SEVERE: We have quite a few dead shards! Please report this on the [Support Server](").append(Constants.INVITE_URL).append(")").append("\n");
    String status = deadShard == 0 && highResponseTime == 0 && reconnecting < (Math.max(quaterShards, 5)) ? "Good! :)" : "Issues :/";
    if (deadShard > 5)
        status = "Severe issues! Discord could be dying! @EVERYONE RUN!";
    sb.append("Bot Status: ").append(status).append("\n\n");
    sb.append(String.format("FlareBot Version: %s\n" + "JDA Version: %s\n" + "Current Shard: %s\n" + "* Average Ping: %s\n" + "* Ping By Shard: %s\n" + "* Dead Shards: %s shards\n" + "* No Voice Connections: %s shards\n" + "* Shards Reconnecting: %s shards\n" + "* Shards Connecting: %s shards\n" + "* High Last Event Time: %s shards\n" + "Guilds: %d | Users: %d | Connected VCs: %d | Active VCs: %d", FlareBot.getVersion(), JDAInfo.VERSION, channel.getJDA().getShardInfo() == null ? 0 : channel.getJDA().getShardInfo().getShardId(), ping, Arrays.toString(ShardUtils.getPingsForShards()), deadShard, noVoiceConnections, reconnecting, connecting, highResponseTime, Getters.getGuildCache().size(), Getters.getUserCache().size(), Getters.getConnectedVoiceChannels(), Getters.getActiveVoiceChannels()));
    channel.sendMessage("**FlareBot's Status**\n```prolog\n" + sb.toString() + "\n```").queue();
}
Also used : JDA(net.dv8tion.jda.core.JDA)

Example 4 with JDA

use of net.dv8tion.jda.core.JDA in project Rubicon by Rubicon-Bot.

the class CommandPortal method closePortal.

private void closePortal(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
    JDA jda = parsedCommandInvocation.getMessage().getJDA();
    Guild messageGuild = parsedCommandInvocation.getMessage().getGuild();
    TextChannel messageChannel = parsedCommandInvocation.getMessage().getTextChannel();
    // Check if portal exists
    String oldGuildPortalEntry = RubiconBot.getMySQL().getGuildValue(messageGuild, "portal");
    if (oldGuildPortalEntry.equals("closed")) {
        messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal is already closed").build()).queue();
        return;
    }
    if (oldGuildPortalEntry.equals("waiting")) {
        RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
        messageChannel.sendMessage(EmbedUtil.success("Portal", "Successful closed portal request.").build()).queue();
        return;
    }
    Guild partnerGuild = jda.getGuildById(RubiconBot.getMySQL().getPortalValue(messageGuild, "partnerid"));
    // Close Channels
    TextChannel channelOne = null;
    TextChannel channelTwo = null;
    try {
        channelOne = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(messageGuild, "channelid"));
        channelTwo = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(partnerGuild, "channelid"));
    } catch (NullPointerException ignored) {
    // Channels doesn't exist
    }
    if (channelOne != null)
        channelOne.getManager().setName(closedChannelName).queue();
    if (channelTwo != null)
        channelTwo.getManager().setName(closedChannelName).queue();
    // Close and delete DB Portal
    RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
    RubiconBot.getMySQL().deletePortal(messageGuild);
    RubiconBot.getMySQL().updateGuildValue(partnerGuild, "portal", "closed");
    RubiconBot.getMySQL().deletePortal(partnerGuild);
    EmbedBuilder portalClosedMessage = new EmbedBuilder();
    portalClosedMessage.setAuthor("Portal closed!", null, jda.getSelfUser().getEffectiveAvatarUrl());
    portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
    portalClosedMessage.setColor(Colors.COLOR_ERROR);
    channelOne.sendMessage(portalClosedMessage.build()).queue();
    portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
    channelTwo.sendMessage(portalClosedMessage.build()).queue();
    channelOne.getManager().setTopic("Portal closed").queue();
    channelTwo.getManager().setTopic("Portal closed").queue();
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) JDA(net.dv8tion.jda.core.JDA) Guild(net.dv8tion.jda.core.entities.Guild)

Example 5 with JDA

use of net.dv8tion.jda.core.JDA in project SkyBot by duncte123.

the class ShardInfoCommand method executeCommand.

@Override
public void executeCommand(@NotNull String invoke, @NotNull String[] args, @NotNull GuildMessageReceivedEvent event) {
    List<String> headers = new ArrayList<>();
    headers.add("Shard ID");
    headers.add("Status");
    headers.add("Ping");
    headers.add("Guild Count");
    headers.add("Connected VCs");
    List<List<String>> table = new ArrayList<>();
    List<JDA> shards = new ArrayList<>(event.getJDA().asBot().getShardManager().getShards());
    Collections.reverse(shards);
    for (JDA jda : shards) {
        List<String> row = new ArrayList<>();
        row.add((jda.getShardInfo().getShardId() + 1) + (event.getJDA().getShardInfo().getShardId() == jda.getShardInfo().getShardId() ? " (current)" : ""));
        row.add(WordUtils.capitalizeFully(jda.getStatus().toString().replace("_", " ")));
        row.add(String.valueOf(jda.getPing()));
        row.add(String.valueOf(jda.getGuilds().size()));
        row.add(String.valueOf(jda.getVoiceChannels().stream().filter(vc -> vc.getMembers().contains(vc.getGuild().getSelfMember())).count()));
        table.add(row);
        if (table.size() == 20) {
            MessageUtils.sendMsg(event, makeAsciiTable(headers, table));
            table = new ArrayList<>();
        }
    }
    if (table.size() > 0) {
        MessageUtils.sendMsg(event, makeAsciiTable(headers, table));
    }
}
Also used : GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) List(java.util.List) WordUtils(org.apache.commons.lang3.text.WordUtils) Command(ml.duncte123.skybot.objects.command.Command) MessageUtils(ml.duncte123.skybot.utils.MessageUtils) CommandCategory(ml.duncte123.skybot.objects.command.CommandCategory) JDA(net.dv8tion.jda.core.JDA) NotNull(org.jetbrains.annotations.NotNull) StringUtils(org.apache.commons.lang3.StringUtils) Collections(java.util.Collections) ArrayList(java.util.ArrayList) JDA(net.dv8tion.jda.core.JDA) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

JDA (net.dv8tion.jda.core.JDA)41 Guild (net.dv8tion.jda.core.entities.Guild)9 Document (org.bson.Document)9 TextChannel (net.dv8tion.jda.core.entities.TextChannel)8 Permission (net.dv8tion.jda.core.Permission)7 Main (ws.nmathe.saber.Main)7 Consumer (java.util.function.Consumer)6 Message (net.dv8tion.jda.core.entities.Message)6 JSONObject (org.json.JSONObject)5 Logging (ws.nmathe.saber.utils.Logging)5 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Date (java.util.Date)4 List (java.util.List)4 Bson (org.bson.conversions.Bson)4 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)3 Member (net.dv8tion.jda.core.entities.Member)3 User (net.dv8tion.jda.core.entities.User)3 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)3 MessageUtilities (ws.nmathe.saber.utils.MessageUtilities)3