--- trunk/bin/irc-logger.pl 2007/09/29 13:13:41 67
+++ trunk/bin/irc-logger.pl 2008/03/07 00:18:02 87
@@ -22,6 +22,10 @@
Name of log file
+=item --follow=file.log
+
+Follows new messages in file
+
=back
=head1 DESCRIPTION
@@ -32,7 +36,8 @@
## CONFIG
-my $HOSTNAME = `hostname`;
+my $HOSTNAME = `hostname -f`;
+chomp($HOSTNAME);
my $NICK = 'irc-logger';
$NICK .= '-dev' if ($HOSTNAME =~ m/llin/);
@@ -45,22 +50,29 @@
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);
my $IRC_ALIAS = "log";
-my %FOLLOWS =
- (
- ACCESS => "/var/log/apache/access.log",
- ERROR => "/var/log/apache/error.log",
- );
+# default log to follow and announce messages
+my $follows_path = 'follows.log';
my $DSN = 'DBI:Pg:dbname=' . $NICK;
+# log output encoding
my $ENCODING = 'ISO-8859-2';
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
my $sleep_on_error = 5;
-## END CONFIG
+# number of last tags to keep in circular buffer
+my $last_x_tags = 50;
+
+# don't pull rss feeds more often than this
+my $rss_min_delay = 60;
+$rss_min_delay = 15;
+my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000;
+my $url = "http://$HOSTNAME:$http_port";
+
+## END CONFIG
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP);
use HTTP::Status;
@@ -76,6 +88,9 @@
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; };
@@ -85,19 +100,86 @@
my $log_path;
GetOptions(
'import-dircproxy:s' => \$import_dircproxy,
+ 'follows:s' => \$follows_path,
'log:s' => \$log_path,
);
+#$SIG{__DIE__} = sub {
+# confess "fatal error";
+#};
+
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";
sub _log {
- print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/;
+ my $out = strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/;
+ from_to( $out, 'UTF-8', $ENCODING );
+ print $out;
}
+# LOG following
+
+my %FOLLOWS =
+ (
+# ACCESS => "/var/log/apache/access.log",
+# ERROR => "/var/log/apache/error.log",
+ );
+
+sub add_follow_path {
+ my $path = shift;
+ my $name = $path;
+ $name =~ s/\..*$//;
+ warn "# using $path to announce messages from $name\n";
+ $FOLLOWS{$name} = $path;
+}
+
+add_follow_path( $follows_path ) if ( -e $follows_path );
+
+# HTML formatters
+
+my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
+my $escape_re = join '|' => keys %escape;
+
+my $tag_regex = '\b([\w-_]+)//';
+
+my %nick_enumerator;
+my $max_color = 0;
+
+my $filter = {
+ message => sub {
+ my $m = shift || return;
+
+ # protect HTML from wiki modifications
+ sub e {
+ my $t = shift;
+ return 'uri_unescape{' . uri_escape($t) . '}';
+ }
+
+ $m =~ s/($escape_re)/$escape{$1}/gs;
+ $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;
+ $m =~ s#_(\w+)_#$1#gs;
+
+ $m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs;
+ return $m;
+ },
+ nick => sub {
+ my $n = shift || return;
+ if (! $nick_enumerator{$n}) {
+ my $max = scalar keys %nick_enumerator;
+ $nick_enumerator{$n} = $max + 1;
+ }
+ return '' . $n . '';
+ },
+};
+
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
my $sql_schema = {
- log => '
+ log => qq{
create table log (
id serial,
time timestamp default now(),
@@ -111,17 +193,31 @@
create index log_time on log(time);
create index log_channel on log(channel);
create index log_nick on log(nick);
- ',
- meta => '
+ },
+ meta => q{
create table meta (
nick text not null,
channel text not null,
name text not null,
value text,
- changed timestamp default now(),
+ changed timestamp default 'now()',
primary key(nick,channel,name)
);
- ',
+ },
+ feeds => qq{
+create table feeds (
+ id serial,
+ url text not null,
+ name text,
+ delay interval not null default '5 min',
+ active boolean default true,
+ last_update timestamp default 'now()',
+ polls int default 0,
+ updates int default 0
+);
+create unique index feeds_url on feeds(url);
+insert into feeds (url,name) values ('http://wiki.razmjenavjestina.org/feed/workspace/razmjenavjestina?category=Recent%20Changes','wiki');
+ },
};
foreach my $table ( keys %$sql_schema ) {
@@ -185,7 +281,7 @@
-my $sth = $dbh->prepare(qq{
+my $sth_insert_log = $dbh->prepare(qq{
insert into log
(channel, me, nick, message, time)
values (?,?,?,?,?)
@@ -193,7 +289,6 @@
my $tags;
-my $tag_regex = '\b([\w-_]+)//';
=head2 get_from_log
@@ -230,14 +325,16 @@
sub get_from_log {
my $args = {@_};
- $args->{fmt} ||= {
- date => '[%s] ',
- time => '{%s} ',
- time_channel => '{%s %s} ',
- nick => '%s: ',
- me_nick => '***%s ',
- message => '%s',
- };
+ if ( ! $args->{fmt} ) {
+ $args->{fmt} = {
+ date => '[%s] ',
+ time => '{%s} ',
+ time_channel => '{%s %s} ',
+ nick => '%s: ',
+ me_nick => '***%s ',
+ message => '%s',
+ };
+ }
my $sql_message = qq{
select
@@ -261,39 +358,49 @@
my $sql = $context ? $sql_context : $sql_message;
sub check_date {
- my $date = shift;
- $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; };
+ my $date = shift || return;
+ my $new_date = eval { DateTime::Format::ISO8601->parse_datetime( $date )->ymd; };
if ( $@ ) {
- warn "invalid date ", $args->{date}, $/;
- $date = DateTime->now->ymd;
+ warn "invalid date $date\n";
+ $new_date = DateTime->now->ymd;
}
- return $date;
+ return $new_date;
}
- $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});
- $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });
- if ($args->{date}) {
- $sql .= " where date(time) = ? ";
- $args->{date} = check_date( $args->{date} );
- }
- $sql .= " order by log.time desc";
- $sql .= " limit " . $args->{limit} if ($args->{limit});
+ my @where;
+ my @args;
- my $sth = $dbh->prepare( $sql );
if (my $search = $args->{search}) {
$search =~ s/^\s+//;
$search =~ s/\s+$//;
- $sth->execute( ( '%' . $search . '%' ) x 2 );
- _log "search for '$search' returned ", $sth->rows, " results ", $context || '';
- } elsif (my $tag = $args->{tag}) {
- $sth->execute();
- _log "tag '$tag' returned ", $sth->rows, " results ", $context || '';
- } elsif (my $date = $args->{date}) {
- $sth->execute( check_date($date) );
- _log "found ", $sth->rows, " messages for date $date ", $context || '';
- } else {
- $sth->execute();
+ push @where, 'message ilike ? or nick ilike ?';
+ push @args, ( ( '%' . $search . '%' ) x 2 );
+ _log "search for '$search'";
+ }
+
+ if ($args->{tag} && $tags->{ $args->{tag} }) {
+ push @where, 'id in (' . join(',', @{ $tags->{ $args->{tag} } }) . ')';
+ _log "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";
+ }
+
+ $sql .= " where " . join(" and ", @where) if @where;
+
+ $sql .= " order by log.time desc";
+ $sql .= " limit " . $args->{limit} if ($args->{limit});
+
+ #warn "### sql: $sql ", dump( @args );
+
+ my $sth = $dbh->prepare( $sql );
+ eval { $sth->execute( @args ) };
+ return if $@;
+
my $last_row = {
date => '',
time => '',
@@ -414,10 +521,12 @@
=head2 add_tag
- add_tag( id => 42, message => 'irc message' );
+ add_tag( id => 42, message => 'irc message', nick => 'foobar' [, me => 1 ] );
=cut
+my @last_tags;
+
sub add_tag {
my $arg = {@_};
@@ -426,13 +535,23 @@
my $m = $arg->{message};
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m));
+ my @tags;
+
while ($m =~ s#$tag_regex##s) {
my $tag = $1;
next if (! $tag || $tag =~ m/https?:/i);
push @{ $tags->{$tag} }, $arg->{id};
#warn "+tag $tag: $arg->{id}\n";
- $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1);
+ $cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1);
+ push @tags, $tag;
+
}
+
+ if ( @tags ) {
+ pop @last_tags if $#last_tags == $last_x_tags;
+ unshift @last_tags, { tags => [ @tags ], %$arg };
+ }
+
}
=head2 seed_tags
@@ -442,14 +561,14 @@
=cut
sub seed_tags {
- my $sth = $dbh->prepare(qq{ select id,message from log where message like '%//%' });
+ my $sth = $dbh->prepare(qq{ select id,message,nick,me,time from log where message like '%//%' order by time asc });
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
add_tag( %$row );
}
foreach my $tag (keys %$tags) {
- $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1);
+ $cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1);
}
}
@@ -462,7 +581,7 @@
channel => '#foobar',
me => 0,
nick => 'dpavlin',
- msg => 'test message',
+ message => 'test message',
time => '2006-06-25 18:57:18',
);
@@ -474,26 +593,24 @@
sub save_message {
my $a = {@_};
+ confess "have msg" if $a->{msg};
$a->{me} ||= 0;
$a->{time} ||= strftime($TIMESTAMP,localtime());
_log
$a->{channel}, " ",
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",
- " " . $a->{msg};
+ " " . $a->{message};
- from_to($a->{msg}, 'UTF-8', $ENCODING);
-
- $sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{msg}, $a->{time});
- add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef),
- message => $a->{msg});
+ $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time});
+ add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );
}
if ($import_dircproxy) {
open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";
warn "importing $import_dircproxy...\n";
- my $tz_offset = 2 * 60 * 60; # TZ GMT+2
+ my $tz_offset = 1 * 60 * 60; # TZ GMT+2
while(<$l>) {
chomp;
if (/^@(\d+)\s(\S+)\s(.+)$/) {
@@ -511,7 +628,7 @@
channel => $CHANNEL,
me => $me,
nick => $nick,
- msg => $msg,
+ message => $msg,
time => $dt->ymd . " " . $dt->hms,
) if ($nick !~ m/^-/);
@@ -524,6 +641,98 @@
exit;
}
+#
+# RSS follow
+#
+
+my $_rss;
+
+
+sub rss_fetch {
+ my ($args) = @_;
+
+ # how many messages to send out when feed is seen for the first time?
+ my $send_rss_msgs = 1;
+
+ _log "RSS fetch", $args->{url};
+
+ my $feed = XML::Feed->parse(URI->new( $args->{url} ));
+ if ( ! $feed ) {
+ _log("can't fetch RSS ", $args->{url});
+ return;
+ }
+ my ( $total, $updates ) = ( 0, 0 );
+ for my $entry ($feed->entries) {
+ $total++;
+
+ # seen allready?
+ return if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0;
+
+ sub prefix {
+ my ($txt,$var) = @_;
+ $var =~ s/^\s+//g;
+ return $txt . $var if $var;
+ }
+
+ my $msg;
+ $msg .= prefix( 'From: ' , $feed->title );
+ $msg .= prefix( ' by ' , $entry->author );
+ $msg .= prefix( ' -- ' , $entry->link );
+# $msg .= prefix( ' id ' , $entry->id );
+
+ if ( $args->{kernel} && $send_rss_msgs ) {
+ warn "# sending to $CHANNEL\n";
+ $send_rss_msgs--;
+ $args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg );
+ $updates++;
+ #$sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, undef );
+ _log('RSS', $msg);
+ }
+ }
+
+ my $sql = qq{ update feeds set last_update = now(), polls = polls + 1 };
+ $sql .= qq{, updates = updates + $updates } if $updates;
+ $sql .= qq{where id = } . $args->{id};
+ eval { $dbh->do( $sql ) };
+
+ _log "RSS got $total items of which $updates new";
+
+ return $updates;
+}
+
+sub rss_fetch_all {
+ my $kernel = shift;
+ my $sql = qq{
+ select id, url, name
+ from feeds
+ where active is true
+ };
+ # limit to newer feeds only if we are not sending messages out
+ $sql .= qq{ and last_update + delay < now() } if $kernel;
+ my $sth = $dbh->prepare( $sql );
+ $sth->execute();
+ warn "# ",$sth->rows," active RSS feeds\n";
+ my $count = 0;
+ while (my $row = $sth->fetchrow_hashref) {
+ $row->{kernel} = $kernel if $kernel;
+ $count += rss_fetch( $row );
+ }
+ return "OK, fetched $count posts from " . $sth->rows . " feeds";
+}
+
+
+sub rss_check_updates {
+ my $kernel = shift;
+ my $last_t = $_rss->{last_poll} || time();
+ my $t = time();
+ if ( $last_t - $t > $rss_min_delay ) {
+ $_rss->{last_poll} = $t;
+ _log rss_fetch_all( $kernel );
+ }
+}
+
+# seed rss seen cache so we won't send out all items on startup
+_log rss_fetch_all;
#
# POE handing part
@@ -535,16 +744,13 @@
POE::Component::IRC->new($IRC_ALIAS);
-POE::Session->create( inline_states =>
- {_start => sub {
+POE::Session->create( inline_states => {
+ _start => sub {
$_[KERNEL]->post($IRC_ALIAS => register => 'all');
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT);
},
irc_255 => sub { # server is done blabbing
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL);
- $_[KERNEL]->post($IRC_ALIAS => join => '#logger');
- $_[KERNEL]->yield("heartbeat"); # start heartbeat
-# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS;
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
},
irc_public => sub {
@@ -553,7 +759,7 @@
my $channel = $_[ARG1]->[0];
my $msg = $_[ARG2];
- save_message( channel => $channel, me => 0, nick => $nick, msg => $msg);
+ save_message( channel => $channel, me => 0, nick => $nick, message => $msg);
meta( $nick, $channel, 'last-msg', $msg );
},
irc_ctcp_action => sub {
@@ -562,7 +768,7 @@
my $channel = $_[ARG1]->[0];
my $msg = $_[ARG2];
- save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);
+ save_message( channel => $channel, me => 1, nick => $nick, message => $msg);
if ( $use_twitter ) {
if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) {
@@ -575,15 +781,16 @@
},
irc_ping => sub {
- warn "pong ", $_[ARG0], $/;
+ _log( "pong ", $_[ARG0] );
$ping->{ $_[ARG0] }++;
+ rss_check_updates( $_[KERNEL] );
},
irc_invite => sub {
my $kernel = $_[KERNEL];
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1];
- warn "invited to $channel by $nick";
+ _log "invited to $channel by $nick";
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." );
$_[KERNEL]->post($IRC_ALIAS => join => $channel);
@@ -594,7 +801,6 @@
my $nick = (split /!/, $_[ARG0])[0];
my $msg = $_[ARG2];
my $channel = $_[ARG1]->[0];
- from_to($msg, 'UTF-8', $ENCODING);
my $res = "unknown command '$msg', try /msg $NICK help!";
my @out;
@@ -638,7 +844,6 @@
foreach my $res (get_from_log( limit => $limit )) {
_log "last: $res";
- from_to($res, $ENCODING, 'UTF-8');
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
}
@@ -653,7 +858,6 @@
search => $what,
)) {
_log "search [$what]: $res";
- from_to($res, $ENCODING, 'UTF-8');
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
}
@@ -723,14 +927,34 @@
$res = "config option $op doesn't exist";
}
}
+ } elsif ($msg =~ m/^rss-update/) {
+ $res = rss_fetch_all( $_[KERNEL] );
+ } elsif ($msg =~ m/^rss-clean/) {
+ $_rss = undef;
+ $res = "OK, cleaned RSS cache";
+ } elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) {
+ my $sql = {
+ add => qq{ insert into feeds (url,name) values (?,?) },
+# remove => qq{ delete from feeds where url = ? and name = ? },
+ start => qq{ update feeds set active = true where url = ? -- ? },
+ stop => qq{ update feeds set active = false where url = ? -- ? },
+
+ };
+ if (my $q = $sql->{$1} ) {
+ my $sth = $dbh->prepare( $q );
+ warn "## SQL $q ( $2 | $3 )\n";
+ eval { $sth->execute( $2, $3 ) };
+ }
+
+ $res ||= "OK, RSS $1 : $2 - $3";
}
if ($res) {
_log ">> [$nick] $res";
- from_to($res, $ENCODING, 'UTF-8');
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
}
+ rss_check_updates( $_[KERNEL] );
},
irc_477 => sub {
_log "# irc_477: ",$_[ARG1];
@@ -769,80 +993,22 @@
"";
0; # false for signals
},
- my_add => sub {
- my $trailing = $_[ARG0];
- my $session = $_[SESSION];
- POE::Session->create
- (inline_states =>
- {_start => sub {
- $_[HEAP]->{wheel} =
- POE::Wheel::FollowTail->new
- (
- Filename => $FOLLOWS{$trailing},
- InputEvent => 'got_line',
- );
- },
- got_line => sub {
- $_[KERNEL]->post($session => my_tailed =>
- time, $trailing, $_[ARG0]);
- },
- },
- );
-
- },
- my_tailed => sub {
- my ($time, $file, $line) = @_[ARG0..ARG2];
- ## $time will be undef on a probe, or a time value if a real line
-
- ## PoCo::IRC has throttling built in, but no external visibility
- ## so this is reaching "under the hood"
- $SEND_QUEUE ||=
- $_[KERNEL]->alias_resolve($IRC_ALIAS)->get_heap->{send_queue};
-
- ## handle "no need to keep skipping" transition
- if ($SKIPPING and @$SEND_QUEUE < 1) {
- $_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL =>
- "[discarded $SKIPPING messages]");
- $SKIPPING = 0;
- }
-
- ## handle potential message display
- if ($time) {
- if ($SKIPPING or @$SEND_QUEUE > 3) { # 3 msgs per 10 seconds
- $SKIPPING++;
- } else {
- my @time = localtime $time;
- $_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL =>
- sprintf "%02d:%02d:%02d: %s: %s",
- ($time[2] + 11) % 12 + 1, $time[1], $time[0],
- $file, $line);
- }
- }
-
- ## handle re-probe/flush if skipping
- if ($SKIPPING) {
- $_[KERNEL]->delay($_[STATE] => 0.5); # $time will be undef
- }
-
- },
- my_heartbeat => sub {
- $_[KERNEL]->yield(my_tailed => time, "heartbeat", "beep");
- $_[KERNEL]->delay($_[STATE] => 10);
- }
},
);
# http server
my $httpd = POE::Component::Server::HTTP->new(
- Port => $NICK =~ m/-dev/ ? 8001 : 8000,
+ Port => $http_port,
+ PreHandler => {
+ '/' => sub {
+ $_[0]->header(Connection => 'close')
+ }
+ },
ContentHandler => { '/' => \&root_handler },
Headers => { Server => 'irc-logger' },
);
-my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
-my $escape_re = join '|' => keys %escape;
-
my $style = <<'_END_OF_STYLE_';
p { margin: 0; padding: 0.1em; }
.time, .channel { color: #808080; font-size: 60%; }
@@ -864,7 +1030,7 @@
.month { border: 0px; width: 100%; }
_END_OF_STYLE_
-my $max_color = 4;
+$max_color = 0;
my @cols = qw(
#ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99
@@ -874,19 +1040,20 @@
#999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff
);
-$max_color = 0;
foreach my $c (@cols) {
$style .= ".col-${max_color} { background: $c }\n";
$max_color++;
}
warn "defined $max_color colors for users...\n";
-my %nick_enumerator;
-
sub root_handler {
my ($request, $response) = @_;
$response->code(RC_OK);
- $response->content_type("text/html; charset=$ENCODING");
+
+ # this doesn't seem to work, so moved to PreHandler
+ #$response->header(Connection => 'close');
+
+ return RC_OK if $request->uri =~ m/favicon.ico$/;
my $q;
@@ -900,19 +1067,120 @@
my $search = $q->param('search') || $q->param('grep') || '';
+ if ($request->url =~ m#/rss(?:/(tags|last-tag|follow.*)\w*(?:=(\d+))?)?#i) {
+ my $show = lc($1);
+ my $nr = $2;
+
+ my $type = 'RSS'; # Atom
+
+ $response->content_type( 'application/' . lc($type) . '+xml' );
+
+ my $html = '';
+ #warn "create $type feed from ",dump( @last_tags );
+
+ my $feed = XML::Feed->new( $type );
+ $feed->link( $url );
+
+ if ( $show eq 'tags' ) {
+ $nr ||= 50;
+ $feed->title( "tags from $CHANNEL" );
+ $feed->link( "$url/tags" );
+ $feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" );
+ my $feed_entry = XML::Feed::Entry->new($type);
+ $feed_entry->title( "$nr tags from $CHANNEL" );
+ $feed_entry->author( $NICK );
+ $feed_entry->link( '/#tags' );
+
+ $feed_entry->content(
+ qq{}
+ . $cloud->css
+ . qq{}
+ . $cloud->html( $nr )
+ . qq{]]>}
+ );
+ $feed->add_entry( $feed_entry );
+
+ } elsif ( $show eq 'last-tag' ) {
+
+ $nr ||= $last_x_tags;
+ $nr = $last_x_tags if $nr > $last_x_tags;
+
+ $feed->title( "last $nr tagged messages from $CHANNEL" );
+ $feed->description( "collects messages which have tags// in them" );
+
+ foreach my $m ( @last_tags ) {
+# warn dump( $m );
+ #my $tags = join(' ', @{$m->{tags}} );
+ my $feed_entry = XML::Feed::Entry->new($type);
+ $feed_entry->title( $m->{nick} . '@' . $m->{time} );
+ $feed_entry->author( $m->{nick} );
+ $feed_entry->link( '/#' . $m->{id} );
+ $feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) );
+
+ my $message = $filter->{message}->( $m->{message} );
+ $message .= "
\n" unless $message =~ m!<(/p|br/?)>!;
+# warn "## message = $message\n";
+
+ #$feed_entry->summary(
+ $feed_entry->content(
+ ""
+ );
+ $feed_entry->category( join(', ', @{$m->{tags}}) );
+ $feed->add_entry( $feed_entry );
+
+ $nr--;
+ last if $nr <= 0;
+
+ }
+
+ } elsif ( $show =~ m/^follow/ ) {
+
+ $feed->title( "Feeds which this bot follows" );
+
+ my $sth = $dbh->prepare( qq{ select * from feeds order by last_update desc } );
+ $sth->execute;
+ while (my $row = $sth->fetchrow_hashref) {
+ my $feed_entry = XML::Feed::Entry->new($type);
+ $feed_entry->title( $row->{name} );
+ $feed_entry->link( $row->{url} );
+ $feed_entry->issued( DateTime::Format::Flexible->build( $row->{last_update} ) );
+ $feed_entry->content(
+ '' . dump( $row ) . ']]>'
+ );
+ $feed->add_entry( $feed_entry );
+ }
+
+ } else {
+ _log "unknown rss request ",$request->url;
+ return RC_DENY;
+ }
+
+ $response->content( $feed->as_xml );
+ return RC_OK;
+ }
+
+ if ( $@ ) {
+ warn "$@";
+ }
+
+ $response->content_type("text/html; charset=UTF-8");
+
my $html =
- qq{
}; - if ($request->url =~ m#/history#) { + } + . $cloud->html(500) + . qq{
};
+
+ if ($request->url =~ m#/tags?#) {
+ # nop
+ } elsif ($request->url =~ m#/history#) {
my $sth = $dbh->prepare(qq{
select date(time) as date,count(*) as nr,sum(length(message)) as len
from log
@@ -944,9 +1212,9 @@
$cal->weekdays('MON','TUE','WED','THU','FRI');
($l_yyyy,$l_mm) = ($yyyy,$mm);
}
- $cal->setcontent($dd, qq{
- $row->{nr}
$row->{len}
- });
+ $cal->setcontent($dd, qq[
+ $row->{nr}
$row->{len}
+ ]);
}
$html .= qq{
", get_from_log( - limit => $q->param('last') || $q->param('date') ? undef : 100, + limit => ( $q->param('last') || $q->param('date') ) ? undef : 100, search => $search || undef, tag => $q->param('tag') || undef, - date => check_date( $q->param('date') ), + date => $q->param('date') || undef, fmt => { date => sub { my $date = shift || return; - qq{