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();
}
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();
});
}
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);
}
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;
}
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"));
}
Aggregations