summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@fairlystable.org>2023-06-14 04:32:05 -0700
committerJoe Rayhawk <jrayhawk@fairlystable.org>2023-06-14 04:32:05 -0700
commitfe3ea5b7d7dc90f4bdbec4631a3b2f47e56dc2fa (patch)
treef40b3c37af99309c939d4c8ca7d9e6bb0c52d85c
parent47adaa9a252f82688eabbf6f18d9ddd786e1cb70 (diff)
downloadtwitchtools-fe3ea5b7d7dc90f4bdbec4631a3b2f47e56dc2fa.tar.gz
twitchtools-fe3ea5b7d7dc90f4bdbec4631a3b2f47e56dc2fa.zip
bash/colorize.sh new irc log colorization filter
-rwxr-xr-xbash/colorize.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/bash/colorize.sh b/bash/colorize.sh
new file mode 100755
index 0000000..519fa19
--- /dev/null
+++ b/bash/colorize.sh
@@ -0,0 +1,105 @@
+#!/bin/bash
+
+NAME=bungmonkey
+
+IFS=$'\n'
+
+set -f # disable pathname expansion out of an abundance of caution
+declare -A assArray
+
+colorword () {
+ WORD="$1"
+ if [ ${assArray["$WORD"]+_} ]; then
+ I="${assArray["$WORD"]}"
+ else
+ #I="$( crc32 <( echo "$WORD" ) | cut -f 1 -d ' ' )" # WHY IS THIS FUCKING PERL
+ I="$( echo "ff$WORD" | md5sum )"
+ I="${I:0:4}"
+
+ I="$(printf '%d' 0x"$I")"
+
+ I=$(( ( "$I" & 226 ) + 1 ))
+
+# I=$(( ( $RANDOM & 226 ) + 1 ))
+ #I=7
+ # Grayscales to exclude:
+ # 007, 008, 015, 016, 231-255
+
+ ( [ $I -ge 7 ] && [ $I -le 8 ] ) && ((I+=2))
+ ( [ $I -ge 15 ] && [ $I -le 16 ] ) && ((I+=2))
+ assArray["$WORD"]="$I"
+ fi
+
+ echo -ne "\033[38;5;${assArray["$WORD"]}m${WORD}\033[0m"
+# How to GC?
+# if [ ${#assArray[@]} -gt 10 ]; then
+# echo purging assArray
+# unset assArray
+# fi
+ return "$I"
+}
+
+while read -r line; do
+ # 11:39 < bungmonkey> test test
+ if [[ "$line" =~ ^([0-9]{2}:[0-9]{2})\ \<(.)([0-9a-zA-Z_]+)\>\ (.*+)$ ]] ; then
+ TIME="${BASH_REMATCH[1]}"
+ MOD="${BASH_REMATCH[2]}"
+ NAME="${BASH_REMATCH[3]}"
+ MSG="${BASH_REMATCH[4]}"
+ #echo "$TIME $NAME $MSG"
+ echo -n "$TIME "
+ echo -ne "\033[38;5;8m<\033[0m"
+ echo -ne "$MOD"
+ colorword "$NAME"
+ COLOR="$?"
+ echo -ne "\033[38;5;8m>\033[0m\033[38;5;${COLOR}m"
+ IFS=" "
+ while read -r word; do
+ if [[ "$word" =~ ^[a-z0-9]+[A-Z][a-zA-Z0-9]+$ ]] ; then
+ echo -ne " \033[0m"
+ echo -n "$word"
+ echo -ne "\033[38;5;${COLOR}m"
+ # FIXME: why does @ break here?
+ #elif [[ "$word" =~ ^@([a-zA-Z0-9_]+) ]]; then
+ # echo -ne " \033[0m@"
+ # colorword "${BASH_REMATCH[1]}"
+ # echo -ne "\033[38;5;${COLOR}m"
+ else
+ echo -n " $word"
+ fi
+ done < <( echo "$MSG" )
+ IFS=$'\n'
+ echo -e "\033[0m"
+ # 11:28 -!- cokedrips69 [cokedrips69@cokedrips69.tmi.twitch.tv] has left #bungmonkey []
+ elif [[ "$line" =~ ^([0-9]{2}:[0-9]{2})\ -!-\ ([0-9a-zA-Z_]+)\ \[([0-9a-zA-Z_]+)@([0-9a-zA-Z_.]+)\]\ has\ ([a-zA-Z]+)\ ([#a-zA-Z0-9_-]+)(\ |)(\[(.*)\]|) ]]; then
+ TIME="${BASH_REMATCH[1]}"
+ NAME="${BASH_REMATCH[2]}"
+ LOCAL="${BASH_REMATCH[3]}"
+ HOST="${BASH_REMATCH[4]}"
+ STATE="${BASH_REMATCH[5]}"
+ ROOM="${BASH_REMATCH[6]}"
+ REASON="${BASH_REMATCH[9]}"
+ # remove some noise
+ if [ "$NAME" == "$LOCAL" ] && [ "$NAME".tmi.twitch.tv == "$HOST" ] ; then
+ LOCAL=""
+ HOST="irc.chat.twitch.tv"
+ fi
+ echo -n "$TIME "
+ echo -ne "\033[38;5;12m-\033[0m!\033[38;5;12m-\033[0m "
+ colorword "$NAME"
+ echo -ne " \033[38;5;8"
+ echo -n "[$LOCAL@$HOST]"
+ echo -ne "\033[0m has "
+ colorword "$STATE"
+ echo -n " "
+ colorword "$ROOM"
+ if [ "x$REASON" != "x" ]; then
+ echo -ne "\033[38;5;8m[\033[0m"
+ echo -n "$REASON"
+ echo -ne "\033[38;5;8m]\033[0m"
+ fi
+ echo
+ else
+ echo "$line"
+ fi
+done