Search in sources :

Example 6 with GuildCommandEvent

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

the class RandomPickCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Member memberr = e.getMember();
    long member = memberr.getIdLong();
    TextChannel tco = e.getChannel();
    Draft d = Draft.getDraftByMember(member, tco);
    if (d == null) {
        e.getChannel().sendMessage("Du Kek der Command funktioniert nur in einem Draft xD").queue();
        return;
    }
    String msg = e.getMessage().getContentDisplay();
    Tierlist tierlist = d.getTierlist();
    ArgumentManager args = e.getArguments();
    String tier = tierlist.order.stream().filter(s -> args.getText("tier").equalsIgnoreCase(s)).findFirst().orElse("");
    if (tier.equals("")) {
        tco.sendMessage("Das ist kein Tier!").queue();
        return;
    }
    if (!d.tc.getId().equals(tco.getId()))
        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(d.name);
    /*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;*/
    ArrayList<String> list = new ArrayList<>(tierlist.tierlist.get(tier));
    Collections.shuffle(list);
    Predicate<String> typecheck;
    if (args.has("type")) {
        Translation type = args.getTranslation("type");
        typecheck = str -> getDataJSON().getJSONObject(getSDName(str)).getJSONArray("types").toList().contains(type.getTranslation());
    } else {
        typecheck = str -> true;
    }
    PickCommand.exec(tco, "!pick " + list.stream().filter(str -> !d.isPicked(str) && !d.hasInAnotherForm(mem, str) && (!d.hasMega(mem) || !str.startsWith("M-")) && typecheck.test(str)).map(String::trim).findFirst().orElse(""), memberr, true);
}
Also used : Command(de.tectoast.emolga.commands.Command) JSONObject(org.jsolf.JSONObject) Predicate(java.util.function.Predicate) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Draft(de.tectoast.emolga.utils.draft.Draft) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Tierlist(de.tectoast.emolga.utils.draft.Tierlist) ArrayList(java.util.ArrayList) 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 7 with GuildCommandEvent

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

the class ShowdownPokeFansCommand method process.

@Override
public void process(GuildCommandEvent e) {
    JSONArray tosend = new JSONArray();
    // for (String id : ids) {
    String paste = e.getArguments().getText("paste");
    JSONArray oneUser = new JSONArray();
    oneUser.put("HierDenNamenÄndern");
    oneUser.put("HierDieLigaÄndern");
    List<String> pmons = new LinkedList<>();
    for (String s : paste.split("\n")) {
        if (s.trim().length() == 0)
            continue;
        if (s.contains(":") && !s.contains("Type: Null"))
            continue;
        logger.info("s = " + s);
        pmons.add(s.trim());
    }
    JSONArray mons = new JSONArray();
    logger.info("pmons = " + pmons);
    pmons.stream().sorted(Comparator.comparing(str -> getDataJSON().getJSONObject(toSDName((String) str)).getJSONObject("baseStats").getInt("spe")).reversed()).map(s -> {
        String[] split = s.split("-");
        return getGerNameNoCheck(split[0]) + (split.length > 1 ? "-" + split[1] : "");
    }).map(str -> str.replace("Boreos-T", "Boreos Tiergeistform").replace("Voltolos-T", "Voltolos Tiergeistform").replace("Demeteros-T", "Demeteros Tiergeistform").replace("Boreos-I", "Boreos Inkarnationsform").replace("Voltolos-I", "Voltolos Inkarnationsform").replace("Demeteros-I", "Demeteros Inkarnationsform").replace("Wolwerock-Tag", "Wolwerock Tagform").replace("Wolwerock-Nacht", "Wolwerock Nachtform").replace("Wolwerock-Zw", "Wolwerock Zwielichtform").replace("Shaymin", "Shaymin Landform").replace("Durengard", "Durengard Schildform").replace("Pumpdjinn", "Pumpdjinn XL").replace("M-", "Mega-").replace("A-", "Alola-").replace("G-", "Galar-")).forEach(mons::put);
    oneUser.put(mons);
    tosend.put(oneUser);
    // }
    e.reply(tosend.toString());
}
Also used : Command(de.tectoast.emolga.commands.Command) List(java.util.List) Logger(org.slf4j.Logger) JSONArray(org.jsolf.JSONArray) Constants(de.tectoast.emolga.utils.Constants) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) LoggerFactory(org.slf4j.LoggerFactory) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) JSONArray(org.jsolf.JSONArray) LinkedList(java.util.LinkedList)

Example 8 with GuildCommandEvent

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

the class FinishDraftCommand 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.isNotCurrent(member)) {
        tco.sendMessage(d.getMention(member) + " Du bist nicht dran!").queue();
        return;
    }
    long mem = d.current;
    int round = d.round;
    if (e.getGuild().getIdLong() == Constants.NDSID && d.picks.get(mem).size() < 15) {
        e.reply("Du hast noch keine 15 Pokemon!");
        return;
    }
    /*if (round < 12) {
            e.reply("Du hast noch nicht 11 Pokemon!");
            return;
        }*/
    e.reply("Du hast den Draft für dich beendet!");
    d.order.values().forEach(l -> l.removeIf(me -> me == mem));
    league.put("finished", league.optString("finished") + mem + ",");
    d.cooldown.cancel(false);
    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);
            saveEmolgaJSON();
            Draft.drafts.remove(d);
            return;
        }
        d.round++;
        if (d.order.get(d.round).size() == 0) {
            e.reply("Da alle bereits ihre Drafts beendet haben, ist der Draft vorbei!");
            saveEmolgaJSON();
            return;
        }
        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);
    d.cooldown.cancel(false);
    league.getJSONObject("picks").put(d.current, d.getTeamAsArray(d.current));
    if (d.isPointBased)
        // tco.sendMessage(getMention(current) + " (<@&" + asl.getLongList("roleids").get(getIndex(current.getIdLong())) + ">) ist dran! (" + points.get(current.getIdLong()) + " mögliche Punkte)").queue();
        tco.sendMessage(d.getMention(d.current) + " ist dran! (" + d.points.get(d.current) + " mögliche Punkte)").queue();
    else
        tco.sendMessage(d.getMention(d.current) + " ist dran! (Mögliche Tiers: " + d.getPossibleTiersAsString(d.current) + ")").queue();
    long delay = calculateDraftTimer();
    league.put("cooldown", System.currentTimeMillis() + delay);
    d.cooldown = d.scheduler.schedule((Runnable) d::timer, delay, TimeUnit.MILLISECONDS);
    saveEmolgaJSON();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Command(de.tectoast.emolga.commands.Command) JSONObject(org.jsolf.JSONObject) Constants(de.tectoast.emolga.utils.Constants) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Draft(de.tectoast.emolga.utils.draft.Draft) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) 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 9 with GuildCommandEvent

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

the class SlashListener method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent e) {
    Command command = Command.byName(e.getName());
    User u = e.getUser();
    TextChannel tco = e.getTextChannel();
    try {
        new GuildCommandEvent(command, e);
    } catch (Command.MissingArgumentException ex) {
        Command.ArgumentManagerTemplate.Argument arg = ex.getArgument();
        if (arg.hasCustomErrorMessage())
            e.reply(arg.getCustomErrorMessage()).queue();
        else {
            e.reply("Das benötigte Argument `" + arg.getName() + "`, was eigentlich " + buildEnumeration(arg.getType().getName()) + " sein müsste, ist nicht vorhanden!\n" + "Nähere Informationen über die richtige Syntax für den Command erhältst du unter `e!help " + command.getName() + "`.").queue();
        }
        if (u.getIdLong() != FLOID) {
            sendToMe("MissingArgument " + tco.getAsMention() + " Server: " + tco.getGuild().getName());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        e.getHook().sendMessage("Es ist ein Fehler beim Ausführen des Commands aufgetreten!\nWenn du denkst, dass dies ein interner Fehler beim Bot ist, melde dich bitte bei Flo/TecToast.\n" + command.getHelp(e.getGuild()) + (u.getIdLong() == FLOID ? "\nJa Flo, du sollst dich auch bei ihm melden du Kek! :^)" : "")).queue();
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) User(net.dv8tion.jda.api.entities.User) Command(de.tectoast.emolga.commands.Command) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent)

Example 10 with GuildCommandEvent

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

the class ListmembersCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Message m = e.getMessage();
    TextChannel tco = e.getChannel();
    Member member = e.getMember();
    ArgumentManager args = e.getArguments();
    Role r = e.getJDA().getRoleById(args.getID("role"));
    /*if (m.getMentionedRoles().size() == 0) {
            if (m.getContentDisplay().split(" ").length == 2) {
                try {
                    r = e.getGuild().getRoleById(m.getContentDisplay().split(" ")[1]);
                } catch (Exception ex) {
                    tco.sendMessage(member.getAsMention() + " Du musst eine Rolle angeben!").queue();
                    return;
                }
            } else {
                tco.sendMessage(member.getAsMention() + " Du musst eine Rolle angeben!").queue();
                return;
            }
        } else
            r = m.getMentionedRoles().get(0);*/
    tco.getGuild().findMembers(mem -> mem.getRoles().contains(r)).onSuccess(members -> {
        StringBuilder s = new StringBuilder();
        for (Member mem : members) {
            s.append(mem.getEffectiveName()).append("\n");
        }
        if (s.toString().equals("")) {
            tco.sendMessage("Kein Member hat die Rolle " + r.getName() + "!").queue();
            return;
        }
        s.append("Insgesamt: ").append(members.size());
        tco.sendMessage("User mit der Rolle " + r.getName() + ":\n" + s).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) 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