Search in sources :

Example 26 with JSONObject

use of org.jsolf.JSONObject in project Emolga by TecToast.

the class PickCommand method ndsdoc.

public static void ndsdoc(Tierlist tierlist, String pokemon, Draft d, long mem, String tier) {
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(d.name);
    // logger.info(d.order.get(d.round).stream().map(Member::getEffectiveName).collect(Collectors.joining(", ")));
    RequestBuilder b = new RequestBuilder(league.getString("sid"));
    String teamname = league.getJSONObject("teamnames").getString(mem);
    String sdName = getSDName(pokemon);
    JSONObject o = getDataJSON().getJSONObject(sdName);
    int i = d.picks.get(mem).size() + 14;
    Coord tl = getTierlistLocation(pokemon, tierlist);
    String gen5Sprite = getGen5Sprite(o);
    b.addSingle(teamname + "!B" + i, gen5Sprite).addSingle(teamname + "!D" + i, pokemon).addSingle("Tierliste!" + getAsXCoord(tl.x() * 6 + 6) + (tl.y() + 4), "='" + teamname + "'!B2");
    List<Object> t = o.getStringList("types").stream().map(s -> getTypeIcons().getString(s)).collect(Collectors.toCollection(LinkedList::new));
    if (t.size() == 1)
        t.add("/");
    b.addRow(teamname + "!F" + i, t);
    b.addSingle(teamname + "!H" + i, o.getJSONObject("baseStats").getInt("spe"));
    int pointsNeeded = tierlist.getPointsNeeded(pokemon);
    b.addSingle(teamname + "!I" + i, pointsNeeded);
    b.addSingle(teamname + "!J" + i, "2");
    b.addRow(teamname + "!L" + i, Arrays.asList(canLearnNDS(sdName, "stealthrock"), canLearnNDS(sdName, "defog"), canLearnNDS(sdName, "rapidspin"), canLearnNDS(sdName, "voltswitch", "uturn", "flipturn", "batonpass", "teleport")));
    int numInRound = d.originalOrder.get(d.round).indexOf(mem) + 1;
    b.addSingle("Draft!%s%d".formatted(getAsXCoord(d.round * 5 - 3), numInRound * 5 + 2), "《《《《").addSingle("Draft!%s%d".formatted(getAsXCoord(d.round * 5 - 1), numInRound * 5 + 2), pokemon).addSingle("Draft!%s%d".formatted(getAsXCoord(d.round * 5), numInRound * 5 + 1), gen5Sprite).addSingle("Draft!%s%d".formatted(getAsXCoord(d.round * 5), numInRound * 5 + 3), pointsNeeded);
    logger.info("d.members.size() = " + d.members.size());
    logger.info("d.order.size() = " + d.order.get(d.round).size());
    logger.info("d.members.size() - d.order.size() = " + numInRound);
    // if (d.members.size() - d.order.get(d.round).size() != 1 && isEnabled)
    b.execute();
}
Also used : JSONObject(org.jsolf.JSONObject) java.util(java.util) Logger(org.slf4j.Logger) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) LoggerFactory(org.slf4j.LoggerFactory) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Draft.getIndex(de.tectoast.emolga.utils.draft.Draft.getIndex) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) Collectors(java.util.stream.Collectors) Command(de.tectoast.emolga.commands.Command) Coord(de.tectoast.emolga.utils.records.Coord) Draft(de.tectoast.emolga.utils.draft.Draft) com.google.api.services.sheets.v4.model(com.google.api.services.sheets.v4.model) Nullable(javax.annotation.Nullable) Coord(de.tectoast.emolga.utils.records.Coord) JSONObject(org.jsolf.JSONObject) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) JSONObject(org.jsolf.JSONObject)

Example 27 with JSONObject

use of org.jsolf.JSONObject in project Emolga by TecToast.

the class PickCommand method zbsdoc.

private static void zbsdoc(Tierlist tierlist, String pokemon, Draft d, Member mem, String tier, int num, int round) {
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(d.name);
    if (league.has("sid")) {
        String doc = league.getString("sid");
        int x = 1;
        int y = 2;
        for (String s : tierlist.tiercolumns) {
            if (s.equalsIgnoreCase(pokemon))
                break;
            // logger.info(s + " " + y);
            if (s.equals("NEXT")) {
                x++;
                y = 2;
            } else
                y++;
        }
        logger.info("num = " + num);
        RequestBuilder b = new RequestBuilder(doc);
        b.addStrikethroughChange(910228334, x * 2 + 1, y, true);
        // logger.info(d.order.get(d.round).stream().map(Member::getEffectiveName).collect(Collectors.joining(", ")));
        b.addStrikethroughChange(856868721, d.round + 2, num + 2, true);
        int user = league.getLongList("table").indexOf(mem.getIdLong());
        String range = "Liga 2!" + getAsXCoord((int) (tier.equals("S") ? (12 + d.picks.get(mem.getIdLong()).stream().filter(p -> p.tier.equals("S")).count()) : (tierlist.order.indexOf(tier) * 3 + 11 + d.picks.get(mem.getIdLong()).stream().filter(p -> p.tier.equals(tier)).count()))) + (user + 3);
        logger.info("range = " + range);
        b.addSingle(range, getGen5Sprite(pokemon));
        logger.info("d.members.size() = " + d.members.size());
        logger.info("d.order.size() = " + d.order.get(d.round).size());
        logger.info("d.members.size() - d.order.size() = " + (d.members.size() - d.order.get(d.round).size()));
        // if (d.members.size() - d.order.get(d.round).size() != 1 && isEnabled)
        b.execute();
    }
}
Also used : JSONObject(org.jsolf.JSONObject) java.util(java.util) Logger(org.slf4j.Logger) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) LoggerFactory(org.slf4j.LoggerFactory) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Draft.getIndex(de.tectoast.emolga.utils.draft.Draft.getIndex) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) Collectors(java.util.stream.Collectors) Command(de.tectoast.emolga.commands.Command) Coord(de.tectoast.emolga.utils.records.Coord) Draft(de.tectoast.emolga.utils.draft.Draft) com.google.api.services.sheets.v4.model(com.google.api.services.sheets.v4.model) Nullable(javax.annotation.Nullable) JSONObject(org.jsolf.JSONObject) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder)

Example 28 with JSONObject

use of org.jsolf.JSONObject in project Emolga by TecToast.

the class ShowdownExportCommand method process.

@Override
public void process(GuildCommandEvent e) {
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(e.getArguments().getText("draft"));
    JSONObject picksObj = league.getJSONObject("picks");
    StringBuilder b = new StringBuilder();
    ArrayList<String> ids = new ArrayList<>(picksObj.keySet());
    HashMap<String, String> names = new HashMap<>();
    emolgajda.getGuildById(league.getString("guild")).retrieveMembersByIds(ids.toArray(new String[0])).get().forEach(mem -> names.put(mem.getId(), mem.getEffectiveName()));
    for (String id : ids) {
        JSONArray picksArr = picksObj.getJSONArray(id);
        JSONArray oneUser = new JSONArray();
        b.append("=== [gen8nationaldexag-box] ").append(e.getArg(0)).append("/").append(names.get(id)).append(" ===\n\n");
        picksArr.toList().stream().map(o -> (String) ((HashMap<String, Object>) o).get("name")).sorted(Comparator.comparing(str -> getDataJSON().getJSONObject(getDataName((String) str)).getJSONObject("baseStats").getInt("spe")).reversed()).map(str -> {
            if (sdex.containsKey(str)) {
                return getEnglName(getFirst(str)) + getFirstAfterUppercase(sdex.get(str)) + " \nAbility: " + getDataJSON().getJSONObject(getDataName(str)).getJSONObject("abilities").getString("0");
            }
            if (str.startsWith("A-")) {
                return getEnglName(str.substring(2)) + "-Alola \nAbility: " + getDataJSON().getJSONObject(getDataName(str)).getJSONObject("abilities").getString("0");
            }
            if (str.startsWith("G-")) {
                return getEnglName(str.substring(2)) + "-Galar \nAbility: " + getDataJSON().getJSONObject(getDataName(str)).getJSONObject("abilities").getString("0");
            }
            if (str.startsWith("M-")) {
                return getEnglName(str.substring(2)) + "-Mega \nAbility: " + getDataJSON().getJSONObject(getDataName(str)).getJSONObject("abilities").getString("0");
            }
            return getEnglName(str) + " \nAbility: " + getDataJSON().getJSONObject(getDataName(str)).getJSONObject("abilities").getString("0");
        }).forEach(str -> b.append(str).append("\n\n"));
        b.append("\n");
        if (b.length() > 1500) {
            e.reply(b.toString());
            b.setLength(0);
        }
    }
    e.reply(b.toString());
}
Also used : Command(de.tectoast.emolga.commands.Command) JSONObject(org.jsolf.JSONObject) JSONArray(org.jsolf.JSONArray) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) HashMap(java.util.HashMap) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) EmolgaMain.emolgajda(de.tectoast.emolga.bot.EmolgaMain.emolgajda) JSONObject(org.jsolf.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.jsolf.JSONArray) JSONObject(org.jsolf.JSONObject)

Example 29 with JSONObject

use of org.jsolf.JSONObject in project Emolga by TecToast.

the class SkipCommand method process.

@Override
public void process(GuildCommandEvent e) {
    String msg = e.getMsg();
    TextChannel tco = e.getChannel();
    Member memberr = e.getMember();
    long member = memberr.getIdLong();
    Draft d = Draft.getDraftByMember(member, tco);
    if (d == null) {
        // tco.sendMessage(member.getAsMention() + " Du bist in keinem Draft drin!").queue();
        return;
    }
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(d.name);
    if (!d.tc.getId().equals(tco.getId()))
        return;
    if (!d.isSwitchDraft) {
        e.reply("Dieser Draft ist kein Switch-Draft, daher wird !skip nicht unterstützt!");
        return;
    }
    if (d.isNotCurrent(member)) {
        tco.sendMessage(d.getMention(member) + " Du bist nicht dran!").queue();
        return;
    }
    d.cooldown.cancel(false);
    int round = d.round;
    if (d.order.get(d.round).size() == 0) {
        if (d.round == d.getTierlist().rounds) {
            tco.sendMessage("Der Draft ist vorbei!").queue();
            d.ended = true;
            // wooloodoc(tierlist, pokemon, d, mem, needed, null, num, round);
            if (d.afterDraft.size() > 0)
                tco.sendMessage("Reihenfolge zum Nachdraften:\n" + d.afterDraft.stream().map(d::getMention).collect(Collectors.joining("\n"))).queue();
            saveEmolgaJSON();
            Draft.drafts.remove(d);
            return;
        }
        d.round++;
        d.tc.sendMessage("Runde " + d.round + "!").queue();
        league.put("round", d.round);
    }
    logger.info("d.order = " + d.order);
    logger.info("d.round = " + d.round);
    d.current = d.order.get(d.round).remove(0);
    league.put("current", d.current);
    JSONObject asl = getEmolgaJSON().getJSONObject("drafts");
    tco.sendMessage(d.getMention(d.current) + " ist dran! (" + d.points.get(d.current) + " mögliche Punkte)").queue();
    d.cooldown.cancel(false);
    long delay = calculateDraftTimer();
    league.put("cooldown", System.currentTimeMillis() + delay);
    d.cooldown = d.scheduler.schedule((Runnable) d::timer, delay, TimeUnit.MILLISECONDS);
    saveEmolgaJSON();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) Draft(de.tectoast.emolga.utils.draft.Draft) JSONObject(org.jsolf.JSONObject) Command(de.tectoast.emolga.commands.Command) Member(net.dv8tion.jda.api.entities.Member)

Example 30 with JSONObject

use of org.jsolf.JSONObject in project Emolga by TecToast.

the class CounterButton method process.

@Override
public void process(ButtonClickEvent e, String name) {
    String[] split = name.split(":");
    String method = split[0];
    Member mem = e.getMember();
    JSONObject counter = shinycountjson.getJSONObject("counter");
    String id = mem.getId().equals("893773494578470922") ? "598199247124299776" : mem.getId();
    counter.getJSONObject(method).put(id, counter.getJSONObject(method).optInt(id, 0) + Integer.parseInt(split[1]));
    Command.updateShinyCounts(e);
}
Also used : JSONObject(org.jsolf.JSONObject) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

JSONObject (org.jsolf.JSONObject)72 TextChannel (net.dv8tion.jda.api.entities.TextChannel)23 Member (net.dv8tion.jda.api.entities.Member)20 Command (de.tectoast.emolga.commands.Command)19 JSONArray (org.jsolf.JSONArray)19 RequestBuilder (de.tectoast.emolga.utils.RequestBuilder)16 CommandCategory (de.tectoast.emolga.commands.CommandCategory)15 GuildCommandEvent (de.tectoast.emolga.commands.GuildCommandEvent)15 Draft (de.tectoast.emolga.utils.draft.Draft)14 Guild (net.dv8tion.jda.api.entities.Guild)13 DraftPokemon (de.tectoast.emolga.utils.draft.DraftPokemon)12 Collectors (java.util.stream.Collectors)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tierlist (de.tectoast.emolga.utils.draft.Tierlist)10 Coord (de.tectoast.emolga.utils.records.Coord)9 Draft.getIndex (de.tectoast.emolga.utils.draft.Draft.getIndex)8 ResultSet (java.sql.ResultSet)8 java.util (java.util)8 ArrayList (java.util.ArrayList)7