From 12d1b626a879f0475b8175abbf1ddf4602ceb9df Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 9 Jun 2011 22:27:24 -0500 Subject: [PATCH] Change to bot directories --- README | 19 ++++++++----------- bot | 22 ++++++++++++++++------ cobalt | 6 ------ cobalt/channels/#woozle | 0 cobalt/connect | 3 +++ cobalt-handler => cobalt/handler | 17 +++++++++-------- cobalt/login | 4 ++++ connect-handler | 20 ++++++++++++++++++++ infobot | 2 ++ run | 16 ++++++++++++++++ 10 files changed, 78 insertions(+), 31 deletions(-) delete mode 100755 cobalt create mode 100644 cobalt/channels/#woozle create mode 100755 cobalt/connect rename cobalt-handler => cobalt/handler (68%) create mode 100755 cobalt/login create mode 100755 connect-handler create mode 100755 run diff --git a/README b/README index d74b424..c028077 100644 --- a/README +++ b/README @@ -29,18 +29,15 @@ specified program with these as arguments. Also responds to server pings as a convenience. -bot +run --- -Given nickname $nick, creates $nick.fifo, logs into IRC as $nick, and -passes control to dispatch -> irc -> $nick-handler. +[run BOTDIR] will run the bot contained in $BOTDIR. It should contain +the following files (see cobalt in the distribution for examples): - -cobalt-handler --------------- - -Joins initial channels, responds to invite messages, and tries private -messages with several different handlers in turn. +* connect : program to open connection +* login : program to log in to IRC +* handler : program to handle IRC messages firebot @@ -75,11 +72,11 @@ Putting it all together A full chain of programs would look something like - tcpclient -> bot -> dispatch -> handler + tcpclient -> connect-handler -> dispatch -> handler and would be invoked as - $ tcpclient irc.host.org 6667 ./bot cobalt + $ tcpclient irc.host.org 6667 ./connect-handler cobalt Author diff --git a/bot b/bot index 585c9e9..491bb9e 100755 --- a/bot +++ b/bot @@ -1,14 +1,24 @@ -#! /bin/sh +#! /bin/sh -e -nickname=$1; export nickname +botdir=$1 +d=$(dirname $0) + +nickname=$(cat $botdir/nickname) +realname=$(cat $botdir/realname 2>/dev/null || \ + echo "I'm a little printf, short and stdout.") +export nickname realname ( # UCSPI wants input on FD 7, and sets $PROTO [ -n "$PROTO" ] && exec 1>&7 - echo "NICK $1" - echo "USER $1 $1 $1 :I'm a little printf, short and stdout." + if [ -x $botdir/login ]; then + $botdir/login + else + echo "NICK $nickname" + echo "USER $nickname $nickname $nickname :$realname" + fi ) -mkfifo -m 0600 $1.fifo +mkfifo -m 0600 $botdir/fifo -exec ./dispatch -f $1.fifo ./irc ./$1-handler +exec $d/dispatch -f $botdir/fifo $d/irc $botdir/handler diff --git a/cobalt b/cobalt deleted file mode 100755 index 8b5819c..0000000 --- a/cobalt +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/sh - -while true; do - tcpclient woozle.org 6667 ./bot cobalt - sleep 5 -done diff --git a/cobalt/channels/#woozle b/cobalt/channels/#woozle new file mode 100644 index 0000000..e69de29 diff --git a/cobalt/connect b/cobalt/connect new file mode 100755 index 0000000..699652e --- /dev/null +++ b/cobalt/connect @@ -0,0 +1,3 @@ +#! /bin/sh + +exec socat OPENSSL:127.0.0.1:6697,verify=0,keepalive EXEC:"$*" diff --git a/cobalt-handler b/cobalt/handler similarity index 68% rename from cobalt-handler rename to cobalt/handler index c65822c..d1f975d 100755 --- a/cobalt-handler +++ b/cobalt/handler @@ -8,7 +8,7 @@ text=$1; export text; shift # $* is now args # Debug output -echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2 +#echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2 raw () { fmt="\007$1\n"; shift @@ -23,26 +23,27 @@ out=$(tempfile) case $command in 001) - for chan in ${CHANNELS:-#cobalt}; do - join $chan + for i in $botdir/channels/*; do + join $(basename $i) done ;; 433) - raw "NICK bottimus" + raw "NICK bot_$(shuf -c 1 /usr/share/dict/words)" ;; PRIVMSG) case "$forum" in \#*) - ./firebot "$text" || \ - ./whuffie woozle/whuffie.cdb "$text" || \ - ./infobot woozle/factoids.cdb "$text" - ./notes woozle/notes "$text" + $ircdir/firebot "$text" || \ + $ircdir/whuffie $botdir/whuffie.cdb "$text" || \ + $ircdir/infobot $botdir/factoids.cdb "$text" ;; esac + $ircdir/notes $botdir/notes "$text" ;; INVITE) join "$forum" raw "PRIVMSG %s :Thanks for the invitation, %s." "$forum" "$sender" + touch $botdir/channels/$forum ;; esac > $out diff --git a/cobalt/login b/cobalt/login new file mode 100755 index 0000000..558824c --- /dev/null +++ b/cobalt/login @@ -0,0 +1,4 @@ +#! /bin/sh + +echo "NICK cobalt" +echo "USER cobalt cobalt cobalt :I'm a little printf, short and stdout." diff --git a/connect-handler b/connect-handler new file mode 100755 index 0000000..a58fbf9 --- /dev/null +++ b/connect-handler @@ -0,0 +1,20 @@ +#! /bin/sh -e + +botdir=$1 +ircdir=$(dirname $0) +export botdir ircdir + +# UCSPI wants communication on fd7 +if [ -n "$PROTO" ]; then + fd=7 +else + fd=1 +fi + +$botdir/login 1>& $fd + +if [ -p $botdir/fifo ]; then + fifo="-f $botdir/fifo" +fi + +exec $ircdir/dispatch $fifo $ircdir/irc $botdir/handler diff --git a/infobot b/infobot index 3f0b742..99884f0 100755 --- a/infobot +++ b/infobot @@ -3,6 +3,8 @@ db=$1; shift text="$1" +[ -f $db ] || echo | cdb -c $db + lookup () { if ! cdb -q -m $db "$1"; then t="$1" diff --git a/run b/run new file mode 100755 index 0000000..c4ad2f6 --- /dev/null +++ b/run @@ -0,0 +1,16 @@ +#! /bin/sh -e + +botdir=$1 +ircdir=$(dirname $0) +export botdir ircdir + +if [ ! -d "$botdir" ]; then + exec 1>&2 + echo "Usage: $0 BOTDIRECTORY" + exit 1 +fi + +while true; do + $botdir/connect $d/connect-handler $botdir + sleep 5 +done \ No newline at end of file