Finished the Poezio notification script. It works! Might make sure there aren't any weird edge cases later.

This commit is contained in:
Olivier Poirier 2023-12-06 04:19:26 -06:00
parent 68f26c1d1d
commit ec983470b3
3 changed files with 79 additions and 13 deletions

74
primitives/poezio-notify Executable file
View File

@ -0,0 +1,74 @@
#!/bin/sh
# This reads in Poezio messages from stdin and displays them as notifications.
# Still have to add some features, namely displaying icons for nicknames
Newline='
'
findicon () {
if [ "$1" != "" ] ; then
ICON_DIR="$HOME/.cache/poezio/avatars"
if [ "$(ls $ICON_DIR | grep $1)" != "" ] ; then
echo "$ICON_DIR/$1/$(ls -t $ICON_DIR/$1 | tail -n 1)"
fi
fi
}
MY_JID="$(sed -n "/^jid = /p" $HOME/.config/poezio/poezio.cfg | sed 's/jid[ ]*=[ ]*//')"
echo "Current user is $MY_JID, ignoring messages from this origin"
while read -r INPUT ; do
if [ "$(echo "$INPUT"^| sed '/^==> .* <==.*$/d')" = "" ] ; then
JID="$(echo $INPUT | sed -e 's/^==> //' -e 's/.<==$//' -e 's/\t/\\t/g' -e 's/\a/\\a/g' -e 's/.*\///')"
JID_ICON="$(findicon $JID)"
MY_NICK="$(grep -a You.*joined\ the\ room "$HOME/.local/share/poezio/logs/$JID" | tail -n 1 | sed -e 's/^[^(]*(//' -e 's/)[^)]*$//')"
if [ "$MY_NICK" != "" ] ; then echo "My nick in $JID is: $MY_NICK" ; fi
elif [ "$INPUT" != "" ] ; then
if [ "$JID" = "" ] ; then JID="Unknown\ Room" ; fi
if [ "$(echo $INPUT | sed -e '/^[^M][^A-Z]/d')" = "" ] ; then
if [ -z $NOCONT ] ; then
HEADER="Continued Message..."
CONTENT="$INPUT"
else
CONTENT=""
fi
elif [ "$(echo $INPUT | sed -e '/^[M][I]/d')" = "" ] ; then
unset NICK
HEADER="Poezio"
CONTENT="$(echo $INPUT | sed 's/^[^ ]*.[^ ]*.[^ ]*.//')"
if [ "$(echo $CONTENT | sed '/^--->/d')" = "" ] ; then
HEADER="$HEADER - Join in $JID"
CONTENT="$(echo $CONTENT | sed -e 's/^.....//')"
elif [ "$(echo $CONTENT | sed '/^-!-/d')" = "" ] ; then
HEADER="$HEADER - Notice in $JID"
CONTENT="$(echo $CONTENT | sed 's/^....//')"
elif [ "$(echo $CONTENT | sed '/^<---/d')" = "" ] ; then
HEADER="$HEADER - Leave in $JID"
CONTENT="$(echo $CONTENT | sed 's/^.....//')"
fi
elif [ "$(echo $INPUT | sed -e '/^[M][R]/d')" = "" ] ; then
NICK="$(echo $INPUT | sed -e 's/^[^<]*<//' -e 's/>.*$//' )"
NICK_ICON="$(findicon $NICK_ICON)"
HEADER="$NICK in $JID"
CONTENT="$(echo $INPUT | sed 's/^[^ ]*.[^ ]*.[^ ]*.//')"
else
HEADER="Poezio"
CONTENT="$(echo $INPUT | sed 's/^[^ ]*.[^ ]*.[^ ]*.//')"
fi
NICK_JID="$(grep -a "$NICK.*joined\ the\ room" "$HOME/.local/share/poezio/logs/$JID" | tail -n 1 | sed -e 's/^[^(]*(//' -e 's/)[^)]*$//' -e 's/\/.*//')"
NICK_ICON="$(findicon $NICK_JID)"
if [ "$NICK_ICON" != "" ] ; then
ICON="$NICK_ICON"
elif [ "$JID_ICON" != "" ] ; then
ICON="$JID_ICON"
else
ICON="$HOME/.local/share/.poezio-icon.png"
fi
if [ "$JID" != "$MY_JID" ] && [ "$NICK" != "$MY_NICK" ] && [ "$CONTENT" != "" ] ; then
CONTENT="$(echo $CONTENT | sed -e 's/-/\\-/g' -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g')"
notify-send -a "Poezio" -i "$ICON" "$HEADER" "$CONTENT"
unset NOCONT
else
NOCONT=1
fi
fi
done

View File

@ -1,15 +1,4 @@
#!/bin/sh
# Tracks Poezio logfiles. Still a work-in-progress.
# It would be better to have one tail aggregating all of the different files into one notification stream.
# Requires: <program> <package (Devuan)>
# tail coreutils
# ls coreutils
# grep grep
# sed sed
# Tracks Poezio logfiles. Reads them from the standard location.
FIFO="$(tail -qf .local/share/poezio/logs/* | pipetofifo $(attfifo poezio))"
# I need to read from this file and do a few specific things.
# I need a script to automatically fetch avatar locations based on a JID, if available.
# I need a script to search in logs for JID-to-temporary-username associations.
# Let's test notify-send.
tail -fn 0 ~/.local/share/poezio/logs/* | poezio-notify

3
primitives/taildog Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# Tail crashes upon retrying a read on a FIFO. We need to continually read the FIFO in a watchdog loop due to this.
while true ; do tail -Fn 0 "$1" 2>/dev/null ; done