#!/bin/bash
#
# this code is released under the WTFPL
# rabbitear radio thing for konverstion

# TODO:
#   * Use ARGS to re-reverse the stream address with --long or
#     something

SERVER=$1
TARGET=$2
RANDOM=100

# nb: repace all blanks.
#bar=${foo// /.}

# nb: random number, not very random :(
# echo $((1 + RANDOM % 15))
# because RANDOM needs set first?

#=======Newer=======#
MYNAME_MSG="%C06what%C11is%C12my%C04name%C06...."
HELLO_MSG="%C06//%C07\%C01R%C02a%C03d%C04i%C05o%C06//%C07\ \
%C12=$C11o%C12^%C110%C12= %C04\sTReaM\ \
%C11[%C12ooo8%C11:%C12moc%C11.%C12tibbarytiruces%C11.%C12xobeulb%C13//%C11:\
%C13ptth%C11]\
%C04 %=-> %C10soNg%C04 %=-> %C01"
GOODBYE_MSG=" %C04<-=% <FIXME>: my Eyes Are Not Working."
HELLO_NON_DYSLEXIC_MSG="%C06//%C07\%C01R%C02a%C03d%C04i%C05o%C06//%C07\ \
%C12=$C11o%C12^%C110%C12= %C04\sTReaM\ \
%C11[%C12ooo8%C11:%C12moc%C11.%C12tibbarytiruces%C11.%C12xobeulb%C13//%C11:\
%C13ptth%C11]\
%C04 %=-> %C10soNg%C04 %=-> %C01"
HELLO_MSG="%C06//%C07\%C01R%C02a%C03d%C04i%C05o%C06//%C07\ \
%C12=$C11o%C12^%C110%C12= %C04\sTReaM\ \
%C11[%C12ooo8%C11:%C12moc%C11.%C12tibbarytiruces%C11.%C12xobeulb%C13//%C11:\
%C13ptth%C11]\
%C04 %=-> %C10soNg%C04 %=-> %C01"


#====Older====#
MPC_CURRENT=$(mpc current)
MPC_FANCY_CURRENT=$(mpc -f '[[02%artist% 02»03»» ]\
[03%album% 02»03»» ]%title%]|[%file%]' current)

#===Put It Together===#
MPC_FLATED_CURRENT="$(basename "$(mpc -f '[%file%]' current)")"

#====Pick Some Random Colors====#
# nb: this is suppose to be random 1-9 for each space seperated word,
#     but, instead RANDOM is picking 1-9 THEN EVER CHANGES!! why?
MPC_COLORS_CURRENT="${MPC_FLATED_CURRENT// /\ %C0$(echo $((1 + RANDOM % 9)))}"

# tryied with awk, didn't come out so well..
#MPC_LETTER_COLORS_CURRENT="$(echo "$MPC_COLORS_CURRENT" | awk '$1=$1' FS= OFS=" ")"
#MPC_AWK_CURRENT="rdm: $(rmd) ${MPC_FLATED_CURRENT// /\ %C0$(rdm)}"

# Logic
if [[ ! -z $MPC_CURRENT ]]; then
    qdbus org.kde.konversation /irc say $SERVER "$TARGET" \
        "/me ${HELLO_MSG}${MPC_COLORS_CURRENT}${GOODBYE_MSG}"
else
    qdbus org.kde.konversation /irc say $SERVER "$TARGET" \
        "/me is not listening to anything via mpd right now..."
fi

