lazily fix the yfd chomens bot crash exploit
This commit is contained in:
parent
c75de26c38
commit
7cb3164a3c
3 changed files with 83 additions and 70 deletions
src/main/java/land/chipmunk/chayapak/chomens_bot/commands
|
@ -53,6 +53,7 @@ public class TranslateCommand implements Command {
|
|||
|
||||
final Gson gson = new Gson();
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
final URL url = new URL("https://translate.google.com/translate_a/single?client=at&dt=t&dt=rm&dj=1");
|
||||
|
||||
|
@ -78,14 +79,19 @@ public class TranslateCommand implements Command {
|
|||
|
||||
final String output = translation.get("trans").getAsString();
|
||||
|
||||
return Component
|
||||
context.sendOutput(
|
||||
Component
|
||||
.translatable(
|
||||
"Result: %s",
|
||||
Component.text(output).color(NamedTextColor.GREEN)
|
||||
)
|
||||
.color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()));
|
||||
.color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))
|
||||
);
|
||||
} catch (Exception e) {
|
||||
return Component.text(e.toString()).color(NamedTextColor.RED);
|
||||
context.sendOutput(Component.text(e.toString()).color(NamedTextColor.RED));
|
||||
}
|
||||
}).start();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public class UrbanCommand implements Command {
|
|||
|
||||
final Gson gson = new Gson();
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
final URL url = new URL(
|
||||
"https://api.urbandictionary.com/v0/define?term=" +
|
||||
|
@ -58,7 +59,7 @@ public class UrbanCommand implements Command {
|
|||
|
||||
final JsonArray list = jsonObject.getAsJsonArray("list");
|
||||
|
||||
if (list.size() == 0) return Component.text("No results found").color(NamedTextColor.RED);
|
||||
if (list.size() == 0) context.sendOutput(Component.text("No results found").color(NamedTextColor.RED));
|
||||
|
||||
for (JsonElement element : list) {
|
||||
final JsonObject definitionObject = element.getAsJsonObject();
|
||||
|
@ -76,8 +77,9 @@ public class UrbanCommand implements Command {
|
|||
context.sendOutput(component);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Component.text(e.toString()).color(NamedTextColor.RED);
|
||||
context.sendOutput(Component.text(e.toString()).color(NamedTextColor.RED));
|
||||
}
|
||||
}).start();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public class WikipediaCommand implements Command {
|
|||
|
||||
final Gson gson = new Gson();
|
||||
|
||||
// TODO: mabe use the executor service thingy instead of threads because threads are b a d
|
||||
new Thread(() -> {
|
||||
try {
|
||||
final URL url = new URL(
|
||||
"https://en.wikipedia.org/api/rest_v1/page/summary/" +
|
||||
|
@ -58,11 +60,14 @@ public class WikipediaCommand implements Command {
|
|||
|
||||
final JsonObject jsonObject = gson.fromJson(jsonOutput, JsonObject.class);
|
||||
|
||||
return Component.text(jsonObject.get("extract").getAsString()).color(NamedTextColor.GREEN);
|
||||
context.sendOutput(Component.text(jsonObject.get("extract").getAsString()).color(NamedTextColor.GREEN));
|
||||
} catch (FileNotFoundException ignored) {
|
||||
return Component.text("Cannot find page: " + page).color(NamedTextColor.RED);
|
||||
context.sendOutput(Component.text("Cannot find page: " + page).color(NamedTextColor.RED));
|
||||
} catch (Exception e) {
|
||||
return Component.text(e.toString()).color(NamedTextColor.RED);
|
||||
context.sendOutput(Component.text(e.toString()).color(NamedTextColor.RED));
|
||||
}
|
||||
}).start();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue