Skip to content

Commit

Permalink
fix: fire clue notification for very first scroll at a given tier (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
PsycloneTM authored Feb 25, 2025
1 parent bd8d46a commit 06b042b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

- Bugfix: Fire clue notification upon the first completion of a scroll at a given tier. (#662)

## 1.10.22

- Minor: Allow excluding Barbarian Assault high gambles from loot notifications to avoid duplication with the gambles notifier. (#657)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dinkplugin/notifiers/ClueNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Slf4j
@Singleton
public class ClueNotifier extends BaseNotifier {
private static final Pattern CLUE_SCROLL_REGEX = Pattern.compile("You have completed (?<scrollCount>\\d+) (?<scrollType>\\w+) Treasure Trails\\.");
private static final Pattern CLUE_SCROLL_REGEX = Pattern.compile("You have completed (?<scrollCount>\\d+) (?<scrollType>\\w+) Treasure Trails?\\.");
private final AtomicInteger badTicks = new AtomicInteger(); // used to prevent notifs from using stale data
private volatile int clueCount = -1;
private volatile String clueType = "";
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/dinkplugin/notifiers/ClueNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,48 @@ void testNotify() {
);
}

@Test
void testNotifyFirst() {
// update config mock
when(config.clueMinTier()).thenReturn(ClueTier.EASY);

// fire chat event
notifier.onChatMessage("You have completed 1 easy Treasure Trail.");

// mock widgets
Widget widget = mock(Widget.class);
when(client.getWidget(ComponentID.CLUESCROLL_REWARD_ITEM_CONTAINER)).thenReturn(widget);

Widget child = mock(Widget.class);
when(child.getItemQuantity()).thenReturn(1);
when(child.getItemId()).thenReturn(ItemID.RUBY);

Widget[] children = { child };
when(widget.getChildren()).thenReturn(children);

// fire widget event
WidgetLoaded event = new WidgetLoaded();
event.setGroupId(InterfaceID.CLUESCROLL_REWARD);
plugin.onWidgetLoaded(event);

// verify notification message
verifyCreateMessage(
PRIMARY_WEBHOOK_URL,
false,
NotificationBody.builder()
.text(
Template.builder()
.template(String.format("%s has completed a {{tier}} clue, for a total of %d. They obtained: 1 x {{ruby}} (%d)", PLAYER_NAME, 1, RUBY_PRICE))
.replacement("{{tier}}", Replacements.ofWiki("easy", "Clue scroll (easy)"))
.replacement("{{ruby}}", Replacements.ofWiki("Ruby"))
.build()
)
.extra(new ClueNotificationData("easy", 1, Collections.singletonList(new SerializedItemStack(ItemID.RUBY, 1, RUBY_PRICE, "Ruby"))))
.type(NotificationType.CLUE)
.build()
);
}

@Test
void testIgnoreTier() {
// fire chat event
Expand Down

0 comments on commit 06b042b

Please sign in to comment.