Search in sources :

Example 1 with UserScore

use of com.osu.api.ciyfhx.UserScore in project MantaroBot by Mantaro.

the class OsuStatsCmd method best.

private static String best(String content) {
    String finalResponse;
    try {
        long start = System.currentTimeMillis();
        String beheaded1 = content.replace("best ", "");
        String[] args = beheaded1.split(" ");
        map.put("m", 0);
        User hey = osuClient.getUser(args[0], map);
        List<UserScore> userBest = osuClient.getUserBest(hey, map);
        StringBuilder sb = new StringBuilder();
        List<String> best = new CopyOnWriteArrayList<>();
        int n1 = 0;
        DecimalFormat df = new DecimalFormat("####0.0");
        for (UserScore userScore : userBest) {
            if (n1 > 9)
                break;
            if (userScore.getEnabledMods().size() > 0) {
                List<Mod> mods = userScore.getEnabledMods();
                StringBuilder sb1 = new StringBuilder();
                mods.forEach(mod -> sb1.append(OsuMod.get(mod).getAbbreviation()));
                mods1 = " Mods: " + sb1.toString();
            }
            best.add(String.format("# %s -> %s\n | ###### |  [%spp] -> Rank: %s\n | (★%s) - %s | Date: %s -> Max Combo: %d\n", userScore.getBeatMap().getTitle().replace("'", ""), mods1, df.format(userScore.getPP()), userScore.getRank(), df.format(userScore.getBeatMap().getDifficultyRating()), userScore.getBeatMap().getCreator(), userScore.getDate(), userScore.getMaxCombo()));
            sb.append(best.get(n1));
            n1++;
        }
        long end = System.currentTimeMillis() - start;
        finalResponse = "```md\n" + sb.toString() + " \n<Response time: " + end + "ms>```";
    } catch (Exception e) {
        if (e instanceof JSONException)
            finalResponse = EmoteReference.ERROR + "No results found.";
        else {
            finalResponse = EmoteReference.ERROR + "Error while looking for results.";
            log.warn("Error retrieving results from osu!API", e);
        }
    }
    return finalResponse;
}
Also used : User(com.osu.api.ciyfhx.User) Mod(com.osu.api.ciyfhx.Mod) OsuMod(net.kodehawa.mantarobot.commands.osu.OsuMod) DecimalFormat(java.text.DecimalFormat) JSONException(org.json.JSONException) JSONException(org.json.JSONException) UserScore(com.osu.api.ciyfhx.UserScore)

Example 2 with UserScore

use of com.osu.api.ciyfhx.UserScore in project MantaroBot by Mantaro.

the class OsuStatsCmd method recent.

private static String recent(String content) {
    String finalMessage;
    try {
        long start = System.currentTimeMillis();
        String beheaded1 = content.replace("recent ", "");
        String[] args = beheaded1.split(" ");
        map.put("m", 0);
        User hey = osuClient.getUser(args[0], map);
        List<UserScore> userRecent = osuClient.getUserRecent(hey, map);
        StringBuilder sb = new StringBuilder();
        List<String> recent = new CopyOnWriteArrayList<>();
        int n1 = 0;
        DecimalFormat df = new DecimalFormat("####0.0");
        for (UserScore u : userRecent) {
            if (n1 > 9)
                break;
            n1++;
            if (u.getEnabledMods().size() > 0) {
                List<Mod> mods = u.getEnabledMods();
                StringBuilder sb1 = new StringBuilder();
                mods.forEach(mod -> sb1.append(OsuMod.get(mod).getAbbreviation()));
                mods1 = " Mods: " + sb1.toString();
            }
            recent.add(String.format("# %s -> %s\n | (★%s) - %s | Date: %s -> Max Combo: %d\n", u.getBeatMap().getTitle().replace("'", ""), mods1, df.format(u.getBeatMap().getDifficultyRating()), u.getBeatMap().getCreator(), u.getDate(), u.getMaxCombo()));
        }
        recent.forEach(sb::append);
        long end = System.currentTimeMillis() - start;
        finalMessage = "```md\n" + sb.toString() + " \n<Response time: " + end + "ms>```";
    } catch (Exception e) {
        if (e instanceof JSONException)
            finalMessage = EmoteReference.ERROR + "No results found.";
        else {
            finalMessage = EmoteReference.ERROR + "Error while looking for results.";
            log.warn("Error retrieving results from osu!API", e);
        }
    }
    return finalMessage;
}
Also used : User(com.osu.api.ciyfhx.User) Mod(com.osu.api.ciyfhx.Mod) OsuMod(net.kodehawa.mantarobot.commands.osu.OsuMod) DecimalFormat(java.text.DecimalFormat) JSONException(org.json.JSONException) JSONException(org.json.JSONException) UserScore(com.osu.api.ciyfhx.UserScore)

Aggregations

Mod (com.osu.api.ciyfhx.Mod)2 User (com.osu.api.ciyfhx.User)2 UserScore (com.osu.api.ciyfhx.UserScore)2 DecimalFormat (java.text.DecimalFormat)2 OsuMod (net.kodehawa.mantarobot.commands.osu.OsuMod)2 JSONException (org.json.JSONException)2