diff --git a/README.md b/README.md index 89d5885..80dc40a 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,8 @@ IRC Bot This is a super simple IRC bot that can send out notices by talking to it via netcat. + +## Running +Modify the parameters in the shell scripts and you're good to go. + +[irc-say](irc-say) is a convenient program that you can use in other scripts. diff --git a/irc-bot b/irc-bot new file mode 100755 index 0000000..05894d1 --- /dev/null +++ b/irc-bot @@ -0,0 +1,37 @@ +#!/bin/bash + +# Super simple IRC bot. +# +# Note: Requires the OpenBSD version of netcat! + +NICK="bitlair-space" +CHANNEL="#bitlair-test" +SERVER="irc.smurfnet.ch" +INPORT="31337" + +loop="/tmp/irc-bot-loop" +mkfifo "$loop" +trap "rm -f $loop" INT TERM EXIT + +{ +echo "NICK $NICK" +sleep 0.2 +echo "USER $NICK +i * :$0" +sleep 6 +echo "JOIN $CHANNEL" + +# FIXME: Possible race condition between loop and stdin. +tail -f "$loop" & + +nc -6 -k -lp "$INPORT" | while read line; do + echo "NOTICE $CHANNEL $line" +done +} | \ +nc "$SERVER" 6667 | while read message; do + case "$message" in + PING*) echo "PONG ${message#PING :}" | tee "$loop";; + ERROR*) echo "$message"; exit;; + *PRIVMSG*) echo "${message}" | sed -nr "s/^:([^!]+).*PRIVMSG[^:]+:(.*)/[$(date '+%R')] <\1> \2/p";; + *) echo "${message}";; + esac +done diff --git a/irc-say b/irc-say new file mode 100755 index 0000000..b1dfc81 --- /dev/null +++ b/irc-say @@ -0,0 +1,11 @@ +#!/bin/bash + +HOST=127.0.0.1 +PORT=31337 + +if [ $# -eq 0 ]; then + echo "Usage: $0 ..." + exit +fi + +echo "$*" | nc "$HOST" "$PORT"