|
2 | 2 |
|
3 | 3 | import io.github.jdaapplications.guildbot.executor.CommandExecutor;
|
4 | 4 | import io.github.jdaapplications.guildbot.util.ExceptionUtils;
|
5 |
| -import io.github.jdaapplications.guildbot.util.Properties; |
| 5 | +import io.github.jdaapplications.guildbot.util.PropertyUtil; |
6 | 6 | import net.dv8tion.jda.core.*;
|
7 | 7 | import net.dv8tion.jda.core.entities.Game;
|
8 | 8 | import net.dv8tion.jda.core.entities.impl.JDAImpl;
|
|
15 | 15 | import net.dv8tion.jda.core.requests.Requester;
|
16 | 16 | import net.dv8tion.jda.core.utils.IOUtil;
|
17 | 17 | import okhttp3.*;
|
| 18 | +import org.apache.commons.io.FileUtils; |
18 | 19 | import org.hjson.JsonObject;
|
19 | 20 | import org.hjson.JsonValue;
|
20 | 21 | import org.json.JSONArray;
|
|
25 | 26 | import java.awt.Color;
|
26 | 27 | import java.io.File;
|
27 | 28 | import java.io.FileNotFoundException;
|
28 |
| -import java.io.FileReader; |
29 | 29 | import java.io.IOException;
|
30 | 30 | import java.nio.file.Paths;
|
31 | 31 | import java.util.concurrent.ScheduledExecutorService;
|
@@ -53,10 +53,9 @@ public class GuildBot
|
53 | 53 |
|
54 | 54 | private CommandExecutor commandExecutor;
|
55 | 55 |
|
56 |
| - @SuppressWarnings("resource") |
57 | 56 | public GuildBot(final File config, final String token, final String errorWebhook) throws LoginException, IllegalArgumentException, RateLimitedException, FileNotFoundException, IOException
|
58 | 57 | {
|
59 |
| - this.config = JsonValue.readHjson(new FileReader(config)).asObject(); |
| 58 | + this.config = JsonValue.readHjson(FileUtils.readFileToString(config, "UTF-8")).asObject(); |
60 | 59 | this.webhookUrl = errorWebhook;
|
61 | 60 |
|
62 | 61 | this.threadPool = new ScheduledThreadPoolExecutor(4, r ->
|
@@ -90,11 +89,11 @@ public static void main(final String[] args) throws Exception
|
90 | 89 | {
|
91 | 90 | final File config = new File(System.getProperty("guildbot.config", "config.hjson"));
|
92 | 91 |
|
93 |
| - String token = Properties.get("guildbot.token", Paths.get(".token")); |
| 92 | + String token = PropertyUtil.getProperty("guildbot.token", Paths.get(".token")); |
94 | 93 | if (token == null)
|
95 | 94 | throw new RuntimeException("could not find a token");
|
96 | 95 |
|
97 |
| - String webhook = Properties.get("guildbot.webhook.error", Paths.get(".error-hook")); |
| 96 | + String webhook = PropertyUtil.getProperty("guildbot.webhook.error", Paths.get(".error-hook")); |
98 | 97 | if (webhook == null)
|
99 | 98 | GuildBot.log.warn("could not find a error webhook token, disabling webhook");
|
100 | 99 |
|
@@ -137,19 +136,20 @@ public void handleThrowable(final Throwable throwable, final String context)
|
137 | 136 | .setDescription(String.format("%.2048s", message))
|
138 | 137 | .build();
|
139 | 138 |
|
140 |
| - |
141 | 139 | final String body = new JSONObject()
|
142 | 140 | .put("embeds", new JSONArray()
|
143 | 141 | .put(embed.toJSONObject()))
|
144 | 142 | .toString();
|
145 | 143 |
|
146 | 144 | OkHttpClient client = ((JDAImpl) getJDA()).getRequester().getHttpClient();
|
| 145 | + |
147 | 146 | Request request = new Request.Builder().url(this.webhookUrl)
|
148 | 147 | .post(RequestBody.create(MediaType.parse("application/json"), body))
|
149 | 148 | .addHeader("user-agent", "GuildBot (https://github.com/JDA-Applications/GuildBot)")
|
150 | 149 | .addHeader("content-type", "application/json")
|
151 | 150 | .addHeader("accept-encoding", "gzip")
|
152 | 151 | .build();
|
| 152 | + |
153 | 153 | Call call = client.newCall(request);
|
154 | 154 | try (Response response = call.execute())
|
155 | 155 | {
|
|
0 commit comments