Change to bot directories

This commit is contained in:
Neale Pickett 2011-06-09 22:27:24 -05:00
parent 6a272b0b86
commit 12d1b626a8
10 changed files with 78 additions and 31 deletions

19
README
View File

@ -29,18 +29,15 @@ specified program with these as arguments. Also responds to server
pings as a convenience. pings as a convenience.
bot run
--- ---
Given nickname $nick, creates $nick.fifo, logs into IRC as $nick, and [run BOTDIR] will run the bot contained in $BOTDIR. It should contain
passes control to dispatch -> irc -> $nick-handler. the following files (see cobalt in the distribution for examples):
* connect : program to open connection
cobalt-handler * login : program to log in to IRC
-------------- * handler : program to handle IRC messages
Joins initial channels, responds to invite messages, and tries private
messages with several different handlers in turn.
firebot firebot
@ -75,11 +72,11 @@ Putting it all together
A full chain of programs would look something like A full chain of programs would look something like
tcpclient -> bot -> dispatch -> handler tcpclient -> connect-handler -> dispatch -> handler
and would be invoked as and would be invoked as
$ tcpclient irc.host.org 6667 ./bot cobalt $ tcpclient irc.host.org 6667 ./connect-handler cobalt
Author Author

22
bot
View File

@ -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 # UCSPI wants input on FD 7, and sets $PROTO
[ -n "$PROTO" ] && exec 1>&7 [ -n "$PROTO" ] && exec 1>&7
echo "NICK $1" if [ -x $botdir/login ]; then
echo "USER $1 $1 $1 :I'm a little printf, short and stdout." $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

6
cobalt
View File

@ -1,6 +0,0 @@
#! /bin/sh
while true; do
tcpclient woozle.org 6667 ./bot cobalt
sleep 5
done

0
cobalt/channels/#woozle Normal file
View File

3
cobalt/connect Executable file
View File

@ -0,0 +1,3 @@
#! /bin/sh
exec socat OPENSSL:127.0.0.1:6697,verify=0,keepalive EXEC:"$*"

View File

@ -8,7 +8,7 @@ text=$1; export text; shift
# $* is now args # $* is now args
# Debug output # Debug output
echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2 #echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2
raw () { raw () {
fmt="\007$1\n"; shift fmt="\007$1\n"; shift
@ -23,26 +23,27 @@ out=$(tempfile)
case $command in case $command in
001) 001)
for chan in ${CHANNELS:-#cobalt}; do for i in $botdir/channels/*; do
join $chan join $(basename $i)
done done
;; ;;
433) 433)
raw "NICK bottimus" raw "NICK bot_$(shuf -c 1 /usr/share/dict/words)"
;; ;;
PRIVMSG) PRIVMSG)
case "$forum" in case "$forum" in
\#*) \#*)
./firebot "$text" || \ $ircdir/firebot "$text" || \
./whuffie woozle/whuffie.cdb "$text" || \ $ircdir/whuffie $botdir/whuffie.cdb "$text" || \
./infobot woozle/factoids.cdb "$text" $ircdir/infobot $botdir/factoids.cdb "$text"
./notes woozle/notes "$text"
;; ;;
esac esac
$ircdir/notes $botdir/notes "$text"
;; ;;
INVITE) INVITE)
join "$forum" join "$forum"
raw "PRIVMSG %s :Thanks for the invitation, %s." "$forum" "$sender" raw "PRIVMSG %s :Thanks for the invitation, %s." "$forum" "$sender"
touch $botdir/channels/$forum
;; ;;
esac > $out esac > $out

4
cobalt/login Executable file
View File

@ -0,0 +1,4 @@
#! /bin/sh
echo "NICK cobalt"
echo "USER cobalt cobalt cobalt :I'm a little printf, short and stdout."

20
connect-handler Executable file
View File

@ -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

View File

@ -3,6 +3,8 @@
db=$1; shift db=$1; shift
text="$1" text="$1"
[ -f $db ] || echo | cdb -c $db
lookup () { lookup () {
if ! cdb -q -m $db "$1"; then if ! cdb -q -m $db "$1"; then
t="$1" t="$1"

16
run Executable file
View File

@ -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