[pastebot-cvs] pastebot/Util Conf.pm,1.1.1.1,1.2 Data.pm,1.1.1.1,1.2
Status: Beta
Brought to you by:
rcaputo
From: <rc...@us...> - 2002-10-15 22:12:38
|
Update of /cvsroot/pastebot/pastebot/Util In directory usw-pr-cvs1:/tmp/cvs-serv18767/Util Modified Files: Conf.pm Data.pm Log Message: Applied Jonathan Scott Duff's patches to periodically expire old pastes or force expiration of the oldest pastes when new ones would overflow some limit. These patches constrain the bot's memory footprint. Index: Conf.pm =================================================================== RCS file: /cvsroot/pastebot/pastebot/Util/Conf.pm,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Conf.pm 8 May 2002 16:11:08 -0000 1.1.1.1 --- Conf.pm 15 Oct 2002 22:12:34 -0000 1.2 *************** *** 8,13 **** use Exporter; use Carp qw(croak); ! use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw( get_names_by_type --- 8,14 ---- use Exporter; use Carp qw(croak); + use Getopt::Std; ! use vars qw(@ISA @EXPORT %OPTS); @ISA = qw(Exporter); @EXPORT = qw( get_names_by_type *************** *** 42,45 **** --- 43,53 ---- localaddr => SCALAR, }, + pastes => + { name => SCALAR | REQUIRED, + check => SCALAR, + expire => SCALAR, + count => SCALAR, + throttle => SCALAR, + }, ); *************** *** 66,70 **** } ! open(MPH, "<./pastebot.conf") or die $!; while (<MPH>) { chomp; --- 74,81 ---- } ! my %opts; ! getopts("f:", \%opts); ! my $cfile = $opts{"f"} || "./pastebot.conf"; ! open(MPH, "<$cfile") or die $!; while (<MPH>) { chomp; Index: Data.pm =================================================================== RCS file: /cvsroot/pastebot/pastebot/Util/Data.pm,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Data.pm 8 May 2002 16:11:08 -0000 1.1.1.1 --- Data.pm 15 Oct 2002 22:12:34 -0000 1.2 *************** *** 8,16 **** use Exporter; use Carp qw(croak); use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); ! @EXPORT = qw( store_paste fetch_paste delete_paste ! fetch_paste_channel clear_channel_ignores set_ignore clear_ignore get_ignores is_ignored ); --- 8,18 ---- use Exporter; use Carp qw(croak); + use POE; + use Util::Conf; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); ! @EXPORT = qw( store_paste fetch_paste delete_paste list_paste_ids ! delete_paste_by_id fetch_paste_channel clear_channel_ignores set_ignore clear_ignore get_ignores is_ignored ); *************** *** 28,35 **** --- 30,58 ---- my %ignores; # $ignores{$ircnet}{lc $channel} = [ mask, mask, ... ]; + # return a list of all paste ids + + sub list_paste_ids { + return keys %paste_cache; + } + + # remove pastes that are too old (if applicable) + sub check_paste_count { + my @names = get_names_by_type('pastes'); + return unless @names; + my %conf = get_items_by_name($names[0]); + return unless %conf && $conf{'count'}; + return if (scalar keys %paste_cache < $conf{'count'}); + my $oldest = time; + for (keys %paste_cache) { + $oldest = $_ if $paste_cache{$_}->[PASTE_TIME] < $oldest; + } + delete $paste_cache{$oldest}; + } + # Save paste, returning an ID. sub store_paste { my ($id, $summary, $paste, $ircnet, $channel, $ipaddress) = @_; + check_paste_count(); my $new_id = ++$id_sequence; $paste_cache{$new_id} = *************** *** 64,67 **** --- 87,95 ---- } + sub delete_paste_by_id { + my $id = shift; + delete $paste_cache{$id}; + } + # Delete a possibly sensitive or offensive paste. *************** *** 144,147 **** --- 172,191 ---- } + my @pastes = get_names_by_type('pastes'); + if (@pastes) { + my %conf = get_items_by_name($pastes[0]); + if ($conf{'check'} && $conf{'expire'}) { + POE::Session->new( + _start => sub { $_[KERNEL]->delay( ticks => $conf{'check'} ); }, + ticks => sub { + for (keys %paste_cache) { + next unless (time - $paste_cache{$_}->[PASTE_TIME]) > $conf{'expire'}; + delete $paste_cache{$_}; + } + $_[KERNEL]->delay( ticks => $conf{'check'} ); + }, + ); + } + } ### End. |