diff --git a/.gitignore b/.gitignore index 49316e3..e58f166 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ *.o dispatch -irc +irc-filter +irc-esc diff --git a/bot b/bot deleted file mode 100755 index 491bb9e..0000000 --- a/bot +++ /dev/null @@ -1,24 +0,0 @@ -#! /bin/sh -e - -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 - if [ -x $botdir/login ]; then - $botdir/login - else - echo "NICK $nickname" - echo "USER $nickname $nickname $nickname :$realname" - fi -) - -mkfifo -m 0600 $botdir/fifo - -exec $d/dispatch -f $botdir/fifo $d/irc $botdir/handler diff --git a/cobalt/channels/#woozle b/cobalt/channels/#woozle deleted file mode 100644 index e69de29..0000000 diff --git a/cobalt/connect b/cobalt/connect deleted file mode 100755 index 699652e..0000000 --- a/cobalt/connect +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -exec socat OPENSSL:127.0.0.1:6697,verify=0,keepalive EXEC:"$*" diff --git a/cobalt/handler b/cobalt/handler deleted file mode 100755 index 46a0a1b..0000000 --- a/cobalt/handler +++ /dev/null @@ -1,83 +0,0 @@ -#! /bin/sh - -prefix=$1; export prefix; shift -command=$1; export command; shift -sender=$1; export sender; shift -forum=$1; export forum; shift -text=$1; export text; shift -# $* is now args - -# Debug output -#echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2 - -raw () { - fmt="\007$1\n"; shift - printf "$fmt" "$@" -} - -join () { - raw "JOIN $1" -} - -cobalt () { - case "$1" in - air) - w3m -dump -cols 9999 'http://environweb.lanl.gov/Teom/teom30s.asp?MasterSiteID=211&offset=0' 2> /dev/null | \ - awk '/.:..:.. .M/ {print "Los Alamos Air: " $5 "μg/m³ at " $2; exit}' - ;; - nachos) - echo "aieeeee" - ;; - *) - return 1 - ;; - esac -} - -out=$(tempfile) - -case $command in - 001) - for i in $botdir/channels/*; do - join $(basename $i) - done - ;; - 433) - raw "NICK bot_$(shuf -c 1 /usr/share/dict/words)" - ;; - PRIVMSG) - case "$forum" in - \#*) - cobalt "$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 - -if [ "$forum" != "$sender" ] && [ $(wc -l < $out) -gt 5 ]; then - printf "PRIVMSG %s :Too many lines, sending privately.\r\n" "$forum" - forum=$sender -fi - -while read -r line; do - case "$line" in - *) - printf "%s\r\n" "${line#}" - ;; - *) - printf "PRIVMSG %s :%s\r\n" "$forum" "$line" - ;; - esac -done < $out - -rm -f $out - diff --git a/cobalt/login b/cobalt/login deleted file mode 100755 index 558824c..0000000 --- a/cobalt/login +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/sh - -echo "NICK cobalt" -echo "USER cobalt cobalt cobalt :I'm a little printf, short and stdout." diff --git a/connect b/connect new file mode 100755 index 0000000..fa8fa97 --- /dev/null +++ b/connect @@ -0,0 +1,3 @@ +#! /bin/sh + +exec socat TCP:"$server":6667 EXEC:"$*" diff --git a/connect-handler b/connect-handler index ecbe8e8..985d83f 100755 --- a/connect-handler +++ b/connect-handler @@ -1,9 +1,5 @@ #! /bin/sh -e -botdir=$1 -ircdir=$(dirname $0) -export botdir ircdir - # UCSPI wants communication on fd7 if [ -n "$PROTO" ]; then fd=7 @@ -11,10 +7,12 @@ else fd=1 fi -$botdir/login 1>& $fd +# Kick things off by logging in +if [ -x "$srvdir/login" ]; then + $srvdir/login +else + echo NICK $nick + echo USER $nick $nick $nick :$nick +fi 1>& $fd -if [ -p $botdir/fifo ]; then - fifo="-f $botdir/fifo" -fi - -exec $ircdir/dispatch $fifo $ircdir/irc-filter $botdir/handler +exec $ircdir/dispatch -f fifo $ircdir/irc-filter $ircdir/handler diff --git a/firebot b/firebot deleted file mode 100755 index 4567d53..0000000 --- a/firebot +++ /dev/null @@ -1,23 +0,0 @@ -#! /bin/sh - -exec 2>&1 - -cmd=${1%% *} -[ "$cmd" = "$1" ] || args=${1#* } -case $cmd in - calc) - printf "%s = " "$args" - echo "$args" | bc -l - ;; - units) - src=$(printf "%s" "$args" | sed 's/ ->.*//') - dst=$(printf "%s" "$args" | sed 's/.*-> //') - units -1 -v -- "$src" "$dst" - ;; - *) - exit 1 - ;; -esac - - - diff --git a/handler b/handler new file mode 100755 index 0000000..2da5bab --- /dev/null +++ b/handler @@ -0,0 +1,55 @@ +#! /bin/sh + +prefix=$1; export prefix; shift +command=$1; export command; shift +sender=$1; export sender; shift +forum=$1; export forum; shift +text=$1; export text; shift +# $* is now args + +mkdir -p $srvdir/$forum + +now=$(date '+%Y-%m-%d %H:%M'); export now +( + flock 3 + for h in $srvdir/handler $srvdir/$forum/handler; do + [ -x $h ] && $h "$@" + done + + [ -x $srvdir/$command-hook ] && $srvdir/$command-hook + + case $command in + PING) + ;; + 001) + for chan in \#* \&* \+*; do + if [ -d "$chan" ]; then + echo "JOIN $chan" + fi + done + ;; + 433) + echo "NICK u$$" + ;; + PRIVMSG) + case "$text" in + "ACTION "*) + txt=${text#ACTION } + txt=${txt%} + echo "$now * $sender $txt" 1>&3 + ;; + *) + txt=${text#} + txt=${txt%} + echo "$now - $sender CTCP $txt" 1>&3 + ;; + *) + echo "$now <$sender> $text" 1>&3 + ;; + esac + ;; + *) + echo "$now" ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&3 + ;; + esac +) 3>> $srvdir/${forum:-.}/log diff --git a/infobot b/infobot deleted file mode 100755 index 99884f0..0000000 --- a/infobot +++ /dev/null @@ -1,90 +0,0 @@ -#! /bin/sh - -db=$1; shift -text="$1" - -[ -f $db ] || echo | cdb -c $db - -lookup () { - if ! cdb -q -m $db "$1"; then - t="$1" - while [ "$t" != "$n" ]; do - n=$t - t=${n%[?!. ]} - done - if [ "$t" != "$1" ]; then - cdb -q -m $db "$t" - fi - fi -} - -db_append () { - (printf "+%d,%d:%s->%s\n" ${#1} ${#2} "$1" "$2"; cdb -d $db) | cdb -c $db - echo "Okay, $sender, I added a factoid to $1." -} - -nickname=${nickname:-infobot} -args=${text#* } - -case "$text" in - !h*) - cat <.*$val" | cdb -c $db - echo "Okay, $sender, I removed $n factoids from $key" - else - echo "Nothing matched, $sender." - fi - ;; - !forget\ *) - cdb -d $db | grep -a -F -v ":$args->" | cdb -c $db - echo "I removed all factoids from $args" - ;; - *) - resp=$(lookup "$text" | shuf -n 1 | sed "s/\$sender/$sender/") - case "$resp" in - "") - exit 1 - ;; - ''*) - echo "Someone's up to no good!" - ;; - '\'*) - printf "%s\n" "${resp#\\}" - ;; - :*) - printf '\001ACTION %s\001\n' "${resp#:}" - ;; - *) - echo "It's been said that $text is $resp" - ;; - esac - ;; -esac diff --git a/irc b/irc new file mode 100755 index 0000000..246c326 --- /dev/null +++ b/irc @@ -0,0 +1,45 @@ +#! /bin/sh -e + +if [ $# -gt 1 ]; then + nick=$1 + shift +else + nick=$LOGNAME +fi +export nick + +if [ $# -ne 1 ]; then + exec 1>&2 + echo "Usage: $0 BOTDIRECTORY" + exit 1 +fi + +server=$1 +ircdir=$(cd $(dirname $0); pwd) +export server ircdir + +if [ -d "$server" ]; then + cd $server +else + mkdir -p $HOME/chat/$server + cd $HOME/chat/$server +fi +srvdir=$(pwd) +export srvdir + +mkdir -p $srvdir +if [ ! -p $srvdir/fifo ]; then + mkfifo $srvdir/fifo +fi + +if [ -x $srvdir/connect ]; then + connect=$srvdir/connect +else + connect=$ircdir/connect +fi + + +while true; do + $connect $ircdir/connect-handler $srvdir + sleep 5 +done diff --git a/m b/m new file mode 100755 index 0000000..794fc21 --- /dev/null +++ b/m @@ -0,0 +1,52 @@ +#! /bin/sh + +if [ ! -p ../fifo ]; then + echo "You need to be in a forum directory." + exit +fi + +forum=${PWD##*/} +nick=${nick:-?} + +privmsg () { + ( + flock 1 + now=$(date '+%Y-%m-%d %H:%M') + case "$1" in + //*) + printf "PRIVMSG %s :%s\n" "$forum" "${1#/}" > ../fifo + echo "$now <$nick> ${1#/}" + ;; + \:*) + printf "PRIVMSG %s :\001ACTION %s\001\n" "$forum" "${1#:}" > ../fifo + echo "$now * $nick ${1#:}" + ;; + /*) + cmd=${1%% *} + args=${1#* } + case "${1%% *}" in + /msg) + echo "PRIVMSG ${args%% *} :${args#* }" > ../fifo + ;; + *) + echo "${1#/}" > ../fifo + ;; + esac + ;; + *) + printf "PRIVMSG %s :%s\n" "$forum" "$1" > ../fifo + echo "$now <$nick> $1" + ;; + esac + ) >> log +} + +if [ "$*" ]; then + privmsg "$*" +else + while true; do + printf "$forum: " + read -r msg || break + privmsg "$msg" + done +fi diff --git a/notes b/notes deleted file mode 100755 index 4baeb4f..0000000 --- a/notes +++ /dev/null @@ -1,27 +0,0 @@ -#! /bin/sh - -db=$1; shift -text=$1 - -lc () { - printf "%s" "$1" | tr A-Z a-z -} - -sender=$(lc "$sender") -if [ -f $db/$sender ]; then - echo "Welcome back, $sender. Your messages:" - cat $db/$sender - rm $db/$sender -fi - -case "$text" in - note\ *) - args=${text#note } - who=$(lc "${args%% *}") - what=${args#* } - when=$(date) - - echo "($when) <$prefix> $what" >> $db/$who - echo "Okay, $sender, I've left $who a note." - ;; -esac diff --git a/rollforinitiative.py b/rollforinitiative.py deleted file mode 100755 index 16a04c2..0000000 --- a/rollforinitiative.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -import re -import sys -import random - -if __name__ == '__main__': - roll = sys.argv[1] - m = re.match('^(?P\d+)d(?P\d+)(x(?P\d+))?$', roll) - if m: - rolls = int(m.group('rolls')) - sides = int(m.group('sides')) - if m.group('multiplier'): - multiplier = int(m.group('multiplier')) - else: - multiplier = 1 - - dice = [] - acc = 0 - for i in range(rolls): - n = random.randint(1, sides) - dice.append(n) - acc += n - acc *= multiplier - if rolls > 1: - print '%s: %d %r' % (roll, acc, dice) - else: - print '%s: %d' % (roll, acc) - diff --git a/run b/run deleted file mode 100755 index 477a8f4..0000000 --- a/run +++ /dev/null @@ -1,16 +0,0 @@ -#! /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 $ircdir/connect-handler $botdir - sleep 5 -done diff --git a/whuffie b/whuffie deleted file mode 100755 index 7d25294..0000000 --- a/whuffie +++ /dev/null @@ -1,41 +0,0 @@ -#! /bin/sh - -db=$1; shift -text="$1" - -get () { - cdb -q $db "$1" || echo 0 -} - -put () { - (printf "+%d,%d:%s->%s\n" ${#1} ${#2} "$1" $2; - cdb -d $db) | cdb -c -u $db -} - -adj () { - who=${text%%$1$1*} - if [ "$who" = "$sender" ]; then - echo "Nice try, $sender." - else - put "$who" $(expr $(get "$who") $1 1) - fi -} - - -case "$text" in - whuffie\ *) - who=${text#whuffie } - amt=$(get "$who") - echo "$who has whuffie score of $amt" - ;; - *++|*++\ *) - adj + - ;; - *--|*--\ *) - adj - - ;; - *) - exit 1 - ;; -esac -