--- trunk/bin/irc-logger.pl 2007/03/18 15:37:05 50
+++ trunk/bin/irc-logger.pl 2007/04/07 22:57:08 59
@@ -75,6 +75,10 @@
use DateTime;
use Data::Dump qw/dump/;
+my $use_twitter = 1;
+eval { require Net::Twitter; };
+$use_twitter = 0 if ($@);
+
my $import_dircproxy;
my $log_path;
GetOptions(
@@ -545,8 +549,13 @@
save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);
- if ( my $twitter = ( $nick, $channel, 'twitter' ) ) {
- _log("FIXME: send twitter for $nick on $channel [$twitter]");
+ if ( $use_twitter ) {
+ if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) {
+ my ($login,$passwd) = split(/\s+/,$twitter,2);
+ _log("sending twitter for $nick/$login on $channel ");
+ my $bot = Net::Twitter->new( username=>$login, password=>$passwd );
+ $bot->update("<${channel}> $msg");
+ }
}
},
@@ -593,11 +602,11 @@
my $sth = $dbh->prepare(qq{
select
- nick,
+ trim(both '_' from nick) as nick,
count(*) as count,
sum(length(message)) as len
from log
- group by nick
+ group by trim(both '_' from nick)
order by len desc,count desc
limit $nr
});
@@ -669,28 +678,35 @@
} 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 );
- $res = "config for $nick ";
+ $res = "config for $nick on $channel";
while ( my ($n,$v) = $sth->fetchrow_array ) {
- $res .= "| $n = $v";
+ $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";
+ }
}
}
@@ -911,6 +927,9 @@
$m =~ s/($escape_re)/$escape{$1}/gs;
$m =~ s#($RE{URI}{HTTP})#$1#gs;
$m =~ s#$tag_regex#$1#g;
+ $m =~ s#\*(\w+)\*#$1#gs;
+ $m =~ s#_(\w+)_#$1#gs;
+ $m =~ s#\/(\w+)\/#$1#gs;
return $m;
},
nick => sub {