Search in sources :

Example 6 with JSONObject

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

the class Draft method getLeague.

public JSONObject getLeague() {
    JSONObject drafts = getEmolgaJSON().getJSONObject("drafts");
    Pattern aslpattern = Pattern.compile("^S\\d");
    return aslpattern.matcher(name).find() ? drafts.getJSONObject("ASLS9").getJSONObject(name) : drafts.getJSONObject(name);
}
Also used : Pattern(java.util.regex.Pattern) JSONObject(org.jsolf.JSONObject)

Example 7 with JSONObject

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

the class Draft method getTeamMembers.

public static List<Long> getTeamMembers(long userid) {
    JSONObject asl = getEmolgaJSON().getJSONObject("drafts").getJSONObject("ASLS9");
    int index = getIndex(userid);
    LinkedList<Long> l = new LinkedList<>();
    if (index == -1)
        return l;
    for (int i = 1; i <= 4; i++) {
        l.add(asl.getJSONObject("S" + i).getLongList("table").get(index));
    }
    return l;
}
Also used : JSONObject(org.jsolf.JSONObject)

Example 8 with JSONObject

use of org.jsolf.JSONObject 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 9 with JSONObject

use of org.jsolf.JSONObject 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)

Example 10 with JSONObject

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

the class Database method init.

public static void init() {
    JSONObject cred = Command.tokens.getJSONObject("database");
    instance = new Database(cred.getString("username"), cred.getString("password"));
}
Also used : JSONObject(org.jsolf.JSONObject)

Aggregations

JSONObject (org.jsolf.JSONObject)72 TextChannel (net.dv8tion.jda.api.entities.TextChannel)23 Member (net.dv8tion.jda.api.entities.Member)20 Command (de.tectoast.emolga.commands.Command)19 JSONArray (org.jsolf.JSONArray)19 RequestBuilder (de.tectoast.emolga.utils.RequestBuilder)16 CommandCategory (de.tectoast.emolga.commands.CommandCategory)15 GuildCommandEvent (de.tectoast.emolga.commands.GuildCommandEvent)15 Draft (de.tectoast.emolga.utils.draft.Draft)14 Guild (net.dv8tion.jda.api.entities.Guild)13 DraftPokemon (de.tectoast.emolga.utils.draft.DraftPokemon)12 Collectors (java.util.stream.Collectors)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tierlist (de.tectoast.emolga.utils.draft.Tierlist)10 Coord (de.tectoast.emolga.utils.records.Coord)9 Draft.getIndex (de.tectoast.emolga.utils.draft.Draft.getIndex)8 ResultSet (java.sql.ResultSet)8 java.util (java.util)8 ArrayList (java.util.ArrayList)7