Repository: pajlads/DinkPlugin (java)

Issue:
Add total level count variable via %TOTAL_SKILLS%
An additional value that could be added to grab the total level of the player would be nice!

Example:
`%USERNAME%` has levelled `%SKILL%` - Total Level: `%TOTAL_SKILLS%`
`Weiqiiing` has levelled `Thieving to 99` - Total Level: `2121`

Pull request:
feat: add %TOTAL_LEVEL% template for level message
Closes #295


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5dbc0e2..83beede 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 ## Unreleased
 
+- Minor: Add `%TOTAL_LEVEL%` message template for level notifications. (#300)
 - Dev: Update gradle wrapper to v8.3 minor version. (#293)
 
 ## 1.6.2
diff --git a/README.md b/README.md
index 050a257..d69f368 100644
--- a/README.md
+++ b/README.md
@@ -246,6 +246,8 @@ Lastly, Dink makes exceptions for Inferno and TzHaar Fight Cave; deaths in these
 
 `%SKILL%` will be replaced with the skill name and level that was achieved
 
+`%TOTAL_LEVEL%` will be replaced with the updated total level across all skills.
+
 <details>
   <summary>JSON for Levelups:</summary>
 
diff --git a/src/main/java/dinkplugin/DinkPluginConfig.java b/src/main/java/dinkplugin/DinkPluginConfig.java
index 951cd50..0e80dcb 100644
--- a/src/main/java/dinkplugin/DinkPluginConfig.java
+++ b/src/main/java/dinkplugin/DinkPluginConfig.java
@@ -648,7 +648,8 @@ public interface DinkPluginConfig extends Config {
         name = "Notification Message",
         description = "The message to be sent through the webhook.<br/>" +
             "Use %USERNAME% to insert your username<br/>" +
-            "Use %SKILL% to insert the levelled skill(s)",
+            "Use %SKILL% to insert the levelled skill(s)<br/>" +
+            "Use %TOTAL_LEVEL% to insert the updated total level",
         position = 27,
         section = levelSection
     )
diff --git a/src/main/java/dinkplugin/notifiers/LevelNotifier.java b/src/main/java/dinkplugin/notifiers/LevelNotifier.java
index 7a94db5..b94120b 100644
--- a/src/main/java/dinkplugin/notifiers/LevelNotifier.java
+++ b/src/main/java/dinkplugin/notifiers/LevelNotifier.java
@@ -170,6 +170,7 @@ public class LevelNotifier extends BaseNotifier {
 
     private void attemptNotify() {
         // Prepare level state
+        int totalLevel = client.getTotalLevel();
         List<String> levelled = new ArrayList<>(levelledSkills.size());
         levelledSkills.drainTo(levelled);
         int count = levelled.size();
@@ -229,6 +230,7 @@ public class LevelNotifier extends BaseNotifier {
             .replacementBoundary("%")
             .replacement("%USERNAME%", Replacements.ofText(Utils.getPlayerName(client)))
             .replacement("%SKILL%", skillMessage.build())
+            .replacement("%TOTAL_LEVEL%", Replacements.ofText(String.valueOf(totalLevel)))
             .build();
 
         // Fire notification


Test patch:
diff --git a/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java b/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java
index 80d7252..3724611 100644
--- a/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java
+++ b/src/test/java/dinkplugin/notifiers/LevelNotifierTest.java
@@ -67,6 +67,9 @@ class LevelNotifierTest extends MockedNotifierTest {
     @Test
     void testNotify() {
         Map<String, Integer> expectedSkills = skillsMap("Agility", 5);
+        int totalLevel = expectedSkills.values().stream().mapToInt(i -> i).sum();
+        when(client.getTotalLevel()).thenReturn(totalLevel);
+        when(config.levelNotifyMessage()).thenReturn("%USERNAME% has levelled %SKILL%, achieving a total level of %TOTAL_LEVEL%");
 
         // fire skill event
         plugin.onStatChanged(new StatChanged(Skill.AGILITY, 400, 5, 5));
@@ -81,8 +84,9 @@ class LevelNotifierTest extends MockedNotifierTest {
             NotificationBody.builder()
                 .text(
                     Template.builder()
-                        .template(PLAYER_NAME + " has levelled {{skill}} to 5")
+                        .template(PLAYER_NAME + " has levelled {{skill}} to 5, achieving a total level of {{total}}")
                         .replacement("{{skill}}", Replacements.ofWiki("Agility"))
+                        .replacement("{{total}}", Replacements.ofText(String.valueOf(totalLevel)))
                         .build()
                 )
                 .extra(new LevelNotificationData(ImmutableMap.of("Agility", 5), expectedSkills, unchangedCombatLevel))