Your own rss-irc chan 2010-09-05

This is my new invention to lose time (I've made an expertise about that).

The principle is simple: you have an irc chan with a bot and a simple command !rss. You pass the uri of a rss and it will be now monitored and display on this chan. I've made this to have a news oriented irc chan.

You'll need ii and rsstail. Set up the ii to put it on an irc chan (I've personally set up my own irc server).

Here is a script to launch and relaunch your ii:

#!/bin/bash

while true
do
    (sleep 7; echo "/j #mychan" > irc/irc.server.net/in) &
    ./ii \\
        -i "irc" \\
        -s "irc.server.net" \\
        -p "6667" \\
        -n "mybotname" \\
        -f "mybotname"
done

Once everything is in place here is the (dirty) script to add the !rss command.
But before, create a .while_cond file in the same directory where you'll place this script. This will help you kill a rsstail instance. Since this script launch the rsstail instance in a while true loop to make sure it won't be down, you have to use this mecanism to avoid the loop to start again. To kill a rsstail you have to write "false" in the .while_cond file then kill the chosen rsstail (don't forget to change .while_cond back after that).

#!/bin/bash

CHAN="#mychan"

# no line containing the messages of the bot
tail -n 0 -f path/to/$CHAN/out | grep -v --line-buffered "<mybotname>" | grep --line-buffered "\\>" | while read -r line
do
    printf '%s\\n'  "$line"
    message_text=`printf '%s\\n' "$line" | sed 's/.\\+> //'`
    case "$message_text" in
        !debug)
          echo "I HAZ NO BUGZ" >> path/to/$CHAN/in ;;
    !rss\\ *)
        temp=`printf '%s\\n' "$message_text" | sed 's/!rss \\?//'`
        echo "[new RSS] $temp"
        while true; do ./rsstail -u "$temp" -l -P -z -N -n 1 -i 60 >> path/to/$CHAN/in; if [ $(cat .while_cond) = "false" ]; then break; fi; done &
            ;;
    esac
done

One other detail: I have remove the carriage return between the title of a rss item and the link by hacking rsstail source code. This is somewhere at line 436. Yes, this is dirty but you should be accustomed now.

I hope you'll lose plenty of time with this script.