diff --git a/triggers/wordtrack/categories.sh b/triggers/wordtrack/categories.sh index 37d049b..048011c 100644 --- a/triggers/wordtrack/categories.sh +++ b/triggers/wordtrack/categories.sh @@ -5,7 +5,8 @@ # Category: coffee # Words that trigger tracking for coffee category -coffeeWords=("coffee" "espresso" "latte" "mocha" "cappuccino" "americano" "frappuccino" "macchiato" "cortado" "affogato") +# Note: coffee* allows matching at start of words (coffeehouse, coffeepot, etc.) +coffeeWords=("coffee*" "espresso" "latte" "mocha" "cappuccino" "americano" "frappuccino" "macchiato" "cortado" "affogato") # Level thresholds and reward names for coffee category # Array key is the threshold (word count needed), value is the level name @@ -30,7 +31,9 @@ declare -A teaLevels=( ) # Category: gaming -gamingWords=("game" "gaming" "play" "played" "console" "steam" "xbox" "playstation" "nintendo" "pc gaming") +# Note: *game* matches game, gaming, endgame, videogame, etc. +# Note: *play* matches play, played, playing, replay, gameplay, etc. +gamingWords=("*game*" "*play*" "console" "steam" "xbox" "playstation" "nintendo" "pc gaming") declare -A gamingLevels=( [10]="Casual Gamer" @@ -42,7 +45,7 @@ declare -A gamingLevels=( ) # Words that trigger tracking for drugs category -drugsWords=("kratom" "gummy" "hemp" "nicotine") +drugsWords=("kratom" "gummy" "hemp" "nicotine" "vape") # Level thresholds and reward names for drugs category # Array key is the threshold (word count needed), value is the level name diff --git a/triggers/wordtrack/wordtrack.sh b/triggers/wordtrack/wordtrack.sh index 4afc941..40b9933 100755 --- a/triggers/wordtrack/wordtrack.sh +++ b/triggers/wordtrack/wordtrack.sh @@ -69,10 +69,48 @@ for category in "${categories[@]}"; do # Count all occurrences of this word in the message wordLower="${word,,}" tempMessage="$messageLower" - while [[ "$tempMessage" =~ $wordLower ]]; do + + # Parse wildcard markers to determine match type + # * prefix = allow match at end of larger word (e.g., *game matches endgame) + # * suffix = allow match at start of larger word (e.g., coffee* matches coffeehouse) + # both = allow match anywhere (e.g., *play* matches gameplay) + # none = exact word match only (e.g., tea only matches tea) + + prefixWild=false + suffixWild=false + + if [[ "$wordLower" == \** ]]; then + prefixWild=true + wordLower="${wordLower#\*}" + fi + + if [[ "$wordLower" == *\* ]]; then + suffixWild=true + wordLower="${wordLower%\*}" + fi + + # Build regex pattern based on wildcard markers + if $prefixWild && $suffixWild; then + # Match anywhere in text + pattern="$wordLower" + elif $prefixWild; then + # Match at end of word or standalone + pattern="$wordLower([[:space:][:punct:]]|$)" + elif $suffixWild; then + # Match at start of word or standalone + pattern="(^|[[:space:][:punct:]])$wordLower" + else + # Exact word match only + pattern="(^|[[:space:][:punct:]])$wordLower([[:space:][:punct:]]|$)" + fi + + # Use word boundary matching based on pattern + while [[ "$tempMessage" =~ $pattern ]]; do ((wordCount++)) # Remove the matched word to find more occurrences - tempMessage="${tempMessage/$wordLower/}" + # Use the actual matched portion to avoid removing partial matches + matchedWord="${BASH_REMATCH[0]}" + tempMessage="${tempMessage/"$matchedWord"/ }" done done