use of tk.ardentbot.core.misc.web.models.Command 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