Repository: runelite/runelite
Pull request #18537 (2024-11-17 11:03:03)

chat commands: add chests
Documentation PR: https://github.com/runelite/wiki/pull/131

* Larran's small chest
* Larran's big chest
* Brimstone chest
* crystal chest

---
Also removed some duplicate code in unit tests, and added a missing double backslash to the pattern for bird eggs.

Adam-: Ideally this would be structured like: 1commit to deduplicate code in the tests, 1 to add the chests, 1 to escape the ..

Patch:
diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java
index 88596b367..ae46e3c79 100644
--- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java
+++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java
@@ -122,9 +122,10 @@ public class ChatCommandsPlugin extends Plugin
 	private static final Pattern HS_KC_FLOOR_PATTERN = Pattern.compile("You have completed Floor (\\d) of the Hallowed Sepulchre! Total completions: <col=ff0000>([0-9,]+)</col>\\.");
 	private static final Pattern HS_KC_GHC_PATTERN = Pattern.compile("You have opened the Grand Hallowed Coffin <col=ff0000>([0-9,]+)</col> times?!");
 	private static final Pattern COLLECTION_LOG_ITEM_PATTERN = Pattern.compile("New item added to your collection log: (.*)");
-	private static final Pattern GUARDIANS_OF_THE_RIFT_PATTERN = Pattern.compile("Amount of Rifts you have closed: <col=ff0000>([0-9,]+)</col>.", Pattern.CASE_INSENSITIVE);
-	private static final Pattern HUNTER_RUMOUR_KC_PATTERN = Pattern.compile("You have completed <col=[0-9a-f]{6}>([0-9,]+)</col> rumours? for the Hunter Guild.");
-	private static final Pattern BIRD_EGG_OFFERING_PATTERN = Pattern.compile("You have made <col=ff0000>(?<kc>[\\d,]+|one)</col> offerings?.");
+	private static final Pattern GUARDIANS_OF_THE_RIFT_PATTERN = Pattern.compile("Amount of Rifts you have closed: <col=ff0000>([0-9,]+)</col>\\.", Pattern.CASE_INSENSITIVE);
+	private static final Pattern HUNTER_RUMOUR_KC_PATTERN = Pattern.compile("You have completed <col=[0-9a-f]{6}>([0-9,]+)</col> rumours? for the Hunter Guild\\.");
+	private static final Pattern BIRD_EGG_OFFERING_PATTERN = Pattern.compile("You have made <col=ff0000>(?<kc>[\\d,]+|one)</col> offerings?\\.");
+	private static final Pattern CHEST_OPENING_PATTERN = Pattern.compile("You have (?<never>never )?opened (the )?(?<chest>crystal chest|Larran's big chest|Larran's small chest|Brimstone chest)( (?<kc>[\\d,]+ times|once))?\\.");
 
 	private static final String TOTAL_LEVEL_COMMAND_STRING = "!total";
 	private static final String PRICE_COMMAND_STRING = "!price";
@@ -643,6 +644,27 @@ public class ChatCommandsPlugin extends Plugin
 
 			setKc("Bird's egg offerings", kc);
 		}
+
+		matcher = CHEST_OPENING_PATTERN.matcher(message);
+		if (matcher.find())
+		{
+			int kc;
+			if (matcher.group("never") != null)
+			{
+				kc = 0;
+			}
+			else
+			{
+				String kcString = matcher.group("kc");
+				kc = kcString.equals("once")
+					? 1
+					: Integer.parseInt(kcString.split(" ")[0].replace(",", ""));
+			}
+
+			String chest = matcher.group("chest");
+
+			setKc(chest, kc);
+		}
 	}
 
 	@VisibleForTesting
@@ -2704,6 +2726,22 @@ public class ChatCommandsPlugin extends Plugin
 			case "huey":
 				return "Hueycoatl";
 
+			case "crystal chest":
+				return "crystal chest";
+
+			case "larran small chest":
+			case "larran's small chest":
+				return "Larran's small chest";
+
+			case "larran chest":
+			case "larran's chest":
+			case "larran big chest":
+			case "larran's big chest":
+				return "Larran's big chest";
+
+			case "brimstone chest":
+				return "Brimstone chest";
+
 			default:
 				return WordUtils.capitalize(boss);
 		}


Test patch:
diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java
index 50955d95d..7524fc5d6 100644
--- a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java
+++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java
@@ -211,10 +211,7 @@ public class ChatCommandsPluginTest
 	@Test
 	public void testCorporealBeastKill()
 	{
-		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Corporeal Beast kill count is: <col=ff0000>4</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessageEvent);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "corporeal beast", 4);
+		testKillCountChatMessage("corporeal beast", "Your Corporeal Beast kill count is: <col=ff0000>4</col>.", 4);
 	}
 
 	@Test
@@ -287,55 +284,37 @@ public class ChatCommandsPluginTest
 	@Test
 	public void testWintertodt()
 	{
-		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your subdued Wintertodt count is: <col=ff0000>4</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessageEvent);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "wintertodt", 4);
+		testKillCountChatMessage("wintertodt", "Your subdued Wintertodt count is: <col=ff0000>4</col>.", 4);
 	}
 
 	@Test
 	public void testKreearra()
 	{
-		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessageEvent);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "kree'arra", 4);
+		testKillCountChatMessage("kree'arra", "Your Kree'arra kill count is: <col=ff0000>4</col>.", 4);
 	}
 
 	@Test
 	public void testBarrows()
 	{
-		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Barrows chest count is: <col=ff0000>277</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessageEvent);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "barrows chests", 277);
+		testKillCountChatMessage("barrows chests", "Your Barrows chest count is: <col=ff0000>277</col>.", 277);
 	}
 
 	@Test
 	public void testHerbiboar()
 	{
-		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your herbiboar harvest count is: <col=ff0000>4091</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessageEvent);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "herbiboar", 4091);
+		testKillCountChatMessage("herbiboar", "Your herbiboar harvest count is: <col=ff0000>4091</col>.", 4091);
 	}
 
 	@Test
 	public void testGauntlet()
 	{
-		ChatMessage gauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>123</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(gauntletMessage);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 123);
+		testKillCountChatMessage("gauntlet", "Your Gauntlet completion count is: <col=ff0000>123</col>.", 123);
 	}
 
 	@Test
 	public void testCorruptedGauntlet()
 	{
-		ChatMessage corruptedGauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Corrupted Gauntlet completion count is: <col=ff0000>4729</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(corruptedGauntletMessage);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "corrupted gauntlet", 4729);
+		testKillCountChatMessage("corrupted gauntlet", "Your Corrupted Gauntlet completion count is: <col=ff0000>4729</col>.", 4729);
 	}
 
 	@Test
@@ -785,19 +764,13 @@ public class ChatCommandsPluginTest
 	@Test
 	public void testHsFloorKc()
 	{
-		ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have completed Floor 5 of the Hallowed Sepulchre! Total completions: <col=ff0000>1,114</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessage);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "hallowed sepulchre floor 5", 1114);
+		testKillCountChatMessage("hallowed sepulchre floor 5", "You have completed Floor 5 of the Hallowed Sepulchre! Total completions: <col=ff0000>1,114</col>.", 1114);
 	}
 
 	@Test
 	public void testHsGhcKc()
 	{
-		ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have opened the Grand Hallowed Coffin <col=ff0000>1,542</col> times!", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessage);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "hallowed sepulchre", 1542);
+		testKillCountChatMessage("hallowed sepulchre", "You have opened the Grand Hallowed Coffin <col=ff0000>1,542</col> times!", 1542);
 	}
 
 	@Test
@@ -1266,49 +1239,57 @@ public class ChatCommandsPluginTest
 	@Test
 	public void testGuardiansOfTheRift()
 	{
-		ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Amount of rifts you have closed: <col=ff0000>1,627</col>.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessage);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "guardians of the rift", 1627);
+		testKillCountChatMessage("guardians of the rift", "Amount of rifts you have closed: <col=ff0000>1,627</col>.", 1627);
 	}
 
 	@Test
 	public void testBirdsEgg()
 	{
-		ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have made <col=ff0000>one</col> offering.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessage);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "bird's egg offerings", 1);
+		testKillCountChatMessage("bird's egg offerings", "You have made <col=ff0000>one</col> offering.", 1);
+		testKillCountChatMessage("bird's egg offerings", "You have made <col=ff0000>420</col> offerings.", 420);
+		testKillCountChatMessage("bird's egg offerings", "You have made <col=ff0000>10,000</col> offerings.", 10_000);
+	}
 
-		chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have made <col=ff0000>420</col> offerings.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessage);
+	@Test
+	public void testBrimstoneChest()
+	{
+		testKillCountChatMessage("brimstone chest", "You have opened the Brimstone chest 0 times.", 0);
+		testKillCountChatMessage("brimstone chest", "You have opened the Brimstone chest once.", 1);
+		testKillCountChatMessage("brimstone chest", "You have opened the Brimstone chest 2 times.", 2);
+		testKillCountChatMessage("brimstone chest", "You have opened the Brimstone chest 1,234 times.", 1234);
+	}
 
-		verify(configManager).setRSProfileConfiguration("killcount", "bird's egg offerings", 420);
+	@Test
+	public void testLarransChests()
+	{
+		testKillCountChatMessage("larran's small chest", "You have opened Larran's small chest 0 times.", 0);
+		testKillCountChatMessage("larran's small chest", "You have opened Larran's small chest once.", 1);
+		testKillCountChatMessage("larran's small chest", "You have opened Larran's small chest 2 times.", 2);
 
-		chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have made <col=ff0000>10,000</col> offerings.", null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessage);
+		testKillCountChatMessage("larran's big chest", "You have opened Larran's big chest 0 times.", 0);
+		testKillCountChatMessage("larran's big chest", "You have opened Larran's big chest once.", 1);
+		testKillCountChatMessage("larran's big chest", "You have opened Larran's big chest 26,644 times.", 26644);
+	}
 
-		verify(configManager).setRSProfileConfiguration("killcount", "bird's egg offerings", 10_000);
+	@Test
+	public void testCrystalChest()
+	{
+		testKillCountChatMessage("crystal chest", "You have never opened the crystal chest.", 0);
+		testKillCountChatMessage("crystal chest", "You have opened the crystal chest once.", 1);
+		testKillCountChatMessage("crystal chest", "You have opened the crystal chest 172 times.", 172);
+		testKillCountChatMessage("crystal chest", "You have opened the crystal chest 2,015 times.", 2015);
 	}
 
 	@Test
 	public void testHunterRumours()
 	{
-		testHunterRumourChatMessage("You have completed <col=ff3045>77</col> rumours for the Hunter Guild.", 77);
+		testKillCountChatMessage("hunter rumours", "You have completed <col=ff3045>77</col> rumours for the Hunter Guild.", 77);
 		// single kc has no s.
-		testHunterRumourChatMessage("You have completed <col=ff3045>1</col> rumour for the Hunter Guild.", 1);
+		testKillCountChatMessage("hunter rumours", "You have completed <col=ff3045>1</col> rumour for the Hunter Guild.", 1);
 		// opaque chatbox has different color
-		testHunterRumourChatMessage("You have completed <col=e00a19>2</col> rumours for the Hunter Guild.", 2);
+		testKillCountChatMessage("hunter rumours", "You have completed <col=e00a19>2</col> rumours for the Hunter Guild.", 2);
 		// with comma in number
-		testHunterRumourChatMessage("You have completed <col=ff3045>1,032</col> rumours for the Hunter Guild.", 1032);
-	}
-
-	private void testHunterRumourChatMessage(String message, int kc)
-	{
-		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", message, null, 0);
-		chatCommandsPlugin.onChatMessage(chatMessageEvent);
-
-		verify(configManager).setRSProfileConfiguration("killcount", "hunter rumours", kc);
+		testKillCountChatMessage("hunter rumours", "You have completed <col=ff3045>1,032</col> rumours for the Hunter Guild.", 1032);
 	}
 
 	@Test
@@ -1398,4 +1379,12 @@ public class ChatCommandsPluginTest
 		verify(configManager).setRSProfileConfiguration("personalbest", "tombs of amascut entry mode", 20 * 60 + 31.);
 		verify(configManager).setRSProfileConfiguration("personalbest", "tombs of amascut entry mode 2 players", 20 * 60 + 31.);
 	}
+
+	private void testKillCountChatMessage(String key, String message, int kc)
+	{
+		ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", message, null, 0);
+		chatCommandsPlugin.onChatMessage(chatMessageEvent);
+
+		verify(configManager).setRSProfileConfiguration("killcount", key, kc);
+	}
 }