#!/bin/dash

# gets executed each time dunst receives a notification

# ignore some apps
if echo "$2" | grep -q 'instantASSIST'; then
    exit
fi

if ! echo "$1" | grep -Eiq '(discord|spotify|thunderbird|mailspring)'; then
    if ! [ -e ~/instantos/notifications/notification.ogg ]; then
        if ping -c 1 google.com; then
            mkdir -p ~/instantos/notifications/
            wget -qO ~/instantos/notifications/notification.ogg \
                "https://notificationsounds.com/notification-sounds/me-too-603/download/ogg"
        else
            exit
        fi
    fi
    mpv ~/instantos/notifications/notification.ogg
fi

# escape characters that cause problems with pango
# some apps dont need/already have notification sounds
cleanstring() {
    echo "$@" | sed 's/&/&amp;/g'
}

# add pango markup
echo "($(date +%H:%M)) [$(cleanstring $1)] <b>$(cleanstring $2)</b> | <i>$(cleanstring $3)</i>" >>/tmp/notifications/notif.txt
