diff --git a/CHANGELOG.md b/CHANGELOG.md index deebcc7f..d9eb7674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Minor: Add advanced setting to hide chat when screenshotting. (#208) - Minor: Rescale screenshots to comply with Discord's 8MB size limit. (#200) - Minor: Include combat level in skill notifications. (#203) +- Bugfix: Skip quest notification for Hazeel cult partial completion. (#211) - Dev: Update grade wrapper to v8.1 minor version. (#209) - Dev: Refactor killer identification in death notifier. (#197, #210) diff --git a/src/main/java/dinkplugin/notifiers/QuestNotifier.java b/src/main/java/dinkplugin/notifiers/QuestNotifier.java index fc4ed69b..7b18c525 100644 --- a/src/main/java/dinkplugin/notifiers/QuestNotifier.java +++ b/src/main/java/dinkplugin/notifiers/QuestNotifier.java @@ -68,6 +68,8 @@ private void handleNotify(String questText) { boolean validPoints = questPoints > 0 && totalQuestPoints > 0; String parsed = QuestUtils.parseQuestWidget(questText); + if (parsed == null) return; + String notifyMessage = StringUtils.replaceEach( config.questNotifyMessage(), new String[] { "%USERNAME%", "%QUEST%" }, diff --git a/src/main/java/dinkplugin/util/QuestUtils.java b/src/main/java/dinkplugin/util/QuestUtils.java index cb556f36..cda8a656 100644 --- a/src/main/java/dinkplugin/util/QuestUtils.java +++ b/src/main/java/dinkplugin/util/QuestUtils.java @@ -1,10 +1,12 @@ /* - * Adapted from https://github.com/oliverpatrick/Enhanced-Discord-Notifications + * Adapted from https://github.com/runelite/runelite/pull/11580 * which is available under the following license: * * BSD 2-Clause License * - * Copyright (c) 2021, William Winter + * Copyright (c) 2016-2017, Adam + * Copyright (c) 2018, Lotto + * * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,11 +35,16 @@ import com.google.common.collect.ImmutableList; import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; +@Slf4j @UtilityClass public class QuestUtils { @@ -46,21 +53,20 @@ public class QuestUtils { private final Collection RFD_TAGS = ImmutableList.of("Another Cook", "freed", "defeated", "saved"); private final Collection WORD_QUEST_IN_NAME_TAGS = ImmutableList.of("Another Cook", "Doric", "Heroes", "Legends", "Observatory", "Olaf", "Waterfall"); + @Nullable public String parseQuestWidget(final String text) { - // "You have completed The Corsair Curse!" - final Matcher questMatch1 = QUEST_PATTERN_1.matcher(text); - // "'One Small Favour' completed!" - final Matcher questMatch2 = QUEST_PATTERN_2.matcher(text); - final Matcher questMatchFinal = questMatch1.matches() ? questMatch1 : questMatch2; - if (!questMatchFinal.matches()) { - return "Unable to find quest name!"; + Matcher matcher = getMatcher(text); + if (matcher == null) { + log.warn("Unable to match quest: {}", text); + return null; } - String quest = questMatchFinal.group("quest"); - String verb = questMatchFinal.group("verb") != null ? questMatchFinal.group("verb") : ""; + String quest = matcher.group("quest"); + String verb = StringUtils.defaultString(matcher.group("verb")); if (verb.contains("kind of")) { - quest += " partial completion"; + log.debug("Skipping partial completion of quest: {}", quest); + return null; } else if (verb.contains("completely")) { quest += " II"; } @@ -76,4 +82,22 @@ public String parseQuestWidget(final String text) { return quest; } + @Nullable + private Matcher getMatcher(String text) { + if (text == null) + return null; + + // "You have completed The Corsair Curse!" + Matcher questMatch1 = QUEST_PATTERN_1.matcher(text); + if (questMatch1.matches()) + return questMatch1; + + // "'One Small Favour' completed!" + Matcher questMatch2 = QUEST_PATTERN_2.matcher(text); + if (questMatch2.matches()) + return questMatch2; + + return null; + } + }