--- trunk/bin/irc-logger.pl 2007/03/18 15:37:05 50 +++ trunk/bin/irc-logger.pl 2007/03/18 16:03:24 51 @@ -669,15 +669,7 @@ } elsif ($msg =~ m/^ping/) { $res = "ping = " . dump( $ping ); - } elsif ($msg =~ m/^(?:twitter)\s+(\S+)\s+(.*?)/) { - if ( defined( $2 ) ) { - meta($nick, $channel, 'twitter', "$1\t$2"); - $res = "saved twitter auth for $1 -- /me on $channel will auto-update twitter status"; - } else { - meta($nick, $channel, 'twitter', '' ); - $res = "removed twitter status update for /me on $channel"; - } - } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size)*\s*(\d*)/) { + } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) { if ( ! defined( $1 ) ) { my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? }); $sth->execute( $nick, $channel ); @@ -685,12 +677,27 @@ while ( my ($n,$v) = $sth->fetchrow_array ) { $res .= "| $n = $v"; } - } elsif ( defined( $2 ) ) { - meta( $nick, $channel, $1, $2 ); - $res = "saved $1 = $2"; - } else { + } elsif ( ! $2 ) { my $val = meta( $nick, $channel, $1 ); $res = "current $1 = " . ( $val ? $val : 'undefined' ); + } else { + my $validate = { + 'last-size' => qr/^\d+/, + 'twitter' => qr/^\w+\s+\w+/, + }; + + my ( $op, $val ) = ( $1, $2 ); + + if ( my $regex = $validate->{$op} ) { + if ( $val =~ $regex ) { + meta( $nick, $channel, $op, $val ); + $res = "saved $op = $val"; + } else { + $res = "config option $op = $val doesn't validate against $regex"; + } + } else { + $res = "config option $op doesn't exist"; + } } }