From da716ad9473c8608d4e6bb31b1958c9717f5cdf1 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 20 Sep 2011 10:39:41 -0500 Subject: [PATCH 1/5] fix a run bug --- cobalt/handler | 16 ++++++++++++++++ run | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cobalt/handler b/cobalt/handler index d1f975d..46a0a1b 100755 --- a/cobalt/handler +++ b/cobalt/handler @@ -19,6 +19,21 @@ 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 @@ -33,6 +48,7 @@ case $command in PRIVMSG) case "$forum" in \#*) + cobalt "$text" || \ $ircdir/firebot "$text" || \ $ircdir/whuffie $botdir/whuffie.cdb "$text" || \ $ircdir/infobot $botdir/factoids.cdb "$text" diff --git a/run b/run index c4ad2f6..477a8f4 100755 --- a/run +++ b/run @@ -11,6 +11,6 @@ if [ ! -d "$botdir" ]; then fi while true; do - $botdir/connect $d/connect-handler $botdir + $botdir/connect $ircdir/connect-handler $botdir sleep 5 -done \ No newline at end of file +done From dc9f49e3507bc0f471de1b8c4ed105b2d5797cbd Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 20 Sep 2011 11:08:14 -0500 Subject: [PATCH 2/5] make notes case-insensitive --- notes | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/notes b/notes index db99ed8..4baeb4f 100755 --- a/notes +++ b/notes @@ -3,6 +3,11 @@ 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 @@ -12,7 +17,7 @@ fi case "$text" in note\ *) args=${text#note } - who=${args%% *} + who=$(lc "${args%% *}") what=${args#* } when=$(date) From 491c65415c400477bea98bcf6923bdf7a4b35912 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 6 Jan 2012 17:14:45 -0600 Subject: [PATCH 3/5] fix forum for privmsg --- Makefile | 2 +- connect-handler | 2 +- irc.c => irc-filter.c | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) rename irc.c => irc-filter.c (87%) diff --git a/Makefile b/Makefile index d2cc6a3..852645c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CFLAGS = -Wall -Werror -TARGETS = dispatch irc +TARGETS = dispatch irc-filter all: $(TARGETS) diff --git a/connect-handler b/connect-handler index a58fbf9..ecbe8e8 100755 --- a/connect-handler +++ b/connect-handler @@ -17,4 +17,4 @@ if [ -p $botdir/fifo ]; then fifo="-f $botdir/fifo" fi -exec $ircdir/dispatch $fifo $ircdir/irc $botdir/handler +exec $ircdir/dispatch $fifo $ircdir/irc-filter $botdir/handler diff --git a/irc.c b/irc-filter.c similarity index 87% rename from irc.c rename to irc-filter.c index 6601253..d297460 100644 --- a/irc.c +++ b/irc-filter.c @@ -92,11 +92,23 @@ main(int argc, char *argv[]) /* Determine forum */ if ((0 == strcmp(cmd, "PRIVMSG")) || - (0 == strcmp(cmd, "NOTICE")) || - (0 == strcmp(cmd, "PART")) || - (0 == strcmp(cmd, "MODE")) || - (0 == strcmp(cmd, "TOPIC")) || - (0 == strcmp(cmd, "KICK"))) { + (0 == strcmp(cmd, "NOTICE"))) { + /* :neale!user@127.0.0.1 PRIVMSG #hydra :foo */ + switch (parts[1][0]) { + case '#': + case '&': + case '+': + case '!': + forum = parts[1]; + break; + default: + forum = snick; + break; + } + } else if ((0 == strcmp(cmd, "PART")) || + (0 == strcmp(cmd, "MODE")) || + (0 == strcmp(cmd, "TOPIC")) || + (0 == strcmp(cmd, "KICK"))) { forum = parts[1]; } else if (0 == strcmp(cmd, "JOIN")) { if (0 == nparts) { From 086e09927a4369cd6e122ee99e6138b25ffbcecb Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 6 Jan 2012 23:19:49 -0700 Subject: [PATCH 4/5] Converter from IRC escape codes to ANSI ones --- Makefile | 2 +- irc-esc.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 irc-esc.c diff --git a/Makefile b/Makefile index 852645c..f59eb11 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CFLAGS = -Wall -Werror -TARGETS = dispatch irc-filter +TARGETS = dispatch irc-filter irc-esc all: $(TARGETS) diff --git a/irc-esc.c b/irc-esc.c new file mode 100644 index 0000000..64ae11a --- /dev/null +++ b/irc-esc.c @@ -0,0 +1,118 @@ +#include + +enum { + RESET, + COLOR, + NOCOLOR, + BOLD, + UNDERLINE, + INVERSE +}; + +int color_map[] = {7, 0, 4, 2, 1, 1, 5, 3, 3, 2, 6, 6, 4, 5, 0, 7}; + +void +change_state(int what, int foreground, int background) +{ + static int bf = 0; + static int ul = 0; + static int rv = 0; + static int fg = -1; + static int bg = -1; + + switch (what) { + case RESET: + fg = -1; + bg = -1; + bf = 0; + ul = 0; + rv = 0; + break; + case COLOR: + fg = (foreground<16)?color_map[foreground]:-1; + bg = (background<16)?color_map[background]:-1; + break; + case NOCOLOR: + fg = -1; + bg = -1; + break; + case BOLD: + bf = !bf; + break; + case UNDERLINE: + ul = !ul; + break; + case INVERSE: + rv = !rv; + break; + } + + printf("\033[0"); + if (bf) printf(";1"); + if (ul) printf(";4"); + if (rv) printf(";7"); + if (0 <= fg) printf(";3%d", fg); + if (0 <= bg) printf(";4%d", bg); + printf("m"); +} + +int +read_num() +{ + int acc = 0; + int fail = 1; + + while (1) { + int c = getchar(); + + if ((c >= '0') && (c <= '9')) { + acc = (acc * 10) + (c - '0'); + } else { + ungetc(c, stdin); + break; + } + fail = 0; + } + return fail?-1:acc; +} + +int +main(int argc, char *argv[]) +{ + while (! feof(stdin)) { + int c = getchar(); + + if (EOF == c) { + break; + } else if (0 == c) { + printf("\\0"); + } else if (3 == c) { /* mIRC color */ + int fg = read_num(); + int bg = -1; + + c = getchar(); + if (',' == c) { + bg = read_num(); + } else { + ungetc(c, stdin); + } + change_state(COLOR, fg, bg); + } else if (2 == c) { + change_state(BOLD, 0, 0); + } else if (22 == c) { + change_state(INVERSE, 0, 0); + } else if (31 == c) { + change_state(UNDERLINE, 0, 0); + } else if (15 == c) { /* mIRC reset everything */ + change_state(RESET, 0, 0); + } else if ('\n' == c) { + change_state(RESET, 0, 0); + putchar(c); + } else if (32 > c) { + printf("^%c", c + 'A' - 1); + } else { + putchar(c); + } + } + change_state(RESET, 0, 0); +} From ffa7d6424957e9ac3e478de52c39d03fedb412d7 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 6 Jan 2012 23:32:38 -0700 Subject: [PATCH 5/5] remove extraneous comment --- irc-esc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irc-esc.c b/irc-esc.c index 64ae11a..26733d9 100644 --- a/irc-esc.c +++ b/irc-esc.c @@ -103,7 +103,7 @@ main(int argc, char *argv[]) change_state(INVERSE, 0, 0); } else if (31 == c) { change_state(UNDERLINE, 0, 0); - } else if (15 == c) { /* mIRC reset everything */ + } else if (15 == c) { change_state(RESET, 0, 0); } else if ('\n' == c) { change_state(RESET, 0, 0);