Skip to content

Commit

Permalink
Merge pull request #1695 from ManInMyVan/custom-webhook-embed-title
Browse files Browse the repository at this point in the history
Allow customizing webhook embed title
  • Loading branch information
SamB440 committed Sep 12, 2024
2 parents f1a1e46 + dfc8c98 commit 3445a02
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/ac/grim/grimac/manager/DiscordManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DiscordManager implements Initable {
private static WebhookClient client;
private int embedColor;
private String staticContent = "";
private String embedTitle = "";

public static final Pattern WEBHOOK_PATTERN = Pattern.compile("(?:https?://)?(?:\\w+\\.)?\\w+\\.\\w+/api(?:/v\\d+)?/webhooks/(\\d+)/([\\w-]+)(?:/(?:\\w+)?)?");

Expand All @@ -40,6 +41,8 @@ public void start() {
client = WebhookClient.withId(Long.parseUnsignedLong(matcher.group(1)), matcher.group(2));
client.setTimeout(15000); // Requests expire after 15 seconds

embedTitle = GrimAPI.INSTANCE.getConfigManager().getConfig().getStringElse("embed-title", "**Grim Alert**");

try {
embedColor = Color.decode(GrimAPI.INSTANCE.getConfigManager().getConfig().getStringElse("embed-color", "#00FFFF")).getRGB();
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -70,7 +73,7 @@ private List<String> getDefaultContents() {
public void sendAlert(GrimPlayer player, String verbose, String checkName, String violations) {
if (client != null) {

String content = staticContent + "";
String content = staticContent;
content = content.replace("%check%", checkName);
content = content.replace("%violations%", violations);
content = GrimAPI.INSTANCE.getExternalAPI().replaceVariables(player, content, false);
Expand All @@ -80,7 +83,7 @@ public void sendAlert(GrimPlayer player, String verbose, String checkName, Strin
.setImageUrl("https://i.stack.imgur.com/Fzh0w.png") // Constant width
.setThumbnailUrl("https://crafthead.net/helm/" + player.user.getProfile().getUUID())
.setColor(embedColor)
.setTitle(new WebhookEmbed.EmbedTitle("**Grim Alert**", null))
.setTitle(new WebhookEmbed.EmbedTitle(embedTitle, null))
.setDescription(content)
.setTimestamp(Instant.now())
.setFooter(new WebhookEmbed.EmbedFooter("", "https://grim.ac/images/grim.png"));
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/de.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Ob Discord Webhook aktiviert werden soll
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Spieler**: %player%"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Player**: %player%"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/discord/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enabled: false
# La URL del webhook.
webhook: ""

embed-title: "**Grim Alert**"

# El color del embed que se mandara por este webhook.
embed-color: "#00FFFF"

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/fr.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Joueur**: %player%"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/it.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Giocatore**: %player%"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/nl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Speler**: %player%"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/pt.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Jogador**: %player%"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/ru.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Включать ли веб-крючок discord
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**Игрок**: %player%"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/discord/zh.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 是否启用discord webhook
enabled: false
webhook: ""
embed-title: "**Grim Alert**"
embed-color: "#00FFFF"
violation-content:
- "**玩家名**: %player%"
Expand Down

0 comments on commit 3445a02

Please sign in to comment.