use of org.jsolf.JSONObject in project Emolga by TecToast.
the class HttpHandler method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/json");
response.setStatus(200);
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Headers", "Authorization, *");
if (request.getMethod().equals("OPTIONS")) {
response.setStatus(204);
baseRequest.setHandled(true);
return;
}
String auth = request.getHeader("Authorization");
String path = target.substring("/api".length());
logger.info("target = " + target);
logger.info("auth = " + auth);
for (Method method : HttpHandler.class.getDeclaredMethods()) {
Route a = method.getAnnotation(Route.class);
if (a == null)
continue;
Matcher matcher = Pattern.compile(a.route()).matcher(path);
if (matcher.find() && baseRequest.getMethod().equals(a.method())) {
baseRequest.setHandled(true);
if (a.needsCookie() && (auth == null || auth.isEmpty())) {
response.getWriter().println(new JSONObject().put("error", "Missing authorization"));
return;
}
List<String> l = new ArrayList<>(matcher.groupCount());
for (int i = 1; i <= matcher.groupCount(); i++) {
l.add(matcher.group(i));
}
try {
if (l.size() > 0)
method.invoke(null, auth, request, response, l);
else
method.invoke(null, auth, request, response);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
break;
}
}
}
use of org.jsolf.JSONObject in project Emolga by TecToast.
the class ResistanceCommand method process.
@Override
public void process(GuildCommandEvent e) {
Translation type = e.getArguments().getTranslation("type");
if (type.isFromType(Translation.Type.TYPE)) {
JSONObject json = getTypeJSON();
HashMap<String, Integer> map = new HashMap<>();
StringBuilder b = new StringBuilder();
JSONObject typejson = json.getJSONObject(type.getTranslation()).getJSONObject("damageTaken");
typejson.keySet().forEach(str -> {
int damageTaken = typejson.getInt(str);
if (damageTaken > 1) {
Translation t = (Translation) Translation.Type.TYPE.validate(str, Translation.Language.GERMAN, "default");
if (t != null) {
if (damageTaken == 3)
b.append("**");
b.append(t.getTranslation());
if (damageTaken == 3)
b.append("**");
b.append("\n");
}
}
});
if (b.length() == 0) {
e.reply("Es wurden keine Typen gefunden, die diesen Typ resistieren! (Das ist für normal ein Fehler, Flo wurde kontaktiert)");
Command.sendToMe("ResistanceCommand ListSize 0");
return;
}
e.reply("Folgende Typen resistiert " + type.getOtherLang() + ":\n" + b);
} else {
e.reply("Macht Flo noch irgendwann :)");
}
}
use of org.jsolf.JSONObject in project Emolga by TecToast.
the class ShinyCommand method process.
@Override
public void process(GuildCommandEvent e) {
String suffix;
ArgumentManager args = e.getArguments();
String monname = e.getArguments().getTranslation("mon").getTranslation();
JSONObject mon = getDataJSON().getJSONObject(toSDName(monname));
if (args.has("regform")) {
String form = args.getText("regform");
suffix = "-" + form.toLowerCase();
} else {
suffix = "";
}
if (args.has("form")) {
String form = args.getText("form");
if (!mon.has("otherFormes")) {
e.reply(monname + " besitzt keine **" + form + "**-Form!");
return;
}
JSONArray otherFormes = mon.getJSONArray("otherFormes");
if (otherFormes.toList().stream().noneMatch(s -> ((String) s).toLowerCase().endsWith("-" + form.toLowerCase()))) {
e.reply(monname + " besitzt keine **" + form + "**-Form!");
return;
}
if (suffix.equals(""))
suffix = "-";
suffix += form.toLowerCase();
}
File f = new File("../Showdown/sspclient/sprites/gen5-shiny/" + monname.toLowerCase() + suffix + ".png");
if (!f.exists()) {
e.reply(mon + " hat keine " + args.getText("form") + "-Form!");
}
// if(!f.exists()) f = new File("../Showdown/sspclient/sprites/gen5-shiny/" + mon.split(";")[1].toLowerCase() + ".png");
e.getChannel().sendFile(f).queue();
}
use of org.jsolf.JSONObject in project Emolga by TecToast.
the class SmogonCommand method process.
@Override
public void process(GuildCommandEvent e) throws IOException {
TextChannel tco = e.getChannel();
Message m = e.getMessage();
String msg = m.getContentDisplay();
Member member = e.getMember();
Document wiki;
ArgumentManager args = e.getArguments();
String name = args.getTranslation("mon").getTranslation();
String form = args.has("form") ? "-" + args.getText("form").toLowerCase() : "";
Document d = Jsoup.connect("https://www.smogon.com/dex/ss/pokemon/" + name.toLowerCase() + form + "/").get();
JSONObject obj = new JSONObject(d.select("script").get(1).data().trim().substring("dexSettings = ".length())).getJSONArray("injectRpcs").getJSONArray(2).getJSONObject(1);
if (obj.getJSONArray("strategies").length() == 0) {
try {
d = Jsoup.connect("https://www.smogon.com/dex/sm/pokemon/" + name.toLowerCase() + form + "/").get();
obj = new JSONObject(d.select("script").get(1).data().trim().substring("dexSettings = ".length())).getJSONArray("injectRpcs").getJSONArray(2).getJSONObject(1);
tco.sendMessage("Gen 7:").queue();
} catch (Exception ex) {
tco.sendMessage("Es gibt kein aktuelles Moveset für dieses Pokemon!").queue();
return;
}
}
JSONArray arr = obj.getJSONArray("strategies");
SmogonSet smogon = new SmogonSet(arr);
// noinspection ResultOfMethodCallIgnored
e.reply(smogon.buildMessage(), ma -> ma.setActionRows(smogon.buildActionRows()), null, mes -> Command.smogonMenu.put(mes.getIdLong(), smogon), null);
}
use of org.jsolf.JSONObject in project Emolga by TecToast.
the class WhatLearnCommand method process.
@Override
public void process(GuildCommandEvent e) {
ArgumentManager args = e.getArguments();
String mon = toSDName(args.getTranslation("mon").getTranslation() + args.getOrDefault("form", ""));
String type = args.getText("type");
int gen = args.getOrDefault("gen", 8);
JSONObject learnset = getLearnsetJSON(getModByGuild(e)).getJSONObject(mon).getJSONObject("learnset");
LinkedList<String> list = new LinkedList<>();
HashMap<Integer, List<String>> levels = new HashMap<>();
boolean b = banane(learnset, gen, type, levels, list);
if (!b)
banane(learnset, --gen, type, levels, list);
String send;
if (type.equals("L")) {
StringBuilder str = new StringBuilder();
for (int i = 0; i <= 100; i++) {
if (levels.containsKey(i)) {
levels.get(i).sort(null);
str.append("L").append(i).append(": ").append(String.join(", ", levels.get(i))).append("\n");
}
}
send = str.toString();
} else {
if (list.isEmpty()) {
e.reply("Dieses Pokemon kann in Generation " + gen + " auf diese Art keine Attacken lernen!");
return;
}
ArrayList<String> set = new ArrayList<>(new HashSet<>(list));
set.sort(null);
send = String.join("\n", set);
}
e.reply(new EmbedBuilder().setColor(Color.CYAN).setDescription(send).setTitle("Attacken").build());
if (e.getMember().getIdLong() == 598199247124299776L)
e.reply("Hier noch ein Keks für dich :3");
}
Aggregations