Search in sources :

Example 1 with InternalStats

use of tk.ardentbot.utils.discord.InternalStats in project Ardent by adamint.

the class Status method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Shard shard = GuildUtils.getShard(guild);
    InternalStats internalStats = InternalStats.collect();
    StringBuilder uptime = new StringBuilder();
    long secondsUptime = internalStats.getUptime();
    long days = secondsUptime / 86400;
    long hours = (secondsUptime / 3600) % 24;
    long minutes = (secondsUptime / 60) % 60;
    long seconds = secondsUptime % 60;
    if (days > 0)
        uptime.append(String.valueOf(days) + " day(s), ");
    if (hours > 0)
        uptime.append(String.valueOf(hours) + " hour(s), ");
    if (minutes > 0)
        uptime.append(String.valueOf(minutes) + " minute(s), ");
    uptime.append(String.valueOf(seconds) + " second(s)");
    DecimalFormat formatter = new DecimalFormat("#,###");
    String cmds = formatter.format(internalStats.getCommandsReceived());
    Pair<Integer, Integer> musicStats = Music.getMusicStats();
    EmbedBuilder embedBuilder = MessageUtils.getDefaultEmbed(user);
    embedBuilder.setAuthor("Ardent Status", "https://ardentbot.tk", shard.bot.getAvatarUrl());
    embedBuilder.setThumbnail("https://a.dryicons.com/images/icon_sets/polygon_icons/png/256x256/computer.png");
    embedBuilder.addField("Loaded Commands", String.valueOf(shard.factory.getLoadedCommandsAmount()), true);
    embedBuilder.addField("Received Messages", String.valueOf(internalStats.getMessagesReceived()), true);
    embedBuilder.addField("Commands Received", cmds, true);
    embedBuilder.addField("Servers", String.valueOf(internalStats.getGuilds()), true);
    embedBuilder.addField("Music Players", String.valueOf(musicStats.getK()), true);
    embedBuilder.addField("Queue Length", String.valueOf(musicStats.getV()), true);
    embedBuilder.addField("CPU Usage", internalStats.getCpu_usage() + "%", true);
    embedBuilder.addField("RAM Usage", internalStats.getUsed_ram() + " / " + internalStats.getTotal_ram() + " MB", true);
    embedBuilder.addField("Uptime", uptime.toString(), true);
    embedBuilder.addField("Website", "https://ardentbot.tk", true);
    embedBuilder.addField("Get Help", "https://ardentbot.tk/guild", true);
    sendEmbed(embedBuilder, channel, user);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) InternalStats(tk.ardentbot.utils.discord.InternalStats) DecimalFormat(java.text.DecimalFormat) Shard(tk.ardentbot.main.Shard)

Example 2 with InternalStats

use of tk.ardentbot.utils.discord.InternalStats in project Ardent by adamint.

the class SparkServer method setup.

/**
 * Sets up the web server and the endpoints
 */
public static void setup() {
    if (!testingBot)
        port(666);
    else
        return;
    Spark.exception(Exception.class, (exception, request, response) -> {
        exception.printStackTrace();
    });
    get("/api/commands", (rq, rs) -> {
        CommandFactory factory = shard0.factory;
        ArrayList<Command> commands = new ArrayList<>();
        factory.getBaseCommands().forEach(command -> {
            try {
                commands.add(new Command(command.getName(), command.getCategory(), command.getDescription()));
            } catch (Exception e) {
                new BotException(e);
            }
        });
        return shard0.gson.toJson(commands);
    });
    get("/api/staff", (rq, rs) -> {
        ArrayList<User> developers = new ArrayList<>();
        for (String id : Ardent.developers) {
            try {
                long u = Long.parseLong(id);
                net.dv8tion.jda.core.entities.User user = UserUtils.getUserById(id);
                String avatarUrl = user.getAvatarUrl();
                if (avatarUrl == null)
                    avatarUrl = getDefaultImage();
                developers.add(new User(id, user.getName(), user.getDiscriminator(), avatarUrl, "developer"));
            } catch (NumberFormatException ignored) {
            }
        }
        ArrayList<User> translators = new ArrayList<>();
        for (String id : Ardent.translators) {
            try {
                net.dv8tion.jda.core.entities.User user = UserUtils.getUserById(id);
                String avatarUrl = user.getAvatarUrl();
                if (avatarUrl == null)
                    avatarUrl = getDefaultImage();
                translators.add(new User(id, user.getName(), user.getDiscriminator(), avatarUrl, "translator"));
            } catch (NumberFormatException ignored) {
            }
        }
        ArrayList<User> moderators = new ArrayList<>();
        for (String id : Ardent.moderators) {
            try {
                net.dv8tion.jda.core.entities.User user = UserUtils.getUserById(id);
                String avatarUrl = user.getAvatarUrl();
                if (avatarUrl == null)
                    avatarUrl = getDefaultImage();
                moderators.add(new User(id, user.getName(), user.getDiscriminator(), avatarUrl, "moderator"));
            } catch (NumberFormatException ignored) {
            }
        }
        ArrayList<ArrayList<User>> staff = new ArrayList<>();
        staff.add(developers);
        staff.add(translators);
        staff.add(moderators);
        return shard0.gson.toJson(staff);
    });
    get("/api/status", (rq, rs) -> {
        InternalStats internalStats = InternalStats.collect();
        return shard0.gson.toJson(new Status(internalStats.getMessagesReceived(), internalStats.getCommandsReceived(), internalStats.getUptime(), internalStats.getLoadedCommands(), internalStats.getGuilds(), internalStats.getUsers(), internalStats.getRoleCount(), internalStats.getTextChannelCount(), internalStats.getVoiceChannelCount(), internalStats.getMusicPlayers()));
    });
}
Also used : Status(tk.ardentbot.core.misc.web.models.Status) User(tk.ardentbot.core.misc.web.models.User) ArrayList(java.util.ArrayList) CommandFactory(tk.ardentbot.core.executor.CommandFactory) BotException(tk.ardentbot.core.misc.logging.BotException) InternalStats(tk.ardentbot.utils.discord.InternalStats) Command(tk.ardentbot.core.misc.web.models.Command) BotException(tk.ardentbot.core.misc.logging.BotException)

Aggregations

InternalStats (tk.ardentbot.utils.discord.InternalStats)2 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 CommandFactory (tk.ardentbot.core.executor.CommandFactory)1 BotException (tk.ardentbot.core.misc.logging.BotException)1 Command (tk.ardentbot.core.misc.web.models.Command)1 Status (tk.ardentbot.core.misc.web.models.Status)1 User (tk.ardentbot.core.misc.web.models.User)1 Shard (tk.ardentbot.main.Shard)1