-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dae03e
commit 9720c4f
Showing
32 changed files
with
158 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/ru/pinkgoosik/kitsun/debug/KitsunDebugWebhook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ru.pinkgoosik.kitsun.debug; | ||
|
||
import ru.pinkgoosik.kitsun.DiscordApp; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class KitsunDebugWebhook { | ||
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder().build(); | ||
|
||
public static void ping(String message) { | ||
DiscordApp.LOGGER.error(message); | ||
sendMessage("<@287598520268095488>\n" + message); | ||
} | ||
|
||
public static void report(String message) { | ||
DiscordApp.LOGGER.error(message); | ||
sendMessage(message); | ||
} | ||
|
||
public static void info(String text) { | ||
DiscordApp.LOGGER.info(text); | ||
sendMessage(text); | ||
} | ||
|
||
private static void sendMessage(String content) { | ||
if(DiscordApp.secrets.get().debugWebhook.isBlank()) return; | ||
|
||
try { | ||
byte[] out = ("{\"content\":\"" + content + "\"}").getBytes(StandardCharsets.UTF_8); | ||
int length = out.length; | ||
|
||
HttpRequest request = HttpRequest.newBuilder() | ||
.POST(HttpRequest.BodyPublishers.ofByteArray(out)) | ||
.uri(new URI(DiscordApp.secrets.get().debugWebhook)) | ||
.header("Content-Type", "application/json") | ||
.build(); | ||
|
||
HTTP_CLIENT.sendAsync(request, HttpResponse.BodyHandlers.ofString()); | ||
} | ||
catch (Exception e) { | ||
DiscordApp.LOGGER.info("Failed to execute webhook due to an exception: " + e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.