#!/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