Repository: pajlads/DinkPlugin
Pull request #126 (2023-01-14 13:22:38)

Added player url to the Discord embed author.
Makes the author have a url that can be clicked. By default links to the osrs highscores, but other services are available.

Don't know where you want the config to be placed, but my suggestion would be to create separate "Discord" section? Since some configs are only meant for Discord and not for a generic webhook?
![image](https://user-images.githubusercontent.com/17124771/212473512-cab01cb3-f8e7-4add-9ba6-3350ffba1022.png)


Felanbird: Ok so we've discussed this.... somewhere, likely in chat. So my immediate opinion is this:

I would only want this to work with Hiscores by default, due to the fact that the other websites are opt-in only

```
[2023-01-4 04:42:17] #pajlada felanbird: i would only want to support hiscores by default because the others are opt in
[2023-01-4 04:42:45] #pajlada felanbird: but we could allow a link
```
TomBolks: That is the current default https://github.com/pajlads/DinkPlugin/pull/126/files#diff-01afae69625eb273d486fd7b242ed458b39fbd20fd4b008a85829958815da9e6R199

NONE is also another possible default.
Felanbird: Note but not something you can fix, discord sees the runescape hiscores as a sketchy download, and requires you to prompt it every single time, with no options of `Trust this domain`
![image](https://user-images.githubusercontent.com/41973452/212475057-76d9badc-b8d4-48ee-a059-886a43eb6098.png)

Felanbird: Add this to the top of unversioned in `CHANGELOG.md`

`- Minor: Made player names in Discord notifications link to a player profile page. This feature can be customized to different providers such as WiseOldMan & CrystalMathLabs in the Advanced menu. (#126)`
TomBolks: I fixed all current comments, thanks for all the feedback.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8abe9b4..8178614 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 ## Unreleased
 
+- Minor: Made player names in Discord notifications link to a player profile page. This feature can be customized to different providers such as WiseOldMan & CrystalMathLabs in the Advanced menu. (#126)
 - Minor: Add setting to skip virtual level notifications. (#122)
 - Minor: Update the README to be less confusing to users. (#123)
 - Minor: Update embed icons for level up and slayer task notifications. (#119)
diff --git a/src/main/java/dinkplugin/DinkPluginConfig.java b/src/main/java/dinkplugin/DinkPluginConfig.java
index 13fd924..a873a56 100644
--- a/src/main/java/dinkplugin/DinkPluginConfig.java
+++ b/src/main/java/dinkplugin/DinkPluginConfig.java
@@ -2,6 +2,7 @@ package dinkplugin;
 
 import dinkplugin.domain.AchievementDiary;
 import dinkplugin.domain.CombatAchievementTier;
+import dinkplugin.domain.PlayerLookupService;
 import net.runelite.client.config.Config;
 import net.runelite.client.config.ConfigGroup;
 import net.runelite.client.config.ConfigItem;
@@ -187,6 +188,17 @@ public interface DinkPluginConfig extends Config {
         return "";
     }
 
+    @ConfigItem(
+        keyName = "playerLookupService",
+        name = "Player Lookup Service",
+        description = "The service used to lookup a players account, to make their name clickable in Discord embeds",
+        position = 1007,
+        section = advancedSection
+    )
+    default PlayerLookupService playerLookupService() {
+        return PlayerLookupService.OSRS_HISCORE;
+    }
+
     @ConfigItem(
         keyName = "discordWebhook", // do not rename; would break old configs
         name = "Primary Webhook URLs",
diff --git a/src/main/java/dinkplugin/domain/PlayerLookupService.java b/src/main/java/dinkplugin/domain/PlayerLookupService.java
new file mode 100644
index 0000000..7d2fd55
--- /dev/null
+++ b/src/main/java/dinkplugin/domain/PlayerLookupService.java
@@ -0,0 +1,36 @@
+package dinkplugin.domain;
+
+public enum PlayerLookupService {
+    NONE("None"),
+    OSRS_HISCORE("OSRS HiScore"),
+    CRYSTAL_MATH_LABS("Crystal Math Labs"),
+    TEMPLE_OSRS("Temple OSRS"),
+    WISE_OLD_MAN("Wise Old Man");
+
+    private final String name;
+
+    PlayerLookupService(String name) {
+        this.name = name;
+    }
+
+    public String getPlayerUrl(String playerName) {
+        switch (this) {
+            case OSRS_HISCORE:
+                return "https://secure.runescape.com/m=hiscore_oldschool/hiscorepersonal?user1=" + playerName;
+            case WISE_OLD_MAN:
+                return "https://wiseoldman.net/players/" + playerName;
+            case CRYSTAL_MATH_LABS:
+                return "https://crystalmathlabs.com/track.php?player=" + playerName;
+            case TEMPLE_OSRS:
+                return "https://templeosrs.com/player/overview.php?player=" + playerName;
+            case NONE:
+            default:
+                return null;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+}
diff --git a/src/main/java/dinkplugin/message/Author.java b/src/main/java/dinkplugin/message/Author.java
index 07b0d83..442ee3d 100644
--- a/src/main/java/dinkplugin/message/Author.java
+++ b/src/main/java/dinkplugin/message/Author.java
@@ -26,4 +26,10 @@ public class Author {
     @Nullable
     @SerializedName("icon_url")
     String iconUrl;
+
+    /**
+     * Makes name a href and opens a browser with the url when clicked
+     */
+    @Nullable
+    String url;
 }
diff --git a/src/main/java/dinkplugin/message/DiscordMessageHandler.java b/src/main/java/dinkplugin/message/DiscordMessageHandler.java
index da34133..9fa76ec 100644
--- a/src/main/java/dinkplugin/message/DiscordMessageHandler.java
+++ b/src/main/java/dinkplugin/message/DiscordMessageHandler.java
@@ -3,6 +3,7 @@ package dinkplugin.message;
 import com.google.gson.Gson;
 import dinkplugin.DinkPlugin;
 import dinkplugin.DinkPluginConfig;
+import dinkplugin.domain.PlayerLookupService;
 import dinkplugin.notifiers.data.NotificationData;
 import dinkplugin.util.Utils;
 import lombok.NonNull;
@@ -83,7 +84,7 @@ public class DiscordMessageHandler {
             mBody = mBody.withAccountType(client.getAccountType());
 
         if (config.discordRichEmbeds()) {
-            mBody = injectContent(mBody, sendImage, config.embedFooterText(), config.embedFooterIcon());
+            mBody = injectContent(mBody, sendImage, config);
         } else {
             mBody = mBody.withComputedDiscordContent(mBody.getText());
         }
@@ -161,12 +162,16 @@ public class DiscordMessageHandler {
         });
     }
 
-    private static NotificationBody<?> injectContent(@NotNull NotificationBody<?> body, boolean screenshot, String footerText, String footerIcon) {
+    private static NotificationBody<?> injectContent(@NotNull NotificationBody<?> body, boolean screenshot, DinkPluginConfig config) {
         NotificationType type = body.getType();
         NotificationData extra = body.getExtra();
+        String footerText = config.embedFooterText();
+        String footerIcon = config.embedFooterIcon();
+        PlayerLookupService playerLookupService = config.playerLookupService();
 
         Author author = Author.builder()
             .name(body.getPlayerName())
+            .url(playerLookupService.getPlayerUrl(body.getPlayerName()))
             .iconUrl(Utils.getChatBadge(body.getAccountType()))
             .build();
         Footer footer = StringUtils.isBlank(footerText) ? null : Footer.builder()


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/MockedNotifierTest.java b/src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
index c593592..e3eefb6 100644
--- a/src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
@@ -6,6 +6,7 @@ import dinkplugin.DinkPlugin;
 import dinkplugin.DinkPluginConfig;
 import dinkplugin.MockedTestBase;
 import dinkplugin.SettingsManager;
+import dinkplugin.domain.PlayerLookupService;
 import dinkplugin.message.DiscordMessageHandler;
 import dinkplugin.util.BlockingClientThread;
 import dinkplugin.util.BlockingExecutor;
@@ -103,6 +104,7 @@ abstract class MockedNotifierTest extends MockedTestBase {
         when(config.discordRichEmbeds()).thenReturn(!"false".equalsIgnoreCase(System.getenv("TEST_WEBHOOK_RICH")));
         when(config.embedFooterText()).thenReturn("Powered by Dink");
         when(config.embedFooterIcon()).thenReturn("https://github.com/pajlads/DinkPlugin/raw/master/icon.png");
+        when(config.playerLookupService()).thenReturn(PlayerLookupService.OSRS_HISCORE);
     }
 
     protected void mockItem(int id, int price, String name) {