Search in sources :

Example 1 with Lavalink

use of lavalink.client.io.Lavalink in project FredBoat by Frederikam.

the class NodeAdminCommand method list.

private void list(@Nonnull CommandContext context) {
    Lavalink lavalink = Launcher.getBotController().getAudioConnectionFacade().getLavalink();
    boolean showHosts = false;
    if (context.hasArguments() && context.rawArgs.contains("host")) {
        if (PermsUtil.checkPermsWithFeedback(PermissionLevel.BOT_ADMIN, context)) {
            showHosts = true;
        } else {
            return;
        }
    }
    List<LavalinkSocket> nodes = lavalink.getNodes();
    if (nodes.isEmpty()) {
        context.replyWithName("There are no remote lavalink nodes registered.");
        return;
    }
    List<String> messages = new ArrayList<>();
    for (LavalinkSocket socket : nodes) {
        RemoteStats stats = socket.getStats();
        String str = "Name:                " + socket.getName() + "\n";
        if (showHosts) {
            str += "Host:                    " + socket.getRemoteUri() + "\n";
        }
        if (stats == null) {
            str += "No stats have been received from this node! Is the node down?";
            str += "\n\n";
            messages.add(str);
            continue;
        }
        str += "Playing players:         " + stats.getPlayingPlayers() + "\n";
        str += "Lavalink load:           " + TextUtils.formatPercent(stats.getLavalinkLoad()) + "\n";
        str += "System load:             " + TextUtils.formatPercent(stats.getSystemLoad()) + " \n";
        str += "Memory:                  " + stats.getMemUsed() / 1000000 + "MB/" + stats.getMemReservable() / 1000000 + "MB\n";
        str += "---------------\n";
        str += "Average frames sent:     " + stats.getAvgFramesSentPerMinute() + "\n";
        str += "Average frames nulled:   " + stats.getAvgFramesNulledPerMinute() + "\n";
        str += "Average frames deficit:  " + stats.getAvgFramesDeficitPerMinute() + "\n";
        str += "---------------\n";
        LavalinkLoadBalancer.Penalties penalties = LavalinkLoadBalancer.getPenalties(socket);
        str += "Penalties Total:    " + penalties.getTotal() + "\n";
        str += "Player Penalty:          " + penalties.getPlayerPenalty() + "\n";
        str += "CPU Penalty:             " + penalties.getCpuPenalty() + "\n";
        str += "Deficit Frame Penalty:   " + penalties.getDeficitFramePenalty() + "\n";
        str += "Null Frame Penalty:      " + penalties.getNullFramePenalty() + "\n";
        str += "Raw: " + penalties.toString() + "\n";
        str += "---------------\n\n";
        messages.add(str);
    }
    if (showHosts) {
        for (String str : messages) {
            context.replyPrivate(TextUtils.asCodeBlock(str), null, null);
        }
        context.replyWithName("Sent you a DM with the data. If you did not receive anything, adjust your privacy settings so I can DM you.");
    } else {
        for (String str : messages) {
            context.reply(TextUtils.asCodeBlock(str));
        }
    }
}
Also used : LavalinkSocket(lavalink.client.io.LavalinkSocket) Lavalink(lavalink.client.io.Lavalink) LavalinkLoadBalancer(lavalink.client.io.LavalinkLoadBalancer) ArrayList(java.util.ArrayList) RemoteStats(lavalink.client.io.RemoteStats)

Example 2 with Lavalink

use of lavalink.client.io.Lavalink in project SkyBot by duncte123.

the class LavalinkManager method start.

public void start() {
    if (!isEnabled())
        return;
    String userId = getIdFromToken(AirUtils.CONFIG.getString("discord.token"));
    lavalink = new Lavalink(userId, AirUtils.CONFIG.getInt("discord.totalShards", 1), shardId -> SkyBot.getInstance().getShardManager().getShardById(shardId));
    List<LavalinkNode> defaultNodes = new ArrayList<>();
    defaultNodes.add(new LavalinkNode("ws://localhost", "youshallnotpass"));
    List<Ason> nodes = AirUtils.CONFIG.getArray("lavalink.nodes", defaultNodes);
    List<LavalinkNode> nodeList = new ArrayList<>();
    nodes.forEach(it -> nodeList.add(Ason.deserialize(it, LavalinkNode.class)));
    nodeList.forEach(it -> lavalink.addNode(Objects.requireNonNull(toURI(it.wsurl)), it.pass));
}
Also used : Link(lavalink.client.io.Link) AudioUtils(ml.duncte123.skybot.utils.AudioUtils) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) LavalinkNode(ml.duncte123.skybot.audio.LavalinkNode) URISyntaxException(java.net.URISyntaxException) LavaplayerPlayerWrapper(lavalink.client.player.LavaplayerPlayerWrapper) IPlayer(lavalink.client.player.IPlayer) Ason(com.afollestad.ason.Ason) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Guild(net.dv8tion.jda.core.entities.Guild) Base64(java.util.Base64) List(java.util.List) Lavalink(lavalink.client.io.Lavalink) SkyBot(ml.duncte123.skybot.SkyBot) URI(java.net.URI) NotNull(org.jetbrains.annotations.NotNull) AirUtils(ml.duncte123.skybot.utils.AirUtils) Lavalink(lavalink.client.io.Lavalink) LavalinkNode(ml.duncte123.skybot.audio.LavalinkNode) ArrayList(java.util.ArrayList) Ason(com.afollestad.ason.Ason)

Aggregations

ArrayList (java.util.ArrayList)2 Lavalink (lavalink.client.io.Lavalink)2 Ason (com.afollestad.ason.Ason)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Base64 (java.util.Base64)1 List (java.util.List)1 Objects (java.util.Objects)1 LavalinkLoadBalancer (lavalink.client.io.LavalinkLoadBalancer)1 LavalinkSocket (lavalink.client.io.LavalinkSocket)1 Link (lavalink.client.io.Link)1 RemoteStats (lavalink.client.io.RemoteStats)1 IPlayer (lavalink.client.player.IPlayer)1 LavaplayerPlayerWrapper (lavalink.client.player.LavaplayerPlayerWrapper)1 SkyBot (ml.duncte123.skybot.SkyBot)1 LavalinkNode (ml.duncte123.skybot.audio.LavalinkNode)1 AirUtils (ml.duncte123.skybot.utils.AirUtils)1 AudioUtils (ml.duncte123.skybot.utils.AudioUtils)1 Guild (net.dv8tion.jda.core.entities.Guild)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1