Search in sources :

Example 1 with JSONArray

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

the class ResetRevolutionCommand method process.

@Override
public void process(GuildCommandEvent e) {
    Guild g = e.getGuild();
    e.getChannel().sendMessage("Die **Diktatur** ist zu Ende D:").queue();
    JSONObject o = getEmolgaJSON().getJSONObject("revolutionreset").getJSONObject(g.getId());
    for (String s : o.keySet()) {
        g.retrieveMemberById(s).submit().thenCompose(mem -> mem.modifyNickname(o.getString(s)).submit());
    }
    for (GuildChannel gc : g.getChannels()) {
        gc.getManager().setName(gc.getName().replaceFirst("(.*)-", "")).queue();
    }
    g.getSelfMember().modifyNickname("Emolga").queue();
    JSONArray arr = getEmolgaJSON().getJSONArray("activerevolutions");
    arr.remove(arr.toList().indexOf(g.getIdLong()));
    saveEmolgaJSON();
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) JSONObject(org.jsolf.JSONObject) JSONArray(org.jsolf.JSONArray) Guild(net.dv8tion.jda.api.entities.Guild)

Example 2 with JSONArray

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

the class RevolutionCommand method process.

@Override
public void process(GuildCommandEvent e) {
    if (e.getArgsLength() == 0) {
        e.reply("Du musst einen Revolution-Namen angeben!");
        return;
    }
    String name = e.getArg(0);
    Guild g = e.getGuild();
    JSONArray arr = getEmolgaJSON().getJSONArray("activerevolutions");
    boolean isRevo = arr.toList().contains(g.getIdLong());
    JSONObject o = new JSONObject();
    e.getChannel().sendMessage("Möge die **" + name + "-Revolution** beginnen! :D").queue();
    g.loadMembers().onSuccess(list -> {
        for (Member member : list) {
            if (member.isOwner())
                continue;
            if (member.getId().equals(e.getJDA().getSelfUser().getId()))
                member.modifyNickname(name + "leader").queue();
            if (!g.getSelfMember().canInteract(member))
                continue;
            if (!isRevo)
                o.put(member.getId(), member.getEffectiveName());
            member.modifyNickname(name).queue();
        }
        for (GuildChannel gc : g.getChannels()) {
            gc.getManager().setName((gc.getType() == ChannelType.TEXT ? name.toLowerCase() : name) + "-" + gc.getName()).queue();
        }
        if (!isRevo) {
            getEmolgaJSON().getJSONObject("revolutionreset").put(g.getId(), o);
            arr.put(g.getIdLong());
        }
        saveEmolgaJSON();
    });
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) JSONObject(org.jsolf.JSONObject) JSONArray(org.jsolf.JSONArray) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member)

Example 3 with JSONArray

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

the class Draft method timer.

public void timer(TimerReason tr) {
    if (ended)
        return;
    JSONObject drafts = getEmolgaJSON().getJSONObject("drafts");
    JSONObject league = drafts.getJSONObject(name);
    if (!league.has("skippedturns"))
        league.put("skippedturns", new JSONObject());
    JSONObject st = league.getJSONObject("skippedturns");
    int rounds = getTierlist().rounds;
    st.put(current, st.optJSONArray(String.valueOf(current), new JSONArray()).put(round));
    if (order.get(round).size() == 0) {
        if (round == rounds) {
            saveEmolgaJSON();
            tc.sendMessage("Der Draft ist vorbei!").queue();
            Draft.drafts.remove(this);
            return;
        }
        round++;
        tc.sendMessage("Runde " + round + "!").queue();
    }
    /*String msg = tr == TimerReason.REALTIMER ? "**" + current.getEffectiveName() + "** war zu langsam und deshalb ist jetzt " + getMention(order.get(round).get(0)) + " (<@&" + asl.getLongList("roleids").get(getIndex(order.get(round).get(0).getIdLong())) + ">) dran! "
                : "Der Pick von " + current.getEffectiveName() + " wurde " + (isSwitchDraft ? "geskippt" : "verschoben") + " und deshalb ist jetzt " + getMention(order.get(round).get(0)) + " dran!";*/
    String msg = tr == TimerReason.REALTIMER ? "**<@" + current + ">** war zu langsam und deshalb ist jetzt " + getMention(order.get(round).get(0)) + " dran! " : "Der Pick von <@" + current + "> wurde " + (isSwitchDraft ? "geskippt" : "verschoben") + " und deshalb ist jetzt " + getMention(order.get(round).get(0)) + " dran!";
    current = order.get(round).remove(0);
    league.put("current", current);
    if (isPointBased)
        msg += "(" + points.get(current) + " mögliche Punkte)";
    else
        msg += "(Mögliche Tiers: " + getPossibleTiersAsString(current) + ")";
    tc.sendMessage(msg).queue();
    cooldown.cancel(false);
    long delay = calculateDraftTimer();
    league.put("cooldown", System.currentTimeMillis() + delay);
    saveEmolgaJSON();
    cooldown = scheduler.schedule((Runnable) this::timer, delay, TimeUnit.MILLISECONDS);
}
Also used : JSONObject(org.jsolf.JSONObject) JSONArray(org.jsolf.JSONArray)

Example 4 with JSONArray

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

the class Draft method getTeamAsArray.

public JSONArray getTeamAsArray(long mem) {
    JSONArray arr = new JSONArray();
    for (DraftPokemon mon : picks.get(mem)) {
        JSONObject obj = new JSONObject();
        obj.put("name", mon.name);
        obj.put("tier", mon.tier);
        arr.put(obj);
    }
    return arr;
}
Also used : JSONObject(org.jsolf.JSONObject) JSONArray(org.jsolf.JSONArray)

Example 5 with JSONArray

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

the class BanManager method getBans.

public JSONArray getBans(Guild g) {
    try {
        ResultSet set = GUILDID.getAll(g.getIdLong());
        JSONArray arr = new JSONArray();
        List<JSONObject> l = new LinkedList<>();
        while (set.next()) {
            l.add(new JSONObject().put("userid", USERID.getValue(set)).put("username", USERNAME.getValue(set)).put("modid", MODID.getValue(set)).put("reason", REASON.getValue(set)).put("timestamp", TIMESTAMP.getValue(set).getTime()));
        }
        Set<Long> idstocheck = new HashSet<>();
        l.stream().map(j -> j.getLong("modid")).forEach(idstocheck::add);
        HashMap<Long, String> names = new HashMap<>();
        g.retrieveMembersByIds(idstocheck).get().forEach(mem -> names.put(mem.getIdLong(), mem.getEffectiveName()));
        for (JSONObject j : l) {
            long uid = j.getLong("userid");
            arr.put(new JSONObject().put("name", j.getString("username")).put("id", String.valueOf(uid)).put("reason", j.getString("reason")).put("mod", names.get(j.getLong("modid"))).put("timestamp", j.getLong("timestamp")));
        }
        return arr;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new JSONArray().put(new JSONObject().put("name", "ERROR"));
}
Also used : JSONObject(org.jsolf.JSONObject) java.util(java.util) Logger(org.slf4j.Logger) Timestamp(java.sql.Timestamp) LoggerFactory(org.slf4j.LoggerFactory) Condition.and(de.tectoast.emolga.utils.sql.base.Condition.and) TimestampColumn(de.tectoast.emolga.utils.sql.base.columns.TimestampColumn) DataManager(de.tectoast.emolga.utils.sql.base.DataManager) Guild(net.dv8tion.jda.api.entities.Guild) LongColumn(de.tectoast.emolga.utils.sql.base.columns.LongColumn) JSONArray(org.jsolf.JSONArray) StringColumn(de.tectoast.emolga.utils.sql.base.columns.StringColumn) ResultSet(java.sql.ResultSet) Nullable(javax.annotation.Nullable) JSONArray(org.jsolf.JSONArray) JSONObject(org.jsolf.JSONObject) ResultSet(java.sql.ResultSet)

Aggregations

JSONArray (org.jsolf.JSONArray)18 JSONObject (org.jsolf.JSONObject)17 Command (de.tectoast.emolga.commands.Command)5 TextChannel (net.dv8tion.jda.api.entities.TextChannel)5 CommandCategory (de.tectoast.emolga.commands.CommandCategory)4 GuildCommandEvent (de.tectoast.emolga.commands.GuildCommandEvent)4 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)4 Guild (net.dv8tion.jda.api.entities.Guild)4 Draft (de.tectoast.emolga.utils.draft.Draft)3 ResultSet (java.sql.ResultSet)3 Member (net.dv8tion.jda.api.entities.Member)3 EmolgaMain.emolgajda (de.tectoast.emolga.bot.EmolgaMain.emolgajda)2 DataManager (de.tectoast.emolga.utils.sql.base.DataManager)2 LongColumn (de.tectoast.emolga.utils.sql.base.columns.LongColumn)2 StringColumn (de.tectoast.emolga.utils.sql.base.columns.StringColumn)2 TimestampColumn (de.tectoast.emolga.utils.sql.base.columns.TimestampColumn)2 File (java.io.File)2 java.util (java.util)2 HashMap (java.util.HashMap)2