--- trunk/bin/irc-logger.pl 2008/03/07 15:49:23 97
+++ trunk/bin/irc-logger.pl 2008/03/08 17:38:30 102
@@ -2,6 +2,23 @@
use strict;
$|++;
+use POE qw(Component::IRC Component::Server::HTTP);
+use HTTP::Status;
+use DBI;
+use Regexp::Common qw /URI/;
+use CGI::Simple;
+use HTML::TagCloud;
+use POSIX qw/strftime/;
+use HTML::CalendarMonthSimple;
+use Getopt::Long;
+use DateTime;
+use URI::Escape;
+use Data::Dump qw/dump/;
+use DateTime::Format::ISO8601;
+use Carp qw/confess/;
+use XML::Feed;
+use DateTime::Format::Flexible;
+
=head1 NAME
irc-logger.pl
@@ -35,15 +52,22 @@
my $NICK = 'irc-logger';
$NICK .= '-dev' if ($HOSTNAME =~ m/llin/);
-my $CONNECT =
- {Server => 'irc.freenode.net',
- Nick => $NICK,
- Ircname => "try /msg $NICK help",
- };
+my $CONNECT = {
+ Server => 'irc.freenode.net',
+ Nick => $NICK,
+ Ircname => "try /msg $NICK help",
+};
my $CHANNEL = '#razmjenavjestina';
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);
my $IRC_ALIAS = "log";
+if ( $HOSTNAME =~ m/lugarin/ ) {
+ $CONNECT->{Server} = 'irc.carnet.hr';
+ $CHANNEL = '#riss';
+}
+
+warn dump( $HOSTNAME, $CONNECT );
+
my $DSN = 'DBI:Pg:dbname=' . $NICK;
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
@@ -62,23 +86,6 @@
## END CONFIG
-use POE qw(Component::IRC Component::Server::HTTP);
-use HTTP::Status;
-use DBI;
-use Regexp::Common qw /URI/;
-use CGI::Simple;
-use HTML::TagCloud;
-use POSIX qw/strftime/;
-use HTML::CalendarMonthSimple;
-use Getopt::Long;
-use DateTime;
-use URI::Escape;
-use Data::Dump qw/dump/;
-use DateTime::Format::ISO8601;
-use Carp qw/confess/;
-use XML::Feed;
-use DateTime::Format::Flexible;
-
my $use_twitter = 1;
eval { require Net::Twitter; };
$use_twitter = 0 if ($@);
@@ -117,11 +124,11 @@
# protect HTML from wiki modifications
sub e {
my $t = shift;
- return 'uri_unescape{' . uri_escape($t) . '}';
+ return 'uri_unescape{' . uri_escape($t, '^a-zA-Z0-9') . '}';
}
$m =~ s/($escape_re)/$escape{$1}/gs;
- $m =~ s#($RE{URI}{HTTP})#e(qq{$1})#egs ||
+ $m =~ s#($RE{URI}{HTTP})#e(qq{$1})#egs;
$m =~ s#\/(\w+)\/#$1#gs;
$m =~ s#$tag_regex#e(qq{$1})#egs;
$m =~ s#\*(\w+)\*#$1#gs;
@@ -339,25 +346,26 @@
my @where;
my @args;
+ my $msg;
if (my $search = $args->{search}) {
$search =~ s/^\s+//;
$search =~ s/\s+$//;
push @where, 'message ilike ? or nick ilike ?';
push @args, ( ( '%' . $search . '%' ) x 2 );
- _log "search for '$search'";
+ $msg = "Search for '$search'";
}
if ($args->{tag} && $tags->{ $args->{tag} }) {
push @where, 'id in (' . join(',', @{ $tags->{ $args->{tag} } }) . ')';
- _log "search for tags $args->{tag}";
+ $msg = "Search for tags $args->{tag}";
}
if (my $date = $args->{date} ) {
$date = check_date( $date );
push @where, 'date(time) = ?';
push @args, $date;
- _log "search for date $date";
+ $msg = "search for date $date";
}
$sql .= " where " . join(" and ", @where) if @where;
@@ -371,6 +379,8 @@
eval { $sth->execute( @args ) };
return if $@;
+ my $nr_results = $sth->rows;
+
my $last_row = {
date => '',
time => '',
@@ -391,10 +401,14 @@
return @rows if ($args->{full_rows});
- my @msgs = (
- "Showing " . ($#rows + 1) . " messages..."
+ $msg .= ' produced ' . (
+ $nr_results == 0 ? 'no results' :
+ $nr_results == 0 ? 'one result' :
+ $nr_results . ' results'
);
+ my @msgs = ( $msg );
+
if ($context) {
my @ids = @rows;
@rows = ();
@@ -655,7 +669,6 @@
} elsif ( $link !~ m!^http! ) {
$link = $args->{url} . $link;
}
- $link =~ s!//+!/!g;
my $msg;
$msg .= prefix( 'From: ' , $args->{name} || $feed->title );
@@ -938,7 +951,9 @@
stop => qq{ update feeds set active = false where url = ? },
};
- if (my $q = $sql->{$command} ) {
+ if ( $command eq 'add' && ! $channel ) {
+ $res = "ERROR: got '$msg' which doesn't have #channel in it, ignoring!";
+ } elsif (my $q = $sql->{$command} ) {
my $sth = $dbh->prepare( $q );
my @data = ( $url );
if ( $command eq 'add' ) {
@@ -954,7 +969,6 @@
} else {
$res = "ERROR: don't know what to do with: $msg";
}
-
}
if ($res) {