Search in sources :

Example 1 with LavalinkSocket

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

the class GetNodeCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    if (Launcher.getBotController().getAudioConnectionFacade().isLocal()) {
        context.replyWithName("Lavalink is not enabled.");
        return;
    }
    Guild guild = null;
    if (context.hasArguments()) {
        try {
            long guildId = Long.parseUnsignedLong(context.args[0]);
            guild = Launcher.getBotController().getJdaEntityProvider().getGuildById(guildId);
        } catch (NumberFormatException ignored) {
        }
        if (guild == null) {
            context.reply("Guild not found for id " + context.args[0]);
            return;
        }
    } else {
        guild = context.guild;
    }
    LavalinkSocket node = Launcher.getBotController().getAudioConnectionFacade().getLavalink().getLink(guild).getNode();
    String reply = String.format("Guild %s id `%s` lavalink socket: `%s`", context.guild.getName(), context.guild.getIdLong(), String.valueOf(node));
    // sensitive info, send it by DM
    context.replyPrivate(reply, __ -> context.replyWithName("Sent you a DM with the data."), t -> context.replyWithName("Could not DM you, adjust your privacy settings."));
}
Also used : LavalinkSocket(lavalink.client.io.LavalinkSocket) Guild(net.dv8tion.jda.core.entities.Guild)

Example 2 with LavalinkSocket

use of lavalink.client.io.LavalinkSocket 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 3 with LavalinkSocket

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

the class NodeAdminCommand method remove.

private void remove(@Nonnull CommandContext context) {
    String name = context.args[1];
    List<LavalinkSocket> nodes = Launcher.getBotController().getAudioConnectionFacade().getLavalink().getNodes();
    int key = -1;
    for (int i = 0; i < nodes.size(); i++) {
        LavalinkSocket node = nodes.get(i);
        if (node.getName().equals(name)) {
            key = i;
        }
    }
    if (key < 0) {
        context.reply("No node with name " + name + " found.");
        return;
    }
    Launcher.getBotController().getAudioConnectionFacade().getLavalink().removeNode(key);
    context.reply("Removed node " + name);
}
Also used : LavalinkSocket(lavalink.client.io.LavalinkSocket)

Example 4 with LavalinkSocket

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

the class NodeAdminCommand method show.

private void show(@Nonnull CommandContext context) {
    String name = context.args[1];
    List<LavalinkSocket> nodes = Launcher.getBotController().getAudioConnectionFacade().getLavalink().getNodes().stream().filter(ll -> ll.getName().equals(name)).collect(Collectors.toList());
    if (nodes.isEmpty()) {
        context.reply("No such node: " + name + ", showing a list of all nodes instead");
        list(context);
        return;
    }
    RemoteStats stats = nodes.get(0).getStats();
    String out = "No stats have been received from this node! Is the node down?";
    if (stats != null) {
        out = TextUtils.asCodeBlock(stats.getAsJson().toString(4), "json");
    }
    context.reply(out);
}
Also used : LavalinkSocket(lavalink.client.io.LavalinkSocket) Launcher(fredboat.main.Launcher) RemoteStats(lavalink.client.io.RemoteStats) URISyntaxException(java.net.URISyntaxException) Command(fredboat.commandmeta.abs.Command) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) CommandContext(fredboat.commandmeta.abs.CommandContext) PermissionLevel(fredboat.definitions.PermissionLevel) TextUtils(fredboat.util.TextUtils) LavalinkLoadBalancer(lavalink.client.io.LavalinkLoadBalancer) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) LavalinkSocket(lavalink.client.io.LavalinkSocket) Context(fredboat.messaging.internal.Context) Lavalink(lavalink.client.io.Lavalink) HelpCommand(fredboat.command.info.HelpCommand) URI(java.net.URI) Nonnull(javax.annotation.Nonnull) PermsUtil(fredboat.perms.PermsUtil) RemoteStats(lavalink.client.io.RemoteStats)

Aggregations

LavalinkSocket (lavalink.client.io.LavalinkSocket)4 ArrayList (java.util.ArrayList)2 Lavalink (lavalink.client.io.Lavalink)2 LavalinkLoadBalancer (lavalink.client.io.LavalinkLoadBalancer)2 RemoteStats (lavalink.client.io.RemoteStats)2 HelpCommand (fredboat.command.info.HelpCommand)1 Command (fredboat.commandmeta.abs.Command)1 CommandContext (fredboat.commandmeta.abs.CommandContext)1 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)1 PermissionLevel (fredboat.definitions.PermissionLevel)1 Launcher (fredboat.main.Launcher)1 Context (fredboat.messaging.internal.Context)1 PermsUtil (fredboat.perms.PermsUtil)1 TextUtils (fredboat.util.TextUtils)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Guild (net.dv8tion.jda.core.entities.Guild)1