Search in sources :

Example 11 with GuildCommandEvent

use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.

the class SwitchCommand 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(memberr.getAsMention() + " Du bist in keinem Draft drin!").queue();
        return;
    }
    if (!d.tc.getId().equals(tco.getId()))
        return;
    if (!d.isSwitchDraft) {
        e.reply("Dieser Draft ist kein Switch-Draft, daher wird !switch nicht unterstützt!");
        return;
    }
    if (msg.equals("!switch")) {
        e.reply("Willst du vielleicht noch zwei Pokemon dahinter schreiben? xD");
        return;
    }
    if (d.isNotCurrent(member)) {
        tco.sendMessage(d.getMention(member) + " Du bist nicht dran!").queue();
        return;
    }
    long mem = d.current;
    JSONObject json = getEmolgaJSON();
    JSONObject league = json.getJSONObject("drafts").getJSONObject(d.name);
    // JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject("ZBSL2");
    /*if (asl.has("allowed")) {
                JSONObject allowed = asl.getJSONObject("allowed");
                if (allowed.has(member.getId())) {
                    mem = d.tc.getGuild().retrieveMemberById(allowed.getString(member.getId())).complete();
                } else mem = member;
            } else mem = member;*/
    Translation t;
    ArgumentManager args = e.getArguments();
    String oldmon = args.getText("oldmon");
    String newmon = args.getText("newmon");
    Tierlist tierlist = d.getTierlist();
    if (!d.isPickedBy(oldmon, mem)) {
        e.reply(memberr.getAsMention() + " " + oldmon + " befindet sich nicht in deinem Kader!");
        return;
    }
    if (d.isPicked(newmon)) {
        e.reply(memberr.getAsMention() + " " + newmon + " wurde bereits gepickt!");
        return;
    }
    int pointsBack = tierlist.getPointsNeeded(oldmon);
    if (pointsBack == -1) {
        e.reply("Das, was du rauswerfen möchtest, steht nicht in der Tierliste!");
        return;
    }
    logger.info("oldmon = " + oldmon);
    logger.info("newmon = " + newmon);
    int newpoints = tierlist.getPointsNeeded(newmon);
    if (newpoints == -1) {
        e.reply("Das, was du haben möchtest, steht nicht in der Tierliste!");
        return;
    }
    String tier = tierlist.getTierOf(newmon);
    d.points.put(mem, d.points.get(mem) + pointsBack);
    if (d.points.get(mem) - newpoints < 0) {
        d.points.put(mem, d.points.get(mem) - pointsBack);
        e.reply(memberr.getAsMention() + " Du kannst dir " + newmon + " nicht leisten!");
        return;
    }
    d.points.put(mem, d.points.get(mem) - newpoints);
    DraftPokemon oldMon = d.picks.get(mem).stream().filter(draftMon -> draftMon.name.equalsIgnoreCase(oldmon)).map(DraftPokemon::copy).findFirst().orElse(null);
    Optional<DraftPokemon> drp = d.picks.get(mem).stream().filter(dp -> dp.name.equalsIgnoreCase(oldmon)).findFirst();
    if (drp.isEmpty()) {
        logger.error("DRP NULL LINE 232");
        return;
    }
    DraftPokemon dp = drp.get();
    dp.setName(newmon);
    dp.setTier(tierlist.getTierOf(newmon));
    // m.delete().queue();
    d.update(mem);
    // fpldoc(tierlist, newmon, d, mem, newpoints, new DraftPokemon(oldmon, tierlist.getTierOf(oldmon)));
    // fpldoc(tierlist, newmon, d, mem, tier, d.members.size() - d.order.get(d.round).size(), d.round, oldmon);
    ndsdoc(tierlist, d, mem, oldMon, dp);
    league.getJSONObject("picks").put(d.current, d.getTeamAsArray(d.current));
    if (newmon.equals("Emolga")) {
        tco.sendMessage("<:Happy:701070356386938991> <:Happy:701070356386938991> <:Happy:701070356386938991> <:Happy:701070356386938991> <:Happy:701070356386938991>").queue();
    }
    d.cooldown.cancel(false);
    int round = d.round;
    if (d.order.get(d.round).size() == 0) {
        if (d.round == tierlist.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);
    }
    d.current = d.order.get(d.round).remove(0);
    league.put("current", d.current);
    JSONObject drafts = getEmolgaJSON().getJSONObject("drafts");
    tco.sendMessage(d.getMention(d.current) + " ist dran! (" + d.points.get(d.current) + " mögliche Punkte)").queue();
    // tco.sendMessage(d.getMention(d.current) + " ist dran! (" + d.points.get(d.current.getIdLong()) + " mögliche Punkte)").queue();
    long delay = calculateDraftTimer();
    league.put("cooldown", System.currentTimeMillis() + delay);
    d.cooldown = d.scheduler.schedule((Runnable) d::timer, delay, TimeUnit.MILLISECONDS);
    saveEmolgaJSON();
}
Also used : IntStream(java.util.stream.IntStream) JSONObject(org.jsolf.JSONObject) Arrays(java.util.Arrays) 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) TimeUnit(java.util.concurrent.TimeUnit) Command(de.tectoast.emolga.commands.Command) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) List(java.util.List) Coord(de.tectoast.emolga.utils.records.Coord) Draft(de.tectoast.emolga.utils.draft.Draft) Optional(java.util.Optional) LinkedList(java.util.LinkedList) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) Command(de.tectoast.emolga.commands.Command) Coord(de.tectoast.emolga.utils.records.Coord) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Draft(de.tectoast.emolga.utils.draft.Draft) JSONObject(org.jsolf.JSONObject) Member(net.dv8tion.jda.api.entities.Member)

Example 12 with GuildCommandEvent

use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.

the class UpdatedatafromfileCommand method process.

@Override
public void process(GuildCommandEvent e) {
    TextChannel tco = e.getChannel();
    Message m = e.getMessage();
    String msg = m.getContentDisplay();
    String name = e.getArguments().getText("name");
    Optional<Draft> op = Draft.drafts.stream().filter(d -> d.name.equals(name)).findFirst();
    if (op.isEmpty()) {
        tco.sendMessage("Dieser Draft existiert nicht!").queue();
        return;
    }
    Draft d = op.get();
    JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(name);
    int lround = league.getInt("round");
    if (d.round != lround) {
        d.tc.sendMessage("Runde " + lround + "!").queue();
    }
    d.round = lround;
    d.current = league.getLong("current");
    int x = 0;
    for (long mem : d.order.get(d.round)) {
        x++;
        if (d.current == mem)
            break;
    }
    if (x > 0) {
        d.order.get(d.round).subList(0, x).clear();
    }
    JSONObject pick = league.getJSONObject("picks");
    for (long mem : d.members) {
        if (pick.has(mem)) {
            JSONArray arr = pick.getJSONArrayL(mem);
            ArrayList<DraftPokemon> monlist = new ArrayList<>();
            for (Object ob : arr) {
                JSONObject obj = (JSONObject) ob;
                monlist.add(new DraftPokemon(obj.getString("name"), obj.getString("tier")));
            }
            d.picks.put(mem, monlist);
            d.update(mem);
        } else {
            d.picks.put(mem, new ArrayList<>());
        }
        if (d.isPointBased) {
            d.points.put(mem, d.getTierlist().points);
            for (DraftPokemon mon : d.picks.get(mem)) {
                d.points.put(mem, d.points.get(mem) - d.getTierlist().prices.get(mon.tier));
            }
        }
    }
    d.cooldown.cancel(false);
    d.cooldown = d.scheduler.schedule((Runnable) d::timer, calculateDraftTimer(), TimeUnit.MILLISECONDS);
    e.done();
}
Also used : Message(net.dv8tion.jda.api.entities.Message) TimeUnit(java.util.concurrent.TimeUnit) Command(de.tectoast.emolga.commands.Command) JSONObject(org.jsolf.JSONObject) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) JSONArray(org.jsolf.JSONArray) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Draft(de.tectoast.emolga.utils.draft.Draft) Optional(java.util.Optional) TextChannel(net.dv8tion.jda.api.entities.TextChannel) ArrayList(java.util.ArrayList) Message(net.dv8tion.jda.api.entities.Message) Command(de.tectoast.emolga.commands.Command) DraftPokemon(de.tectoast.emolga.utils.draft.DraftPokemon) JSONArray(org.jsolf.JSONArray) ArrayList(java.util.ArrayList) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Draft(de.tectoast.emolga.utils.draft.Draft) JSONObject(org.jsolf.JSONObject) JSONObject(org.jsolf.JSONObject)

Example 13 with GuildCommandEvent

use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.

the class AbilityCommand method process.

@Override
public void process(GuildCommandEvent e) {
    JSONObject json = getDataJSON(getModByGuild(e));
    ArrayList<String> mons = new ArrayList<>();
    String abi = e.getArguments().getTranslation("abi").getTranslation();
    for (String s : json.keySet()) {
        JSONObject data = json.getJSONObject(s);
        if (data.getInt("num") < 0)
            continue;
        if (data.getJSONObject("abilities").keySet().stream().map(string -> data.getJSONObject("abilities").getString(string)).anyMatch(string -> string.equalsIgnoreCase(abi))) {
            String name;
            if (s.equals("nidoranf"))
                name = "Nidoran-F";
            else if (s.equals("nidoranm"))
                name = "Nidoran-M";
            else {
                Translation gerName = getGerName(s);
                if (gerName.isSuccess())
                    name = gerName.getTranslation();
                else {
                    name = getGerNameNoCheck(data.getString("baseSpecies")) + "-" + data.getString("forme");
                }
            }
            mons.add(name);
        }
    }
    mons.removeIf(Objects::isNull);
    Collections.sort(mons);
    StringBuilder s = new StringBuilder();
    for (String mon : mons) {
        s.append(mon).append("\n");
        if (s.length() > 1900) {
            e.reply(new EmbedBuilder().setColor(Color.CYAN).setTitle(e.getArguments().getTranslation("abi").getOtherLang() + " haben:").setDescription(s).build());
            s = new StringBuilder();
        }
    }
    e.reply(new EmbedBuilder().setColor(Color.CYAN).setTitle(e.getArguments().getTranslation("abi").getOtherLang() + " haben:").setDescription(s).build());
/*
        try {
            tco.sendMessage(new EmbedBuilder().setColor(Color.CYAN).setTitle(eachWordUpperCase(msg.substring(9)) + " haben:").setDescription(String.join("\n", Jsoup.connect("https://www.pokewiki.de/" + msg.substring(9)).get().select("span[style=\"padding-left: 0.2em;\"]").stream().map(Element::text).collect(Collectors.toCollection(ArrayList::new)))).build()).queue();
        } catch (IOException e) {
            e.printStackTrace();
            tco.sendMessage("Es ist ein Fehler aufgetreten!").queue();
        }*/
}
Also used : java.awt(java.awt) Objects(java.util.Objects) Command(de.tectoast.emolga.commands.Command) JSONObject(org.jsolf.JSONObject) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Collections(java.util.Collections) ArrayList(java.util.ArrayList) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) JSONObject(org.jsolf.JSONObject) ArrayList(java.util.ArrayList) Objects(java.util.Objects)

Example 14 with GuildCommandEvent

use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.

the class HelpCommand method process.

@Override
public void process(GuildCommandEvent e) {
    String cmdname = e.getArguments().getText("cmd");
    Command c = Command.byName(cmdname);
    EmbedBuilder builder = new EmbedBuilder();
    builder.setTitle(c.getPrefix() + c.getName());
    builder.setColor(Color.CYAN);
    ArgumentManagerTemplate template = c.getArgumentTemplate();
    builder.setDescription(c.getHelpWithoutCmd(e.getGuild()));
    builder.addField("Syntax", "```" + (template.hasSyntax() ? template.getSyntax() : c.getPrefix() + c.getName() + " " + template.arguments.stream().map(a -> (a.isOptional() ? "[" : "<") + a.getName() + (a.isOptional() ? "]" : ">")).collect(Collectors.joining(" "))) + "```", false);
    for (ArgumentManagerTemplate.Argument a : template.arguments) {
        builder.addField(a.getName(), (a.isOptional() ? "(Optional)\n" : "") + a.getHelp(), true);
    }
    builder.setFooter("Aufgerufen von " + e.getAuthor().getAsTag());
    if (template.hasExample()) {
        builder.addField("Beispiel", "```" + template.getExample() + "```", false);
    }
    if (!c.getAliases().isEmpty()) {
        builder.addField("Aliases", "`" + String.join("`, `", c.getAliases()) + "`", false);
    }
    e.reply(builder.build());
}
Also used : java.awt(java.awt) Command(de.tectoast.emolga.commands.Command) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Command(de.tectoast.emolga.commands.Command)

Example 15 with GuildCommandEvent

use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.

the class GetIdsCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Message m = e.getMessage();
    TextChannel tco = e.getChannel();
    Member member = e.getMember();
    Role r = e.getJDA().getRoleById(e.getArguments().getID("role"));
    tco.getGuild().findMembers(mem -> mem.getRoles().contains(r)).onSuccess(members -> tco.sendMessage(members.stream().map(mem -> mem.getEffectiveName() + ": " + mem.getId()).collect(Collectors.joining("\n"))).queue()).onError(t -> {
        t.printStackTrace();
        tco.sendMessage("Es ist ein Fehler beim Laden der Member aufgetreten!").queue();
    });
}
Also used : Role(net.dv8tion.jda.api.entities.Role) Message(net.dv8tion.jda.api.entities.Message) Command(de.tectoast.emolga.commands.Command) Role(net.dv8tion.jda.api.entities.Role) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Collectors(java.util.stream.Collectors) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Message(net.dv8tion.jda.api.entities.Message) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

Command (de.tectoast.emolga.commands.Command)15 GuildCommandEvent (de.tectoast.emolga.commands.GuildCommandEvent)15 CommandCategory (de.tectoast.emolga.commands.CommandCategory)14 JSONObject (org.jsolf.JSONObject)8 TextChannel (net.dv8tion.jda.api.entities.TextChannel)7 Member (net.dv8tion.jda.api.entities.Member)6 Draft (de.tectoast.emolga.utils.draft.Draft)5 ArrayList (java.util.ArrayList)5 Comparator (java.util.Comparator)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 JSONArray (org.jsolf.JSONArray)4 Constants (de.tectoast.emolga.utils.Constants)3 java.awt (java.awt)3 Collections (java.util.Collections)3 LinkedList (java.util.LinkedList)3 Optional (java.util.Optional)3 TimeUnit (java.util.concurrent.TimeUnit)3 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 Message (net.dv8tion.jda.api.entities.Message)3