Search in sources :

Example 1 with GuildCommandEvent

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

the class RandomizeKillsCommand method process.

@Override
public void process(GuildCommandEvent e) {
    List<Integer> l = new LinkedList<>();
    Random r = new Random();
    for (int i = 0; i < 6; i++) {
        int rand = r.nextInt(6) + 1;
        int sum = l.stream().mapToInt(x -> x).sum();
        if (sum + rand > 6)
            rand = 6 - sum;
        l.add(rand);
    }
    Collections.shuffle(l);
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < l.size(); i++) {
        b.append("Pokemon ").append(i + 1).append(": ").append(l.get(i)).append("\n");
    }
    e.reply(b.toString());
}
Also used : Command(de.tectoast.emolga.commands.Command) List(java.util.List) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) Random(java.util.Random) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Random(java.util.Random) LinkedList(java.util.LinkedList)

Example 2 with GuildCommandEvent

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

the class NaturalGiftCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Translation t = e.getArguments().getTranslation("stuff");
    String translation = t.getTranslation();
    if (t.isFromType(Translation.Type.ITEM)) {
        NGData ngData = DBManagers.NATURAL_GIFT.fromName(translation);
        e.reply(new EmbedBuilder().setTitle(translation).addField("Typ", ngData.type(), false).addField("Basepower", String.valueOf(ngData.bp()), false).setColor(Color.CYAN).build());
    } else {
        List<NGData> ngData = DBManagers.NATURAL_GIFT.fromType(translation);
        e.reply(new EmbedBuilder().setTitle(translation).setDescription(ngData.stream().sorted(Comparator.comparing(NGData::bp)).map(d -> d.name() + "/" + getEnglName(d.name()) + ": " + d.bp()).collect(Collectors.joining("\n"))).setColor(Color.CYAN).build());
    }
}
Also used : java.awt(java.awt) Command(de.tectoast.emolga.commands.Command) List(java.util.List) NGData(de.tectoast.emolga.utils.records.NGData) GuildCommandEvent(de.tectoast.emolga.commands.GuildCommandEvent) CommandCategory(de.tectoast.emolga.commands.CommandCategory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) DBManagers(de.tectoast.emolga.utils.sql.DBManagers) NGData(de.tectoast.emolga.utils.records.NGData) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Example 3 with GuildCommandEvent

use of de.tectoast.emolga.commands.GuildCommandEvent 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 4 with GuildCommandEvent

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

the class AllowCommand method process.

@Override
public void process(GuildCommandEvent e) {
    JSONObject drafts = getEmolgaJSON().getJSONObject("drafts");
    Member member = e.getMember();
    Optional<JSONObject> op = drafts.keySet().stream().map(drafts::getJSONObject).filter(o -> o.has("guild")).filter(o -> o.getString("guild").equals(e.getGuild().getId())).filter(o -> o.has("table")).filter(o -> o.getLongList("table").contains(member.getIdLong())).findFirst();
    if (op.isPresent()) {
        Member mem = e.getArguments().getMember("user");
        long user = mem.getIdLong();
        JSONObject league = op.get();
        if (!league.has("allowed"))
            league.put("allowed", new JSONObject());
        JSONObject allowed = league.getJSONObject("allowed");
        if (allowed.has(user)) {
            e.reply("%s pickt bereits für `%s`!".formatted(mem.getEffectiveName(), e.getGuild().retrieveMemberById(allowed.getLongL(user)).complete().getEffectiveName()));
            return;
        }
        allowed.put(user, member.getIdLong());
        e.reply("Du hast %s erlaubt, für dich zu picken!".formatted(mem.getEffectiveName()));
        saveEmolgaJSON();
    } else {
        e.reply("Du nimmst nicht an einer Liga auf diesem Server teil!");
    }
}
Also used : 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) Optional(java.util.Optional) Member(net.dv8tion.jda.api.entities.Member) JSONObject(org.jsolf.JSONObject) Member(net.dv8tion.jda.api.entities.Member)

Example 5 with GuildCommandEvent

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

the class PokeFansExportCommand method process.

@Override
public void process(GuildCommandEvent e) {
    JSONObject league = Draft.getLeagueStatic(e.getArguments().getText("draft"));
    JSONObject picksObj = league.getJSONObject("picks");
    JSONArray tosend = new JSONArray();
    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();
        oneUser.put(names.get(id).replaceAll("[^A-Za-z\\s]", ""));
        oneUser.put(e.getArg(0));
        JSONArray mons = new JSONArray();
        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 -> 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);
        if (tosend.toString().length() > 1500) {
            e.reply(tosend.toString());
            tosend.clear();
        }
    }
    e.reply(tosend.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) Draft(de.tectoast.emolga.utils.draft.Draft) 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) JSONArray(org.jsolf.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.jsolf.JSONObject)

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