Merge branch 'master' of fozzie:projects/bot

This commit is contained in:
Neale Pickett 2012-05-02 11:44:56 -06:00
commit c0f8b1b88e
7 changed files with 161 additions and 10 deletions

View File

@ -1,5 +1,5 @@
CFLAGS = -Wall -Werror CFLAGS = -Wall -Werror
TARGETS = dispatch irc TARGETS = dispatch irc-filter irc-esc
all: $(TARGETS) all: $(TARGETS)

View File

@ -19,6 +19,21 @@ join () {
raw "JOIN $1" 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) out=$(tempfile)
case $command in case $command in
@ -33,6 +48,7 @@ case $command in
PRIVMSG) PRIVMSG)
case "$forum" in case "$forum" in
\#*) \#*)
cobalt "$text" || \
$ircdir/firebot "$text" || \ $ircdir/firebot "$text" || \
$ircdir/whuffie $botdir/whuffie.cdb "$text" || \ $ircdir/whuffie $botdir/whuffie.cdb "$text" || \
$ircdir/infobot $botdir/factoids.cdb "$text" $ircdir/infobot $botdir/factoids.cdb "$text"

View File

@ -17,4 +17,4 @@ if [ -p $botdir/fifo ]; then
fifo="-f $botdir/fifo" fifo="-f $botdir/fifo"
fi fi
exec $ircdir/dispatch $fifo $ircdir/irc $botdir/handler exec $ircdir/dispatch $fifo $ircdir/irc-filter $botdir/handler

118
irc-esc.c Normal file
View File

@ -0,0 +1,118 @@
#include <stdio.h>
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) {
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);
}

View File

@ -92,8 +92,20 @@ main(int argc, char *argv[])
/* Determine forum */ /* Determine forum */
if ((0 == strcmp(cmd, "PRIVMSG")) || if ((0 == strcmp(cmd, "PRIVMSG")) ||
(0 == strcmp(cmd, "NOTICE")) || (0 == strcmp(cmd, "NOTICE"))) {
(0 == strcmp(cmd, "PART")) || /* :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, "MODE")) ||
(0 == strcmp(cmd, "TOPIC")) || (0 == strcmp(cmd, "TOPIC")) ||
(0 == strcmp(cmd, "KICK"))) { (0 == strcmp(cmd, "KICK"))) {

7
notes
View File

@ -3,6 +3,11 @@
db=$1; shift db=$1; shift
text=$1 text=$1
lc () {
printf "%s" "$1" | tr A-Z a-z
}
sender=$(lc "$sender")
if [ -f $db/$sender ]; then if [ -f $db/$sender ]; then
echo "Welcome back, $sender. Your messages:" echo "Welcome back, $sender. Your messages:"
cat $db/$sender cat $db/$sender
@ -12,7 +17,7 @@ fi
case "$text" in case "$text" in
note\ *) note\ *)
args=${text#note } args=${text#note }
who=${args%% *} who=$(lc "${args%% *}")
what=${args#* } what=${args#* }
when=$(date) when=$(date)

2
run
View File

@ -11,6 +11,6 @@ if [ ! -d "$botdir" ]; then
fi fi
while true; do while true; do
$botdir/connect $d/connect-handler $botdir $botdir/connect $ircdir/connect-handler $botdir
sleep 5 sleep 5
done done