From 7ea50ad1d0e8dc5e851aa1c5db489de01e719d24 Mon Sep 17 00:00:00 2001 From: dms Date: Mon, 31 Jul 2000 14:37:02 +0000 Subject: [PATCH] cvs commit borked, continuing git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@22 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/IRC/Irc.pl | 4 ++-- src/IRC/IrcHooks.pl | 6 +++--- src/IRC/Schedulers.pl | 46 +++++++++++++++++++++++++++++++++++++--- src/Modules/Countdown.pl | 2 +- src/Modules/Factoids.pl | 8 +++---- src/Modules/Freshmeat.pl | 8 +++---- src/Modules/Kernel.pl | 2 +- src/Modules/Units.pl | 2 +- src/Modules/Uptime.pl | 6 +++--- src/Modules/Wingate.pl | 2 +- src/Modules/babel.pl | 1 - 11 files changed, 63 insertions(+), 24 deletions(-) diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 1abd87e..f377598 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -160,7 +160,7 @@ sub rawout { sub say { my ($msg) = @_; - if (!defined $msg or $msg eq "NOREPLY") { + if (!defined $msg or $msg eq $noreply) { $msg ||= "NULL"; &DEBUG("say: msg == $msg."); return; @@ -187,7 +187,7 @@ sub msg { return; } - if (!defined $msg or $msg eq "NOREPLY") { + if (!defined $msg or $msg eq $noreply) { $msg ||= "NULL"; &DEBUG("msg: msg == $msg."); return; diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 8fc4c07..889734b 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -96,7 +96,7 @@ sub on_chat { if ($message =~ s/^\.//) { # dcc chat commands. ### TODO: make use of &Forker(); here? &loadMyModule($myModules{'ircdcc'}); - return 'NOREPLY from userD' if (&userDCC() eq 'NOREPLY'); + return '$noreply from userD' if (&userDCC() eq $noreply); $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command."); } else { # dcc chat arena. @@ -112,7 +112,7 @@ sub on_endofmotd { my ($self) = @_; if (&IsParam("wingate")) { - my $file = "$infobot_base_dir/$param{'ircUser'}.wingate"; + my $file = "$bot_base_dir/$param{'ircUser'}.wingate"; open(IN, $file); while () { chop; @@ -692,7 +692,7 @@ sub on_version { my $nick = $event->nick; &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob"); - $self->ctcp_reply($nick, "VERSION $infobot_version"); + $self->ctcp_reply($nick, "VERSION $bot_version"); } sub on_who { diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index d92d9a5..efb28af 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -41,7 +41,7 @@ sub ScheduleThis { } sub randomQuote { - my $line = &getRandomLineFromFile($infobot_misc_dir. "/infobot.randtext"); + my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.randtext"); if (!defined $line) { &ERROR("random Quote: weird error?"); return; @@ -106,6 +106,7 @@ sub randomFactoid { } sub logCycle { + # check if current size is too large. if ( -s $file{log} > $param{'maxLogSize'}) { my $date = sprintf("%04d%02d%02d", (localtime)[5,4,3]); $file{log} = $param{'logfile'} ."-". $date; @@ -129,6 +130,45 @@ sub logCycle { &status("cycling log file."); } + # check if all the logs exceed size. + my $logdir = "$bot_base_dir/log/"; + if (opendir(LOGS, $logdir)) { + my $tsize = 0; + my (%age, %size); + + while (defined($_ = readdir LOGS)) { + my $logfile = "$logdir/$_"; + + next unless ( -f $logfile); + my $size = -s $logfile; + my $age = (stat $logfile)[9]; ### or 8 ? + + $age{$age} = $logfile; + $size{$logfile} = $size; + + $tsize += $size; + } + closedir LOGS; + + my $delete = 0; + while ($tsize > $param{'maxLogSize'}) { + &status("LOG: current size > max ($tsize > $param{'maxLogSize'})"); + my $oldest = (sort {$a <=> $b} keys %age)[0]; + &status("LOG: unlinking $age{$oldest}."); + ### NOT YET. + # unlink $age{$oldest}; + $tsize -= $oldest; + $delete++; + } + + ### TODO: add how many b,kb,mb removed? + if ($delete) { + &status("LOG: removed $delete logs."); + } + } else { + &WARN("could not open dir $logdir"); + } + &ScheduleThis(60, "logCycle") if (@_); } @@ -462,8 +502,8 @@ sub wingateCheck { sub wingateWriteFile { return unless (scalar @wingateCache); - my $file = "$infobot_base_dir/$param{'ircUser'}.wingate"; - if ($infobot_pid != $$) { + my $file = "$bot_base_dir/$param{'ircUser'}.wingate"; + if ($bot_pid != $$) { &DEBUG("wingateWriteFile: Reorganising!"); open(IN, $file); diff --git a/src/Modules/Countdown.pl b/src/Modules/Countdown.pl index 51cae88..0fdbdd3 100644 --- a/src/Modules/Countdown.pl +++ b/src/Modules/Countdown.pl @@ -11,7 +11,7 @@ use strict; sub Countdown { my ($query) = @_; - my $file = "$infobot_base_dir/$param{'ircUser'}.countdown"; + my $file = "$bot_base_dir/$param{'ircUser'}.countdown"; my (%date, %desc); my $reply; diff --git a/src/Modules/Factoids.pl b/src/Modules/Factoids.pl index 4449ef6..525d900 100644 --- a/src/Modules/Factoids.pl +++ b/src/Modules/Factoids.pl @@ -16,7 +16,7 @@ sub CmdFactInfo { if ($faqtoid eq "") { &help("factinfo"); - return 'NOREPLY'; + return $noreply; } my $i = 0; @@ -30,7 +30,7 @@ sub CmdFactInfo { # factoid does not exist. if (scalar @factinfo <= 1) { &performReply("there's no such factoid as \002$faqtoid\002"); - return 'NOREPLY'; + return $noreply; } # created: @@ -119,11 +119,11 @@ sub CmdFactInfo { # factoid was inserted not through the bot. if (!scalar @array) { &performReply("no extra info on \002$faqtoid\002"); - return 'NOREPLY'; + return $noreply; } &performStrictReply("$factinfo{'factoid_key'} -- ". join("; ", @array) ."."); - return 'NOREPLY'; + return $noreply; } sub CmdFactStats { diff --git a/src/Modules/Freshmeat.pl b/src/Modules/Freshmeat.pl index 2e32602..be96f49 100644 --- a/src/Modules/Freshmeat.pl +++ b/src/Modules/Freshmeat.pl @@ -32,12 +32,12 @@ sub Freshmeat { } $renewtable++ if (&main::countKeys("freshmeat") < 10); - if ($renewtable and $$ == $main::infobot_pid) { + if ($renewtable and $$ == $main::blootbot_pid) { &main::Forker("freshmeat", sub { &downloadIndex(); &Freshmeat($sstr); } ); - return if ($$ == $main::infobot_pid); + return if ($$ == $main::bot_pid); } if (!&showPackage($sstr)) { # no exact match. @@ -97,7 +97,7 @@ sub showPackage { sub downloadIndex { my $start_time = &main::gettimeofday(); # set the start time. - my $idx = "$main::infobot_base_dir/Temp/fm_index.txt"; + my $idx = "$main::bot_base_dir/Temp/fm_index.txt"; &main::msg($main::who, "Updating freshmeat index... please wait"); @@ -179,7 +179,7 @@ sub downloadIndex { } sub freshmeatAnnounce { - my $file = "$main::infobot_base_dir/Temp/fm_recent.txt"; + my $file = "$main::bot_base_dir/Temp/fm_recent.txt"; my @old; if ( -f $file) { diff --git a/src/Modules/Kernel.pl b/src/Modules/Kernel.pl index c9749f9..9d74a65 100644 --- a/src/Modules/Kernel.pl +++ b/src/Modules/Kernel.pl @@ -67,7 +67,7 @@ sub Kernel { } sub kernelAnnounce { - my $file = "$main::infobot_base_dir/Temp/kernel.txt"; + my $file = "$main::blootbot_base_dir/Temp/kernel.txt"; my @now = &kernelGetInfo(); my @old; diff --git a/src/Modules/Units.pl b/src/Modules/Units.pl index dd8a8ed..cabfd37 100644 --- a/src/Modules/Units.pl +++ b/src/Modules/Units.pl @@ -49,7 +49,7 @@ BEGIN { ################################################################ { my $defs_read = 0; - $defs_read += read_defs("$main::infobot_misc_dir/unittab"); + $defs_read += read_defs("$main::bot_misc_dir/unittab"); unless ($defs_read) { &main::ERROR("Could not read any of the initialization files UNITTAB"); diff --git a/src/Modules/Uptime.pl b/src/Modules/Uptime.pl index 1ef9d22..40bdb40 100644 --- a/src/Modules/Uptime.pl +++ b/src/Modules/Uptime.pl @@ -1,5 +1,5 @@ # -# Uptime.pl: Uptime daemon for infobot. +# Uptime.pl: Uptime daemon. # Author: dms # Version: v0.3 (19991008) # Created: 19990925. @@ -17,9 +17,9 @@ sub uptimeStr { my $uptimenow = &uptimeNow(); if (defined $_[0]) { - return "$uptimenow.$$ running $infobot_version, ended ". localtime(time()); + return "$uptimenow.$$ running $bot_version, ended ". localtime(time()); } else { - return "$uptimenow running $infobot_version"; + return "$uptimenow running $bot_version"; } } diff --git a/src/Modules/Wingate.pl b/src/Modules/Wingate.pl index 0bca799..4a7a363 100644 --- a/src/Modules/Wingate.pl +++ b/src/Modules/Wingate.pl @@ -12,7 +12,7 @@ use strict; my $select = IO::Select->new; sub Wingates { - my $file = "$main::infobot_base_dir/$main::param{'ircUser'}.wingate"; + my $file = "$main::blootbot_base_dir/$main::param{'ircUser'}.wingate"; my @hosts; open(IN, $file); diff --git a/src/Modules/babel.pl b/src/Modules/babel.pl index ccaefc1..01d097d 100644 --- a/src/Modules/babel.pl +++ b/src/Modules/babel.pl @@ -1,5 +1,4 @@ # This program is copyright Jonathan Feinberg 1999. - # This program is distributed under the same terms as infobot. # Jonathan Feinberg -- 2.39.2