Search in sources :

Example 1 with RequestBuilder

use of de.tectoast.emolga.utils.RequestBuilder in project Emolga by TecToast.

the class Draft method doNDSNominate.

public static void doNDSNominate() {
    JSONObject nds = getEmolgaJSON().getJSONObject("drafts").getJSONObject("NDS");
    JSONObject nom = nds.getJSONObject("nominations");
    int cday = nom.getInt("currentDay");
    JSONObject o = nom.getJSONObject(String.valueOf(cday));
    JSONObject picks = nds.getJSONObject("picks");
    String sid = nds.getString("sid");
    RequestBuilder builder = new RequestBuilder(sid);
    RequestGetter getter = new RequestGetter(sid);
    List<List<List<Object>>> get = new LinkedList<>();
    int temp = 0;
    for (String s : picks.keySet()) {
        logger.info(MarkerFactory.getMarker("important"), "{} {}", temp, s);
        get.add(Google.get(sid, nds.getJSONObject("teamnames").getString(s) + "!B15:O29", true, false));
        temp++;
    }
    int x = 0;
    for (String u : picks.keySet()) {
        // String u = "297010892678234114";
        if (!o.has(u)) {
            if (cday == 1) {
                List<JSONObject> mons = picks.getJSONList(u);
                o.put(u, mons.stream().limit(11).map(obj -> obj.getString("name")).collect(Collectors.joining(";")) + "###" + mons.stream().skip(11).map(obj -> obj.getString("name")).collect(Collectors.joining(";")));
            } else {
                o.put(u, nom.getJSONObject(String.valueOf(cday - 1)).getString(u));
            }
        }
        // logger.info("o.get(u) = " + o.get(u));
        String str = o.getString(u);
        List<String> mons = Arrays.stream(str.split("###")).flatMap(s -> Arrays.stream(s.split(";"))).toList();
        logger.info("mons = " + mons);
        String range = nds.getJSONObject("teamnames").getString(u) + "!B15:O29";
        logger.info("u = " + u);
        logger.info("range = " + range);
        builder.addAll(range, get.get(x).stream().filter(n -> !n.get(2).equals("")).sorted(Comparator.comparing(n -> {
            String s1 = (String) n.get(2);
            logger.info("s1 = " + s1);
            int ret = mons.indexOf(s1);
            logger.info("ret = " + ret);
            return ret;
        })).collect(Collectors.toList()));
        x++;
    }
    builder.execute();
    nom.increment("currentDay");
    saveEmolgaJSON();
}
Also used : Message(net.dv8tion.jda.api.entities.Message) JSONObject(org.jsolf.JSONObject) java.util(java.util) JDA(net.dv8tion.jda.api.JDA) Logger(org.slf4j.Logger) RequestGetter(de.tectoast.emolga.utils.RequestGetter) java.util.concurrent(java.util.concurrent) LoggerFactory(org.slf4j.LoggerFactory) MarkerFactory(org.slf4j.MarkerFactory) SimpleDateFormat(java.text.SimpleDateFormat) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Collectors(java.util.stream.Collectors) Google(de.tectoast.emolga.utils.Google) Command(de.tectoast.emolga.commands.Command) Guild(net.dv8tion.jda.api.entities.Guild) JSONArray(org.jsolf.JSONArray) Constants(de.tectoast.emolga.utils.Constants) Pattern(java.util.regex.Pattern) Emote(net.dv8tion.jda.api.entities.Emote) EmolgaMain.emolgajda(de.tectoast.emolga.bot.EmolgaMain.emolgajda) RequestGetter(de.tectoast.emolga.utils.RequestGetter) JSONObject(org.jsolf.JSONObject) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) JSONObject(org.jsolf.JSONObject)

Example 2 with RequestBuilder

use of de.tectoast.emolga.utils.RequestBuilder in project Emolga by TecToast.

the class PickCommand method aslS10Doc.

private static void aslS10Doc(Tierlist tierlist, String pokemon, Draft d, long mem, String tier, int effectiveRound) {
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(d.name);
    String sid = league.getString("sid");
    RequestBuilder b = new RequestBuilder(sid);
    Coord c = getTierlistLocation(pokemon, tierlist);
    logger.info("c.toString() = {}", c);
    logger.info("c.valid() = {}", c.valid());
    if (c.valid())
        b.addBGColorChange(league.getInt("tierlist"), c.x() * 2 + 2, c.y() + 5, convertColor(0xFF0000));
    Coord cengl = getTierlistLocation(pokemon, tierlist.tiercolumnsEngl);
    if (cengl.valid())
        b.addBGColorChange(league.getInt("tierlistengl"), cengl.x() * 2 + 2, cengl.y() + 5, convertColor(0xFF0000));
    Integer points = tierlist.prices.get(tier);
    Comparator<DraftPokemon> comparator = Comparator.comparing(p -> tierlist.order.indexOf(p.getTier()));
    Comparator<DraftPokemon> finalComp = comparator.thenComparing(p -> p.name);
    b.addAll("Teamseite HR!B%d".formatted(league.getLongList("table").indexOf(mem) * 15 + 4), d.picks.get(mem).stream().sorted(finalComp).map(mon -> new ArrayList<Object>(Arrays.asList(mon.getTier(), mon.getName(), getDataJSON().getJSONObject(getSDName(mon.getName())).getJSONObject("baseStats").getInt("spe")))).collect(Collectors.toList()));
    int rr = effectiveRound - 1;
    logger.info("d.originalOrder = {}", d.originalOrder);
    logger.info("effectiveRound = {}", effectiveRound);
    logger.info("mem = {}", mem);
    int index = d.originalOrder.get(effectiveRound).indexOf(mem);
    logger.info("index = {}", index);
    b.addRow("Draft!%s%d".formatted(getAsXCoord((rr % 6) * 4 + 3), (rr / 6) * 10 + 4 + index), Arrays.asList(pokemon, points));
    b.execute();
}
Also used : Coord(de.tectoast.emolga.utils.records.Coord) JSONObject(org.jsolf.JSONObject) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) JSONObject(org.jsolf.JSONObject)

Example 3 with RequestBuilder

use of de.tectoast.emolga.utils.RequestBuilder in project Emolga by TecToast.

the class PickCommand method aslCoachDoc.

private static void aslCoachDoc(Tierlist tierlist, String pokemon, Draft d, Member mem, int needed, int round, @Nullable DraftPokemon removed) {
    JSONObject asl = getEmolgaJSON().getJSONObject("drafts").getJSONObject("ASLS9");
    JSONObject league = asl.getJSONObject(d.name);
    String sid = asl.getString("sid");
    int x = 1;
    int y = 5;
    boolean found = false;
    for (String s : tierlist.tiercolumns) {
        if (s.equalsIgnoreCase(pokemon)) {
            found = true;
            break;
        }
        // logger.info(s + " " + y);
        if (s.equals("NEXT")) {
            x++;
            y = 5;
        } else
            y++;
    }
    RequestBuilder b = new RequestBuilder(sid);
    if (found) {
        b.addBGColorChange(league.getInt("tierlist"), x * 2, y, convertColor(0xff0000));
    }
    x = 1;
    y = 5;
    if (removed != null) {
        for (String s : tierlist.tiercolumns) {
            if (s.equalsIgnoreCase(removed.name)) {
                break;
            }
            // logger.info(s + " " + y);
            if (s.equals("NEXT")) {
                x++;
                y = 5;
            } else
                y++;
        }
        /*Request request = new Request();
            request.setUpdateCells(new UpdateCellsRequest().setRows(Collections.singletonList(new RowData()
                            .setValues(Collections.singletonList(new CellData()
                                    .setUserEnteredFormat(new CellFormat()
                                            .setBackgroundColor(new Color()
                                                    .setRed((float) 0.5764706).setGreen((float) 0.76862746).setBlue((float) 0.49019608)))))))
                    .setFields("userEnteredFormat.backgroundColor").setRange(new GridRange().setSheetId(league.getInt("tierlist")).setStartRowIndex(y).setEndRowIndex(y + 1).setStartColumnIndex(x * 2 - 1).setEndColumnIndex(x * 2)));
            b.addBatch(request);*/
        b.addBGColorChange(league.getInt("tierlist"), x * 2, y, convertColor(0x93c47d));
    }
    // logger.info(d.order.get(d.round).stream().map(Member::getEffectiveName).collect(Collectors.joining(", ")));
    String team = asl.getStringList("teams").get(getIndex(mem.getIdLong()));
    int yc = (Draft.getLevel(mem.getIdLong()) * 20 + d.picks.get(mem.getIdLong()).size());
    List<Integer> list = new LinkedList<>();
    for (int i = 0; i < 9; i++) {
        list.add(i * 4 + 10);
    }
    b.addRow(team + "!B" + yc, Arrays.asList(getGen5Sprite(pokemon), pokemon, needed, "=" + list.stream().map(i -> getAsXCoord(i) + yc).collect(Collectors.joining(" + ")), "=" + list.stream().map(i -> getAsXCoord(i + 1) + yc).collect(Collectors.joining(" + ")), ("=E" + yc + " - F" + yc), getDataJSON().getJSONObject(getSDName(pokemon)).getJSONObject("baseStats").getInt("spe")));
    b.execute();
}
Also used : JSONObject(org.jsolf.JSONObject) RequestBuilder(de.tectoast.emolga.utils.RequestBuilder)

Example 4 with RequestBuilder

use of de.tectoast.emolga.utils.RequestBuilder in project Emolga by TecToast.

the class PickCommand method woolooolddoc.

/*public void doc(Tierlist tierlist, String pokemon, Draft d, Member mem, String tier, JSONObject league, int pk) {
        zbsdoc(tierlist, pokemon, d, mem, tier, num);
        //aslnocoachdoc(tierlist, pokemon, d, mem, tier, league, pk);
    }*/
private static void woolooolddoc(Tierlist tierlist, String pokemon, Draft d, Member mem, int needed, @Nullable DraftPokemon removed, int num, int round) {
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(d.name);
    String sid = league.getString("sid");
    int x = 1;
    int y = 2;
    boolean found = false;
    for (String s : tierlist.tiercolumns) {
        if (s.equalsIgnoreCase(pokemon)) {
            found = true;
            break;
        }
        // logger.info(s + " " + y);
        if (s.equals("NEXT")) {
            x++;
            y = 2;
        } else
            y++;
    }
    RequestBuilder b = new RequestBuilder(sid);
    if (found) {
        Request request = new Request();
        request.setUpdateCells(new UpdateCellsRequest().setRows(Collections.singletonList(new RowData().setValues(Collections.singletonList(new CellData().setUserEnteredFormat(new CellFormat().setBackgroundColor(new Color().setRed(1f))))))).setFields("userEnteredFormat.backgroundColor").setRange(new GridRange().setSheetId(league.getInt("tierlist")).setStartRowIndex(y).setEndRowIndex(y + 1).setStartColumnIndex(x * 2 - 1).setEndColumnIndex(x * 2)));
        b.addBatch(request);
    }
    x = 1;
    y = 2;
    if (removed != null) {
        for (String s : tierlist.tiercolumns) {
            if (s.equalsIgnoreCase(removed.name)) {
                break;
            }
            // logger.info(s + " " + y);
            if (s.equals("NEXT")) {
                x++;
                y = 2;
            } else
                y++;
        }
        Request request = new Request();
        request.setUpdateCells(new UpdateCellsRequest().setRows(Collections.singletonList(new RowData().setValues(Collections.singletonList(new CellData().setUserEnteredFormat(new CellFormat().setBackgroundColor(new Color().setRed((float) 0.5764706).setGreen((float) 0.76862746).setBlue((float) 0.49019608))))))).setFields("userEnteredFormat.backgroundColor").setRange(new GridRange().setSheetId(league.getInt("tierlist")).setStartRowIndex(y).setEndRowIndex(y + 1).setStartColumnIndex(x * 2 - 1).setEndColumnIndex(x * 2)));
        b.addBatch(request);
    }
    Request req = new Request();
    // logger.info(d.order.get(d.round).stream().map(Member::getEffectiveName).collect(Collectors.joining(", ")));
    req.setUpdateCells(new UpdateCellsRequest().setRows(Collections.singletonList(new RowData().setValues(Collections.singletonList(new CellData().setUserEnteredFormat(new CellFormat().setTextFormat(new TextFormat().setStrikethrough(true))))))).setFields("userEnteredFormat.textFormat.strikethrough").setRange(new GridRange().setSheetId(1316641169).setStartRowIndex(num + 1).setEndRowIndex(num + 2).setStartColumnIndex(round).setEndColumnIndex(round + 1)));
    // logger.info(d.order.get(d.round).stream().map(Member::getEffectiveName).collect(Collectors.joining(", ")));
    b.addBatch(req);
    int user = Arrays.asList(league.getString("table").split(",")).indexOf(mem.getId());
    List<DraftPokemon> picks = d.picks.get(mem.getIdLong());
    for (int i = 0; i < 13; i++) {
        List<Object> list = new ArrayList<>();
        if (i < picks.size()) {
            DraftPokemon mon = picks.get(i);
            list.add(tierlist.prices.get(mon.tier));
            list.add(mon.name);
        } else {
            list.add("");
            list.add("");
        }
        b.addRow("Teamübersicht!" + getAsXCoord((user > 3 ? user - 4 : user) * 6 + 2) + ((user > 3 ? 25 : 7) + i), list);
    }
    b.execute();
}
Also used : RequestBuilder(de.tectoast.emolga.utils.RequestBuilder) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) JSONObject(org.jsolf.JSONObject) JSONObject(org.jsolf.JSONObject)

Example 5 with RequestBuilder

use of de.tectoast.emolga.utils.RequestBuilder 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)

Aggregations

RequestBuilder (de.tectoast.emolga.utils.RequestBuilder)14 JSONObject (org.jsolf.JSONObject)13 DraftPokemon (de.tectoast.emolga.utils.draft.DraftPokemon)9 Command (de.tectoast.emolga.commands.Command)7 Coord (de.tectoast.emolga.utils.records.Coord)7 Collectors (java.util.stream.Collectors)7 TextChannel (net.dv8tion.jda.api.entities.TextChannel)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 CommandCategory (de.tectoast.emolga.commands.CommandCategory)6 GuildCommandEvent (de.tectoast.emolga.commands.GuildCommandEvent)6 Draft (de.tectoast.emolga.utils.draft.Draft)6 Draft.getIndex (de.tectoast.emolga.utils.draft.Draft.getIndex)6 Tierlist (de.tectoast.emolga.utils.draft.Tierlist)6 Member (net.dv8tion.jda.api.entities.Member)6 java.util (java.util)4 com.google.api.services.sheets.v4.model (com.google.api.services.sheets.v4.model)3 Arrays (java.util.Arrays)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3