use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.
the class SwitchCommand method process.
@Override
public void process(GuildCommandEvent e) {
String msg = e.getMsg();
TextChannel tco = e.getChannel();
Member memberr = e.getMember();
long member = memberr.getIdLong();
Draft d = Draft.getDraftByMember(member, tco);
if (d == null) {
tco.sendMessage(memberr.getAsMention() + " Du bist in keinem Draft drin!").queue();
return;
}
if (!d.tc.getId().equals(tco.getId()))
return;
if (!d.isSwitchDraft) {
e.reply("Dieser Draft ist kein Switch-Draft, daher wird !switch nicht unterstützt!");
return;
}
if (msg.equals("!switch")) {
e.reply("Willst du vielleicht noch zwei Pokemon dahinter schreiben? xD");
return;
}
if (d.isNotCurrent(member)) {
tco.sendMessage(d.getMention(member) + " Du bist nicht dran!").queue();
return;
}
long mem = d.current;
JSONObject json = getEmolgaJSON();
JSONObject league = json.getJSONObject("drafts").getJSONObject(d.name);
// JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject("ZBSL2");
/*if (asl.has("allowed")) {
JSONObject allowed = asl.getJSONObject("allowed");
if (allowed.has(member.getId())) {
mem = d.tc.getGuild().retrieveMemberById(allowed.getString(member.getId())).complete();
} else mem = member;
} else mem = member;*/
Translation t;
ArgumentManager args = e.getArguments();
String oldmon = args.getText("oldmon");
String newmon = args.getText("newmon");
Tierlist tierlist = d.getTierlist();
if (!d.isPickedBy(oldmon, mem)) {
e.reply(memberr.getAsMention() + " " + oldmon + " befindet sich nicht in deinem Kader!");
return;
}
if (d.isPicked(newmon)) {
e.reply(memberr.getAsMention() + " " + newmon + " wurde bereits gepickt!");
return;
}
int pointsBack = tierlist.getPointsNeeded(oldmon);
if (pointsBack == -1) {
e.reply("Das, was du rauswerfen möchtest, steht nicht in der Tierliste!");
return;
}
logger.info("oldmon = " + oldmon);
logger.info("newmon = " + newmon);
int newpoints = tierlist.getPointsNeeded(newmon);
if (newpoints == -1) {
e.reply("Das, was du haben möchtest, steht nicht in der Tierliste!");
return;
}
String tier = tierlist.getTierOf(newmon);
d.points.put(mem, d.points.get(mem) + pointsBack);
if (d.points.get(mem) - newpoints < 0) {
d.points.put(mem, d.points.get(mem) - pointsBack);
e.reply(memberr.getAsMention() + " Du kannst dir " + newmon + " nicht leisten!");
return;
}
d.points.put(mem, d.points.get(mem) - newpoints);
DraftPokemon oldMon = d.picks.get(mem).stream().filter(draftMon -> draftMon.name.equalsIgnoreCase(oldmon)).map(DraftPokemon::copy).findFirst().orElse(null);
Optional<DraftPokemon> drp = d.picks.get(mem).stream().filter(dp -> dp.name.equalsIgnoreCase(oldmon)).findFirst();
if (drp.isEmpty()) {
logger.error("DRP NULL LINE 232");
return;
}
DraftPokemon dp = drp.get();
dp.setName(newmon);
dp.setTier(tierlist.getTierOf(newmon));
// m.delete().queue();
d.update(mem);
// fpldoc(tierlist, newmon, d, mem, newpoints, new DraftPokemon(oldmon, tierlist.getTierOf(oldmon)));
// fpldoc(tierlist, newmon, d, mem, tier, d.members.size() - d.order.get(d.round).size(), d.round, oldmon);
ndsdoc(tierlist, d, mem, oldMon, dp);
league.getJSONObject("picks").put(d.current, d.getTeamAsArray(d.current));
if (newmon.equals("Emolga")) {
tco.sendMessage("<:Happy:701070356386938991> <:Happy:701070356386938991> <:Happy:701070356386938991> <:Happy:701070356386938991> <:Happy:701070356386938991>").queue();
}
d.cooldown.cancel(false);
int round = d.round;
if (d.order.get(d.round).size() == 0) {
if (d.round == tierlist.rounds) {
tco.sendMessage("Der Draft ist vorbei!").queue();
d.ended = true;
// wooloodoc(tierlist, pokemon, d, mem, needed, null, num, round);
if (d.afterDraft.size() > 0)
tco.sendMessage("Reihenfolge zum Nachdraften:\n" + d.afterDraft.stream().map(d::getMention).collect(Collectors.joining("\n"))).queue();
saveEmolgaJSON();
Draft.drafts.remove(d);
return;
}
d.round++;
d.tc.sendMessage("Runde " + d.round + "!").queue();
league.put("round", d.round);
}
d.current = d.order.get(d.round).remove(0);
league.put("current", d.current);
JSONObject drafts = getEmolgaJSON().getJSONObject("drafts");
tco.sendMessage(d.getMention(d.current) + " ist dran! (" + d.points.get(d.current) + " mögliche Punkte)").queue();
// tco.sendMessage(d.getMention(d.current) + " ist dran! (" + d.points.get(d.current.getIdLong()) + " mögliche Punkte)").queue();
long delay = calculateDraftTimer();
league.put("cooldown", System.currentTimeMillis() + delay);
d.cooldown = d.scheduler.schedule((Runnable) d::timer, delay, TimeUnit.MILLISECONDS);
saveEmolgaJSON();
}
use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.
the class UpdatedatafromfileCommand method process.
@Override
public void process(GuildCommandEvent e) {
TextChannel tco = e.getChannel();
Message m = e.getMessage();
String msg = m.getContentDisplay();
String name = e.getArguments().getText("name");
Optional<Draft> op = Draft.drafts.stream().filter(d -> d.name.equals(name)).findFirst();
if (op.isEmpty()) {
tco.sendMessage("Dieser Draft existiert nicht!").queue();
return;
}
Draft d = op.get();
JSONObject league = getEmolgaJSON().getJSONObject("drafts").getJSONObject(name);
int lround = league.getInt("round");
if (d.round != lround) {
d.tc.sendMessage("Runde " + lround + "!").queue();
}
d.round = lround;
d.current = league.getLong("current");
int x = 0;
for (long mem : d.order.get(d.round)) {
x++;
if (d.current == mem)
break;
}
if (x > 0) {
d.order.get(d.round).subList(0, x).clear();
}
JSONObject pick = league.getJSONObject("picks");
for (long mem : d.members) {
if (pick.has(mem)) {
JSONArray arr = pick.getJSONArrayL(mem);
ArrayList<DraftPokemon> monlist = new ArrayList<>();
for (Object ob : arr) {
JSONObject obj = (JSONObject) ob;
monlist.add(new DraftPokemon(obj.getString("name"), obj.getString("tier")));
}
d.picks.put(mem, monlist);
d.update(mem);
} else {
d.picks.put(mem, new ArrayList<>());
}
if (d.isPointBased) {
d.points.put(mem, d.getTierlist().points);
for (DraftPokemon mon : d.picks.get(mem)) {
d.points.put(mem, d.points.get(mem) - d.getTierlist().prices.get(mon.tier));
}
}
}
d.cooldown.cancel(false);
d.cooldown = d.scheduler.schedule((Runnable) d::timer, calculateDraftTimer(), TimeUnit.MILLISECONDS);
e.done();
}
use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.
the class AbilityCommand method process.
@Override
public void process(GuildCommandEvent e) {
JSONObject json = getDataJSON(getModByGuild(e));
ArrayList<String> mons = new ArrayList<>();
String abi = e.getArguments().getTranslation("abi").getTranslation();
for (String s : json.keySet()) {
JSONObject data = json.getJSONObject(s);
if (data.getInt("num") < 0)
continue;
if (data.getJSONObject("abilities").keySet().stream().map(string -> data.getJSONObject("abilities").getString(string)).anyMatch(string -> string.equalsIgnoreCase(abi))) {
String name;
if (s.equals("nidoranf"))
name = "Nidoran-F";
else if (s.equals("nidoranm"))
name = "Nidoran-M";
else {
Translation gerName = getGerName(s);
if (gerName.isSuccess())
name = gerName.getTranslation();
else {
name = getGerNameNoCheck(data.getString("baseSpecies")) + "-" + data.getString("forme");
}
}
mons.add(name);
}
}
mons.removeIf(Objects::isNull);
Collections.sort(mons);
StringBuilder s = new StringBuilder();
for (String mon : mons) {
s.append(mon).append("\n");
if (s.length() > 1900) {
e.reply(new EmbedBuilder().setColor(Color.CYAN).setTitle(e.getArguments().getTranslation("abi").getOtherLang() + " haben:").setDescription(s).build());
s = new StringBuilder();
}
}
e.reply(new EmbedBuilder().setColor(Color.CYAN).setTitle(e.getArguments().getTranslation("abi").getOtherLang() + " haben:").setDescription(s).build());
/*
try {
tco.sendMessage(new EmbedBuilder().setColor(Color.CYAN).setTitle(eachWordUpperCase(msg.substring(9)) + " haben:").setDescription(String.join("\n", Jsoup.connect("https://www.pokewiki.de/" + msg.substring(9)).get().select("span[style=\"padding-left: 0.2em;\"]").stream().map(Element::text).collect(Collectors.toCollection(ArrayList::new)))).build()).queue();
} catch (IOException e) {
e.printStackTrace();
tco.sendMessage("Es ist ein Fehler aufgetreten!").queue();
}*/
}
use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.
the class HelpCommand method process.
@Override
public void process(GuildCommandEvent e) {
String cmdname = e.getArguments().getText("cmd");
Command c = Command.byName(cmdname);
EmbedBuilder builder = new EmbedBuilder();
builder.setTitle(c.getPrefix() + c.getName());
builder.setColor(Color.CYAN);
ArgumentManagerTemplate template = c.getArgumentTemplate();
builder.setDescription(c.getHelpWithoutCmd(e.getGuild()));
builder.addField("Syntax", "```" + (template.hasSyntax() ? template.getSyntax() : c.getPrefix() + c.getName() + " " + template.arguments.stream().map(a -> (a.isOptional() ? "[" : "<") + a.getName() + (a.isOptional() ? "]" : ">")).collect(Collectors.joining(" "))) + "```", false);
for (ArgumentManagerTemplate.Argument a : template.arguments) {
builder.addField(a.getName(), (a.isOptional() ? "(Optional)\n" : "") + a.getHelp(), true);
}
builder.setFooter("Aufgerufen von " + e.getAuthor().getAsTag());
if (template.hasExample()) {
builder.addField("Beispiel", "```" + template.getExample() + "```", false);
}
if (!c.getAliases().isEmpty()) {
builder.addField("Aliases", "`" + String.join("`, `", c.getAliases()) + "`", false);
}
e.reply(builder.build());
}
use of de.tectoast.emolga.commands.GuildCommandEvent in project Emolga by TecToast.
the class GetIdsCommand method process.
@Override
public void process(GuildCommandEvent e) {
Message m = e.getMessage();
TextChannel tco = e.getChannel();
Member member = e.getMember();
Role r = e.getJDA().getRoleById(e.getArguments().getID("role"));
tco.getGuild().findMembers(mem -> mem.getRoles().contains(r)).onSuccess(members -> tco.sendMessage(members.stream().map(mem -> mem.getEffectiveName() + ": " + mem.getId()).collect(Collectors.joining("\n"))).queue()).onError(t -> {
t.printStackTrace();
tco.sendMessage("Es ist ein Fehler beim Laden der Member aufgetreten!").queue();
});
}
Aggregations