From c271580e74a659de31eb2169ca7e1ac27a080bd7 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 4 Jun 2021 23:40:45 -0400 Subject: [PATCH] chat commands: fix tob hm/sm kc/pb tracking The : in the boss name breaks for logged in users, so remap it to a clean name instead. Also add short names. --- .../chatcommands/ChatCommandsPlugin.java | 46 ++++++++++++++++--- .../chatcommands/ChatCommandsPluginTest.java | 15 ++++++ 2 files changed, 55 insertions(+), 6 deletions(-) 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 33f282d513..8acde22888 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 @@ -98,7 +98,7 @@ public class ChatCommandsPlugin extends Plugin private static final String COX_TEAM_SIZES = "(?:\\d+(?:\\+|-\\d+)? players|Solo)"; private static final Pattern RAIDS_PB_PATTERN = Pattern.compile("Congratulations - your raid is complete!
Team size: " + COX_TEAM_SIZES + " Duration: (?[0-9:]+(?:\\.[0-9]+)?) \\(new personal best\\)"); private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("Congratulations - your raid is complete!
Team size: " + COX_TEAM_SIZES + " Duration: [0-9:.]+ Personal best: (?[0-9:]+(?:\\.[0-9]+)?)"); - private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("^.*Theatre of Blood wave completion time: (?[0-9:]+(?:\\.[0-9]+)?) \\(Personal best!\\)"); + private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("^.*Theatre of Blood wave completion time: (?[0-9:]+(?:\\.[0-9]+)?) \\((Personal best!|new personal best)\\)"); private static final Pattern TOB_WAVE_DURATION_PATTERN = Pattern.compile("^.*Theatre of Blood wave completion time: [0-9:.]+
Personal best: (?[0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("(?i)^(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) [0-9:.]+\\. Personal best: (?:)?(?[0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern NEW_PB_PATTERN = Pattern.compile("(?i)^(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) (?[0-9:]+(?:\\.[0-9]+)?) \\(new personal best\\)"); @@ -245,6 +245,11 @@ public class ChatCommandsPlugin extends Plugin configManager.setRSProfileConfiguration("killcount", boss.toLowerCase(), killcount); } + private void unsetKc(String boss) + { + configManager.unsetRSProfileConfiguration("killcount", boss.toLowerCase()); + } + private int getKc(String boss) { Integer killCount = configManager.getRSProfileConfiguration("killcount", boss.toLowerCase(), int.class); @@ -256,6 +261,11 @@ public class ChatCommandsPlugin extends Plugin configManager.setRSProfileConfiguration("personalbest", boss.toLowerCase(), seconds); } + private void unsetPb(String boss) + { + configManager.unsetRSProfileConfiguration("personalbest", boss.toLowerCase()); + } + private double getPb(String boss) { Double personalBest = configManager.getRSProfileConfiguration("personalbest", boss.toLowerCase(), double.class); @@ -280,19 +290,30 @@ public class ChatCommandsPlugin extends Plugin String boss = matcher.group(1); int kc = Integer.parseInt(matcher.group(2)); - boss = KILLCOUNT_RENAMES.getOrDefault(boss, boss); + String renamedBoss = KILLCOUNT_RENAMES + .getOrDefault(boss, boss) + // The config service doesn't support keys with colons in them + .replace(":", ""); + if (boss != renamedBoss) + { + // Unset old TOB kc + unsetKc(boss); + unsetPb(boss); + unsetKc(boss.replace(":", ".")); + unsetPb(boss.replace(":", ".")); + } - setKc(boss, kc); + setKc(renamedBoss, kc); // We either already have the pb, or need to remember the boss for the upcoming pb if (lastPb > -1) { - log.debug("Got out-of-order personal best for {}: {}", boss, lastPb); - setPb(boss, lastPb); + log.debug("Got out-of-order personal best for {}: {}", renamedBoss, lastPb); + setPb(renamedBoss, lastPb); lastPb = -1; } else { - lastBossKill = boss; + lastBossKill = renamedBoss; lastBossTime = client.getTickCount(); } return; @@ -1687,6 +1708,19 @@ public class ChatCommandsPlugin extends Plugin case "raids 2": return "Theatre of Blood"; + case "Theatre of Blood: Story Mode": + case "tob sm": + case "tob story mode": + case "tob story": + return "Theatre of Blood Story Mode"; + + case "Theatre of Blood: Hard Mode": + case "tob cm": + case "tob hm": + case "tob hard mode": + case "tob hard": + return "Theatre of Blood Hard Mode"; + // agility course case "prif": case "prifddinas": 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 775470f944..dc1c1251e9 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 @@ -194,6 +194,21 @@ public class ChatCommandsPluginTest verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 37 * 60 + 4.4); } + @Test + public void testTheatreOfBloodStoryMode() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", + "Theatre of Blood wave completion time: 5:04 (new personal best)
" + + "Theatre of Blood total completion time: 24:39 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood: Story Mode count is: 73.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood story mode", 73); + verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood story mode", 5 * 60 + 4.0); + } + @Test public void testWintertodt() {