use of org.jsolf.JSONObject in project Emolga by TecToast.
the class NicknameCommand method process.
@Override
public void process(GuildCommandEvent e) {
TextChannel tco = e.getChannel();
Message m = e.getMessage();
String msg = m.getContentDisplay();
Member member = e.getMember();
String nickname = msg.substring(10);
if (!e.getGuild().getSelfMember().canInteract(member)) {
tco.sendMessage("Ich kann deinen Nickname nicht modifizieren!").queue();
return;
}
if (nickname.length() > 32) {
tco.sendMessage("Dieser Nickname ist zu lang! (Er darf maximal 32 Zeichen enthalten)").queue();
return;
}
try {
JSONObject json = getEmolgaJSON();
Guild g = tco.getGuild();
if (!json.has("cooldowns"))
json.put("cooldowns", new JSONObject());
if (!json.getJSONObject("cooldowns").has(g.getId()))
json.getJSONObject("cooldowns").put(g.getId(), new JSONObject());
if (json.getJSONObject("cooldowns").getJSONObject(g.getId()).has(member.getId())) {
long l = Long.parseLong(json.getJSONObject("cooldowns").getJSONObject(g.getId()).getString(member.getId()));
long untilnow = System.currentTimeMillis() - l;
if (untilnow < 604800000) {
long delay = 604800000 - untilnow;
int days = (int) (delay / 86400000);
delay -= days * 86400000L;
int hours = (int) (delay / 3600000);
delay -= hours * 3600000L;
int minutes = (int) (delay / 60000);
tco.sendMessage(member.getAsMention() + " Du kannst deinen Namen noch nicht wieder ändern!\nCooldown: " + days + "d " + hours + "h " + minutes + "m").queue();
return;
}
}
String oldname = member.getEffectiveName();
member.modifyNickname(nickname).complete();
if (g.getId().equals("518008523653775366"))
EmolgaMain.emolgajda.getGuildById("518008523653775366").getTextChannelById("728675253924003870").sendMessage(oldname + " hat sich in " + nickname + " umbenannt!").queue();
tco.sendMessage(member.getAsMention() + " Dein Nickname wurde erfolgreich geändert!").queue();
json.getJSONObject("cooldowns").getJSONObject(g.getId()).put(member.getId(), Long.toString(System.currentTimeMillis()));
saveEmolgaJSON();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.jsolf.JSONObject 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.JSONObject 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.JSONObject in project Emolga by TecToast.
the class Draft method doNDSNominate.
public static void doNDSNominate() {
JSONObject nds = getEmolgaJSON().getJSONObject("drafts").getJSONObject("NDS");
JSONObject nom = nds.getJSONObject("nominations");
int cday = nom.getInt("currentDay");
JSONObject o = nom.getJSONObject(String.valueOf(cday));
JSONObject picks = nds.getJSONObject("picks");
String sid = nds.getString("sid");
RequestBuilder builder = new RequestBuilder(sid);
RequestGetter getter = new RequestGetter(sid);
List<List<List<Object>>> get = new LinkedList<>();
int temp = 0;
for (String s : picks.keySet()) {
logger.info(MarkerFactory.getMarker("important"), "{} {}", temp, s);
get.add(Google.get(sid, nds.getJSONObject("teamnames").getString(s) + "!B15:O29", true, false));
temp++;
}
int x = 0;
for (String u : picks.keySet()) {
// String u = "297010892678234114";
if (!o.has(u)) {
if (cday == 1) {
List<JSONObject> mons = picks.getJSONList(u);
o.put(u, mons.stream().limit(11).map(obj -> obj.getString("name")).collect(Collectors.joining(";")) + "###" + mons.stream().skip(11).map(obj -> obj.getString("name")).collect(Collectors.joining(";")));
} else {
o.put(u, nom.getJSONObject(String.valueOf(cday - 1)).getString(u));
}
}
// logger.info("o.get(u) = " + o.get(u));
String str = o.getString(u);
List<String> mons = Arrays.stream(str.split("###")).flatMap(s -> Arrays.stream(s.split(";"))).toList();
logger.info("mons = " + mons);
String range = nds.getJSONObject("teamnames").getString(u) + "!B15:O29";
logger.info("u = " + u);
logger.info("range = " + range);
builder.addAll(range, get.get(x).stream().filter(n -> !n.get(2).equals("")).sorted(Comparator.comparing(n -> {
String s1 = (String) n.get(2);
logger.info("s1 = " + s1);
int ret = mons.indexOf(s1);
logger.info("ret = " + ret);
return ret;
})).collect(Collectors.toList()));
x++;
}
builder.execute();
nom.increment("currentDay");
saveEmolgaJSON();
}
use of org.jsolf.JSONObject 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);
}
Aggregations