]> git.donarmstrong.com Git - infobot.git/commitdiff
* Changed logger filehands to utf8 binmode
authordjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Tue, 30 Oct 2007 16:32:08 +0000 (16:32 +0000)
committerdjmcgrath <djmcgrath@c11ca15a-4712-0410-83d8-924469b57eb5>
Tue, 30 Oct 2007 16:32:08 +0000 (16:32 +0000)
* Corrected the insane getRandomInt sub ;)
* Added new RSS Feeds module
* Fix bug in scheduler using random (sometimes negative or zero) times
* Adjusted scheduled task times to reflect new "seconds only" format

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1598 c11ca15a-4712-0410-83d8-924469b57eb5

doc/infobot.config.pod
files/infobot.help
files/sample/infobot.config
src/CommandStubs.pl
src/IRC/Schedulers.pl
src/Misc.pl
src/logger.pl

index cbbbb2f523980c3c8a3ac87c76ec51cea75630b0..ba1d5665f70583360019cd6cd10e4803a2624730 100644 (file)
@@ -364,6 +364,11 @@ freshmeat for factoids which do not exist.
 
 This controls if the bot should store uptime records or not.
 
+=item B<set rssFeedTime E<lt>minutesE<gt>>
+
+Should you decide to use the RSS Feed module, this setting controls how often
+the feeds for all channels will be polled.
+
 =back
 
 =head2 Miscellaneous configuration options
index 5ae4fdfb5a46025bfdbd3e8d1ad9773bd8840eef..ef925b3b1ff3018125b5b4fc9a0d16f7d23c3666 100644 (file)
@@ -483,3 +483,9 @@ flags: D:        - can [un]lock factoids
 flags: D: "r" - remove factoid.
 flags: D: "t" - teach/add factoid.
 flags: D: "s" - Bypass +silent on channels
+
+rssfeeds: D: rssfeeds is used to control the RSS Feed tracking module
+rssfeeds: U: rssfeeds [command]
+rssfeeds: E: rssfeeds flush
+rssfeeds: D: flush - Will erase the cache file. (Must be chattr +o)
+rssfeeds: D: update - Force a manual update of the feeds. (Must be chattr +o)
index ce166f114958eb4e1f2da2d9790459f0805214a5..2e855b298d6f633fa103043964433653f8fba78f 100644 (file)
@@ -180,6 +180,9 @@ set freshmeatForFactoid             false
 # [0/1] Uptime logs
 set Uptime             true
 
+# [minutes] RSS Feeds refresh interval
+set rssFeedTime         30
+
 #####
 # Miscellaneous configuration options
 #####
index 2e0bd65253a3265f9b97897e479bae44eb17b604..0d3c7f81c3a164f96163e06494c0dbdde8cc5173 100644 (file)
@@ -784,6 +784,7 @@ sub nullski {
 &addCmdHook('RootWarn', ('CODEREF' => 'CmdrootWarn', 'Identifier' => 'RootWarn', 'Module' => 'RootWarn') );
 &addCmdHook('OnJoin', ('CODEREF' => 'Cmdonjoin', 'Identifier' => 'OnJoin', 'Module' => 'OnJoin') );
 &addCmdHook('Rss', ('CODEREF' => 'Rss::Rss', 'Identifier' => 'Rss', 'Cmdstats' => 'Rss', 'Forker' => 1, 'Help' => 'rss') );
+&addCmdHook('RSSFeeds',('CODEREF' => 'RSSFeeds::RSS', 'Identifier' => 'RSSFeeds', 'Forker' => 1, 'Help' => 'rssfeeds', 'Cmdstats' => 'RSSFeeds', 'Module' => 'RSSFeeds') );
 &addCmdHook('sched(stats|info)', ('CODEREF' => 'scheduleList', ) );
 &addCmdHook('scramble', ('CODEREF' => 'scramble::scramble', 'Identifier' => 'scramble', 'Cmdstats' => 'scramble', 'Forker' => 1, 'Module' => 'scramble') );
 &addCmdHook('seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') );
index 4e9bb9c4bb24ea004a33496d170037584f1993c6..a4ea985004d63146dfef133f76e5ee5819422313 100644 (file)
@@ -70,6 +70,7 @@ sub setupSchedulers {
     &factoidCheck(2);  # takes a couple of seconds on a 486. defer it
 # TODO: convert to new format... or nuke altogether.
     &newsFlush(2);
+    &rssFeeds(2);
 
     # 1 for run straight away
     &uptimeLoop(1);
@@ -99,7 +100,8 @@ sub setupSchedulers {
 
 sub ScheduleThis {
     my ($interval, $codename, @args) = @_;
-    my $waittime = &getRandomInt($interval);
+    # Set to supllied value plus a random 0-60 seconds to avoid simultaneous runs
+    my $waittime = &getRandomInt("$interval-" . ($interval+&getRandomInt(60) ) );
 
     if (!defined $waittime) {
        &WARN("interval == waittime == UNDEF for $codename.");
@@ -124,10 +126,26 @@ sub ScheduleThis {
 #### LET THE FUN BEGIN.
 ####
 
+sub rssFeeds {
+  my $interval = $param{'rssFeedTime'} || 30;
+  if (@_) {
+    &ScheduleThis( $interval*60, 'rssFeeds' ); # minutes
+    return if ( $_[0] eq '2' );    # defer.
+  }
+  &Forker(
+    'RSSFeeds',
+    sub {
+      my $line = &RSSFeeds::RSS();
+      return unless ( defined $line );
+
+    }
+  );
+}
+
 sub randomQuote {
     my $interval = &getChanConfDefault('randomQuoteInterval', 60, $chan);
     if (@_) {
-       &ScheduleThis($interval, 'randomQuote');
+       &ScheduleThis($interval*60, 'randomQuote'); # every hour
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -153,7 +171,7 @@ sub randomFactoid {
 
     my $interval = &getChanConfDefault('randomFactoidInterval', 60, $chan);
     if (@_) {
-       &ScheduleThis($interval, 'randomFactoid');
+       &ScheduleThis($interval*60, 'randomFactoid'); # minutes
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -181,7 +199,7 @@ sub randomFactoid {
 
 sub logLoop {
     if (@_) {
-       &ScheduleThis(60, 'logLoop');
+       &ScheduleThis(3600, 'logLoop'); # 1 hour
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -250,7 +268,7 @@ sub logLoop {
 
 sub seenFlushOld {
     if (@_) {
-       &ScheduleThis(1440, 'seenFlushOld');
+       &ScheduleThis(86400, 'seenFlushOld'); # 1 day
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -292,7 +310,7 @@ sub seenFlushOld {
 
 sub newsFlush {
     if (@_) {
-       &ScheduleThis(60, 'newsFlush');
+       &ScheduleThis(3600, 'newsFlush'); # 1 hour
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -373,7 +391,7 @@ sub chanlimitCheck {
     my $mynick=$conn->nick();
 
     if (@_) {
-       &ScheduleThis($interval, 'chanlimitCheck');
+       &ScheduleThis($interval*60, 'chanlimitCheck'); # default 10 minutes
        return if ($_[0] eq '2');
     }
 
@@ -441,7 +459,7 @@ sub netsplitCheck {
     my ($s1,$s2);
 
     if (@_) {
-       &ScheduleThis(15, 'netsplitCheck');
+       &ScheduleThis(300, 'netsplitCheck'); # every 5 minutes
        return if ($_[0] eq '2');
     }
 
@@ -519,7 +537,7 @@ sub floodLoop {
     my $who;
 
     if (@_) {
-       &ScheduleThis(60, 'floodLoop'); # minutes.
+       &ScheduleThis(60, 'floodLoop'); # 1 minute
        return if ($_[0] eq '2');
     }
 
@@ -545,7 +563,7 @@ sub floodLoop {
 sub seenFlush {
     if (@_) {
        my $interval = &getChanConfDefault('seenFlushInterval', 60, $chan);
-       &ScheduleThis($interval, 'seenFlush');
+       &ScheduleThis($interval*60, 'seenFlush'); # minutes
        return if ($_[0] eq '2');
     }
 
@@ -588,7 +606,7 @@ sub leakCheck {
     my $count = 0;
 
     if (@_) {
-       &ScheduleThis(240, 'leakCheck');
+       &ScheduleThis(14400, 'leakCheck'); # every 4 hours
        return if ($_[0] eq '2');
     }
 
@@ -644,7 +662,7 @@ sub leakCheck {
 
 sub ignoreCheck {
     if (@_) {
-       &ScheduleThis(60, 'ignoreCheck');
+       &ScheduleThis(60, 'ignoreCheck'); # once every minute
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -672,7 +690,7 @@ sub ignoreCheck {
 
 sub ircCheck {
     if (@_) {
-       &ScheduleThis(15, 'ircCheck');
+       &ScheduleThis(300, 'ircCheck'); # every 5 minutes
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -740,7 +758,7 @@ sub ircCheck {
 
 sub miscCheck {
     if (@_) {
-       &ScheduleThis(120, 'miscCheck');
+       &ScheduleThis(7200, 'miscCheck'); # every 2 hours
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -798,7 +816,7 @@ sub miscCheck {
 
 sub miscCheck2 {
     if (@_) {
-       &ScheduleThis(240, 'miscCheck2');
+       &ScheduleThis(14400, 'miscCheck2'); # every 4 hours
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -856,7 +874,7 @@ sub uptimeLoop {
 #    return unless &IsParam('Uptime');
 
     if (@_) {
-       &ScheduleThis(60, 'uptimeLoop');
+       &ScheduleThis(3600, 'uptimeLoop'); # once per hour
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -866,7 +884,7 @@ sub uptimeLoop {
 sub slashdotLoop {
 
     if (@_) {
-       &ScheduleThis(60, 'slashdotLoop');
+       &ScheduleThis(3600, 'slashdotLoop'); # once per hour
        return if ($_[0] eq '2');
     }
 
@@ -889,7 +907,7 @@ sub slashdotLoop {
 sub plugLoop {
 
     if (@_) {
-       &ScheduleThis(60, 'plugLoop');
+       &ScheduleThis(3600, 'plugLoop'); # once per hour
        return if ($_[0] eq '2');
     }
 
@@ -911,7 +929,7 @@ sub plugLoop {
 
 sub kernelLoop {
     if (@_) {
-       &ScheduleThis(240, 'kernelLoop');
+       &ScheduleThis(14400, 'kernelLoop'); # once every 4 hours
        return if ($_[0] eq '2');
     }
 
@@ -969,7 +987,7 @@ sub wingateCheck {
 ### TODO: ??
 sub wingateWriteFile {
     if (@_) {
-       &ScheduleThis(60, 'wingateWriteFile');
+       &ScheduleThis(3600, 'wingateWriteFile'); # once per hour 
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -1001,7 +1019,7 @@ sub wingateWriteFile {
 
 sub factoidCheck {
     if (@_) {
-       &ScheduleThis(720, 'factoidCheck');
+       &ScheduleThis(43200, 'factoidCheck'); # ever 12 hours
        return if ($_[0] eq '2');       # defer.
     }
 
@@ -1046,7 +1064,7 @@ sub dccStatus {
     return unless (scalar keys %{ $dcc{CHAT} });
 
     if (@_) {
-       &ScheduleThis(10, 'dccStatus');
+       &ScheduleThis(600, 'dccStatus'); # every 10 minutes
        return if ($_[0] eq '2');       # defer.
     }
 
index e580fa0ece969f578dec4a5059007aebb514727f..c8a06371df23e0f14369406c9eebd54ec29547c4 100644 (file)
@@ -367,36 +367,28 @@ sub getRandom {
     return $array[int(rand(scalar @array))];
 }
 
-# Usage: &getRandomInt("30-60");
+# Usage: &getRandomInt("30-60"); &getRandomInt(5);
+# Desc : Returns a randomn integer between "X-Y" or 1 and the value passed
 sub getRandomInt {
-    my $str = $_[0];
+       my $str = shift;
 
-    if (!defined $str) {
-       &WARN("gRI: str == NULL.");
-       return;
-    }
-
-    srand();
-
-    if ($str =~ /^(\d+(\.\d+)?)$/) {
-       my $i = $1;
-       my $fuzzy = int(rand 5);
-       if ($i < 10) {
-           return $i;
+       if ( !defined $str ) {
+               &WARN("getRandomInt: str == NULL.");
+               return undef;
        }
-       if (rand > 0.5) {
-           return ($i - $fuzzy)*60;
+
+       if ( $str =~ /^(\d+(\.\d+)?)$/ ) {
+               return int( rand $str ) + 1;
+       } elsif ( $str =~ /^(\d+)-(\d+)$/ ) {
+               return $1 if $1 == $2;
+               my $min = $1 < $2 ? $1 : $2;    # Swap is backwords
+               my $max = $2 > $1 ? $2 : $1;
+               return int( rand( $max - $min + 1 ) ) + $min;
        } else {
-           return ($i + $fuzzy)*60;
-       }
-    } elsif ($str =~ /^(\d+)-(\d+)$/) {
-       return ($2 - $1)*int(rand $1)*60;
-    } else {
-       return $str;    # hope we're safe.
-    }
 
-    &ERROR("getRandomInt: invalid arg '$str'.");
-    return 1800;
+               # &ERROR("getRandomInt: invalid arg '$str'.");
+               return undef;
+       }
 }
 
 ##########
index 9f110e69e4fbac0acd73dd7e55d27cb538841400..353e95598f0ed3c58248a4f31224470eb10e6205 100644 (file)
@@ -97,6 +97,7 @@ sub openLog {
     }
 
     if (open(LOG, ">>$file{log}")) {
+       binmode(LOG, ":utf8");
        &status("Opened logfile $file{log}.");
        LOG->autoflush(1);
     } else {
@@ -375,9 +376,11 @@ sub debug_perl {
        &status("WARN: cannot open $file: $!");
        return;
     }
+    binmode(IN, ":utf8");
 
     # TODO: better filename.
     open(OUT, ">>debug.log");
+    binmode(OUT, ":utf8");
     print OUT "DEBUG: $str\n";
 
     # note: cannot call external functions because SIG{} does not allow us to.
@@ -412,6 +415,7 @@ sub openSQLDebug {
        delete $param{'SQLDebug'};
        return 0;
     }
+    binmode(SQLDEBUG, ":utf8");
 
     &status("Opened SQL Debug file: $param{'SQLDebug'}");
     return 1;