use of tk.ardentbot.core.executor.CommandFactory in project Ardent by adamint.
the class InternalStats method collect.
public static InternalStats collect() {
long messagesReceived = 0;
long commandsReceived = 0;
long loadedCommands = 0;
long guilds = 0;
long users = 0;
long roleCount = 0;
long textChannelCount = 0;
long voiceChannelCount = 0;
long musicPlayers = 0;
for (Shard shard : getShards()) {
CommandFactory factory = shard.factory;
messagesReceived += factory.getMessagesReceived();
commandsReceived += factory.getCommandsReceived();
if (loadedCommands == 0)
loadedCommands = factory.getLoadedCommandsAmount();
guilds += shard.jda.getGuilds().size();
users += shard.jda.getUsers().size();
for (Guild guild : shard.jda.getGuilds()) {
roleCount += guild.getRoles().size();
textChannelCount += guild.getTextChannels().size();
voiceChannelCount += guild.getVoiceChannels().size();
if (guild.getAudioManager().isConnected())
musicPlayers++;
}
}
return new InternalStats(messagesReceived, commandsReceived, loadedCommands, guilds, users, roleCount, textChannelCount, voiceChannelCount, musicPlayers);
}
use of tk.ardentbot.core.executor.CommandFactory 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()));
});
}
Aggregations