Skip to content

Commit

Permalink
fix(quest): ignore partial completions (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Apr 14, 2023
1 parent 7a0b379 commit ac1bbbc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dinkplugin/notifiers/QuestNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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%" },
Expand Down
48 changes: 36 additions & 12 deletions src/main/java/dinkplugin/util/QuestUtils.java
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -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 {

Expand All @@ -46,21 +53,20 @@ public class QuestUtils {
private final Collection<String> RFD_TAGS = ImmutableList.of("Another Cook", "freed", "defeated", "saved");
private final Collection<String> 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";
}
Expand All @@ -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;
}

}

0 comments on commit ac1bbbc

Please sign in to comment.