Repository: pajlads/DinkPlugin (java)

Issue:
Allow different notification message for dupe pets
I believe it should be easy enough to differentiate given the game message is different when receiving a duplicate pet?

Pull request:
feat(pet): clarify duplicate status for non-rich webhook messages
Actually closes #292


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5b05586..715c6c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,7 @@
 ## Unreleased
 
 - Minor: Support new thread creation for Discord forum channels. (#302)
-- Minor: Indicate whether pets are already owned in pet notifications. (#303)
+- Minor: Indicate whether pets are already owned in pet notifications. (#303, #307)
 - Minor: Include NPC kill count in loot notifications. (#299)
 - Minor: Add option to disable price in Group Storage notifications. (#298)
 - Minor: Add `%TOTAL_LEVEL%` message template for level notifications. (#300)
diff --git a/src/main/java/dinkplugin/DinkPluginConfig.java b/src/main/java/dinkplugin/DinkPluginConfig.java
index 51021f0..3f413e5 100644
--- a/src/main/java/dinkplugin/DinkPluginConfig.java
+++ b/src/main/java/dinkplugin/DinkPluginConfig.java
@@ -570,12 +570,13 @@ public interface DinkPluginConfig extends Config {
         keyName = "petNotifMessage",
         name = "Notification Message",
         description = "The message to be sent through the webhook.<br/>" +
-            "Use %USERNAME% to insert your username",
+            "Use %USERNAME% to insert your username<br/>" +
+            "Use %GAME_MESSAGE% to insert the game message associated with this type of pet drop",
         position = 12,
         section = petSection
     )
     default String petNotifyMessage() {
-        return "%USERNAME% has a funny feeling they are being followed";
+        return "%USERNAME% %GAME_MESSAGE%";
     }
 
     @ConfigItem(
diff --git a/src/main/java/dinkplugin/notifiers/PetNotifier.java b/src/main/java/dinkplugin/notifiers/PetNotifier.java
index e68e78c..38bbe5a 100644
--- a/src/main/java/dinkplugin/notifiers/PetNotifier.java
+++ b/src/main/java/dinkplugin/notifiers/PetNotifier.java
@@ -73,6 +73,8 @@ public class PetNotifier extends BaseNotifier {
 
     private volatile boolean duplicate = false;
 
+    private volatile boolean backpack = false;
+
     @Override
     public boolean isEnabled() {
         return config.notifyPet() && super.isEnabled();
@@ -90,6 +92,7 @@ public class PetNotifier extends BaseNotifier {
                     // Prime the notifier to trigger next tick
                     this.petName = PRIMED_NAME;
                     this.duplicate = chatMessage.contains("would have been");
+                    this.backpack = chatMessage.contains(" backpack");
                 }
             } else if (PRIMED_NAME.equals(petName)) {
                 parseItemFromGameMessage(chatMessage)
@@ -129,14 +132,25 @@ public class PetNotifier extends BaseNotifier {
         this.petName = null;
         this.milestone = null;
         this.duplicate = false;
+        this.backpack = false;
         this.ticksWaited.set(0);
     }
 
     private void handleNotify() {
+        String gameMessage;
+        if (backpack) {
+            gameMessage = "feels something weird sneaking into their backpack";
+        } else if (duplicate) {
+            gameMessage = "has a funny feeling like they would have been followed...";
+        } else {
+            gameMessage = "has a funny feeling like they're being followed";
+        }
+
         Template notifyMessage = Template.builder()
             .template(config.petNotifyMessage())
             .replacementBoundary("%")
             .replacement("%USERNAME%", Replacements.ofText(Utils.getPlayerName(client)))
+            .replacement("%GAME_MESSAGE%", Replacements.ofText(gameMessage))
             .build();
 
         String thumbnail = Optional.ofNullable(petName)


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/PetNotifierTest.java b/src/test/java/dinkplugin/notifiers/PetNotifierTest.java
index d57e8a2..0e8b3f2 100644
--- a/src/test/java/dinkplugin/notifiers/PetNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/PetNotifierTest.java
@@ -44,6 +44,9 @@ class PetNotifierTest extends MockedNotifierTest {
 
     @Test
     void testNotify() {
+        // update mocks
+        when(config.petNotifyMessage()).thenReturn("%USERNAME% %GAME_MESSAGE%");
+
         // send fake message
         notifier.onChatMessage("You feel something weird sneaking into your backpack.");
         IntStream.rangeClosed(0, MAX_TICKS_WAIT).forEach(i -> notifier.onTick());
@@ -54,7 +57,7 @@ class PetNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .extra(new PetNotificationData(null, null, false))
-                .text(buildTemplate(PLAYER_NAME + " got a pet"))
+                .text(buildTemplate(PLAYER_NAME + " feels something weird sneaking into their backpack"))
                 .type(NotificationType.PET)
                 .build()
         );
@@ -62,6 +65,9 @@ class PetNotifierTest extends MockedNotifierTest {
 
     @Test
     void testNotifyDuplicate() {
+        // update mocks
+        when(config.petNotifyMessage()).thenReturn("%USERNAME% %GAME_MESSAGE%");
+
         // send fake message
         notifier.onChatMessage("You have a funny feeling like you would have been followed...");
         IntStream.rangeClosed(0, MAX_TICKS_WAIT).forEach(i -> notifier.onTick());
@@ -72,7 +78,7 @@ class PetNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .extra(new PetNotificationData(null, null, true))
-                .text(buildTemplate(PLAYER_NAME + " got a pet"))
+                .text(buildTemplate(PLAYER_NAME + " has a funny feeling like they would have been followed..."))
                 .type(NotificationType.PET)
                 .build()
         );
@@ -258,11 +264,14 @@ class PetNotifierTest extends MockedNotifierTest {
 
     @Test
     void testNotifyOverride() {
+        // update mocks
+        when(config.petNotifyMessage()).thenReturn("%USERNAME% %GAME_MESSAGE%");
+
         // define url override
         when(config.petWebhook()).thenReturn("https://example.com");
 
         // send fake message
-        notifier.onChatMessage("You feel something weird sneaking into your backpack.");
+        notifier.onChatMessage("You have a funny feeling like you're being followed.");
         IntStream.rangeClosed(0, MAX_TICKS_WAIT).forEach(i -> notifier.onTick());
 
         // verify handled at override url
@@ -271,7 +280,7 @@ class PetNotifierTest extends MockedNotifierTest {
             false,
             NotificationBody.builder()
                 .extra(new PetNotificationData(null, null, false))
-                .text(buildTemplate(PLAYER_NAME + " got a pet"))
+                .text(buildTemplate(PLAYER_NAME + " has a funny feeling like they're being followed"))
                 .type(NotificationType.PET)
                 .build()
         );