]> git.donarmstrong.com Git - infobot.git/blobdiff - src/CommandStubs.pl
- nice patch from Phil Edwards <pme@devphil.com>. Thanks!
[infobot.git] / src / CommandStubs.pl
index 5651c715b4ab57f51149bee6670e22e3048c97d2..cc0a3fb926a759a0eaaeceff275cf1f303beeb62 100644 (file)
@@ -14,6 +14,7 @@ use vars qw(%channels %cache %mask %userstats %myModules %cmdstats
 use vars qw($total $x $type $i $good);
 
 $babel_lang_regex = "fr|sp|es|po|pt|it|ge|de|gr|en|zh|ja|jp|ko|kr|ru";
+$w3search_regex   = "google";
 
 ### COMMAND HOOK IMPLEMENTATION.
 # addCmdHook("SECTION", 'TEXT_HOOK',
@@ -222,9 +223,6 @@ sub parseCmdHook {
 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
        'Cmdstats' => 'Uptime') );
 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
-&addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
-       'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
-       'Forker' => 1, 'Help' => 'freshmeat') );
 &addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) );
 &addCmdHook("extra", 'weather', ('CODEREF' => 'Weather::Weather',
        'Identifier' => 'weather', 'Help' => 'weather',
@@ -247,8 +245,8 @@ sub parseCmdHook {
 &addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query',
        'Identifier' => 'exchange', 'Cmdstats' => 'exchange',
        'Forker' => 1) );
-&addCmdHook("extra", 'botmail', ('CODEREF' => 'botmail::parse',
-       'Identifier' => 'botmail' ) );
+&addCmdHook("extra", '(botmail|message)', ('CODEREF' => 'botmail::parse',
+       'Identifier' => 'botmail', 'Cmdstats' => 'botmail') );
 
 ###
 ### END OF ADDING HOOKS.
@@ -297,7 +295,7 @@ sub Modules {
     }
 
     # google searching. Simon++
-    if ($message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) {
+    if ($message =~ /^(?:search\s+)?($w3search_regex)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) {
        return unless (&hasParam("wwwsearch"));
 
        &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
@@ -331,22 +329,24 @@ sub Modules {
            # even more uglier with channel/time arguments.
            my $c       = $chan;
 #          my $c       = $chan || "PRIVATE";
-           my $where   = "type=".&dbQuote($type);
-           $where      .= " AND channel=".&dbQuote($c) if (defined $c);
+           my $where   = "type=".&sqlQuote($type);
+           $where      .= " AND channel=".&sqlQuote($c) if (defined $c);
            &DEBUG("not using chan arg") if (!defined $c);
-           my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats"
+           my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats"
                        ." WHERE ".$where ))[0];
 
            if (!defined $arg or $arg =~ /^\s*$/) {
                # this is way fucking ugly.
 
-               my %hash = &dbGetCol("stats", "nick,counter",
-                       $where." ORDER BY counter DESC LIMIT 3", 1);
+               # TODO convert $where to hash
+               my %hash = &sqlSelectColHash("stats", "nick,counter",
+                       { },
+                       $where." ORDER BY counter DESC LIMIT 3", 1
+               );
                my $i;
                my @top;
 
                # unfortunately we have to sort it again!
-               # todo: make dbGetCol return hash and array? too much effort.
                my $tp = 0;
                foreach $i (sort { $b <=> $a } keys %hash) {
                    foreach (keys %{ $hash{$i} }) {
@@ -367,8 +367,9 @@ sub Modules {
                    &pSReply("zero counter for \037$type\037.");
                }
            } else {
-               my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats".
-                       " WHERE $where AND nick=".&dbQuote($arg) ))[0];
+               # TODO convert $where to hash and use a sqlSelect
+               my $x = (&sqlRawReturn("SELECT SUM(counter) FROM stats".
+                       " WHERE $where AND nick=".&sqlQuote($arg) ))[0];
 
                if (!defined $x) {      # !defined.
                    &pSReply("$arg has not said $type yet.");
@@ -376,8 +377,10 @@ sub Modules {
                }
 
                # defined.
-               my @array = &dbGet("stats", "nick",
-                       $where." ORDER BY counter", 1);
+               # TODO convert $where to hash
+               my @array = &sqlSelect("stats", "nick", undef,
+                       $where." ORDER BY counter", 1
+               );
                my $good = 0;
                my $i = 0;
                for($i=0; $i<scalar @array; $i++) {
@@ -429,8 +432,8 @@ sub Modules {
            $args       =~ s/^["']|["']$//g;
        }
 
-       if (length $args == 1) {
-           &msg($who,"search string is too short.");
+       if (length $args < 2 && &IsFlag("o") ne "o") {
+           &msg($who, "search string is too short.");
            return;
        }
 
@@ -571,19 +574,6 @@ sub Modules {
     return "CONTINUE";
 }
 
-# Freshmeat. xk++
-sub freshmeat {
-    my ($query) = @_;
-
-    if (!defined $query) {
-       &help("freshmeat");
-       &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
-       return;
-    }
-
-    &Freshmeat::Freshmeat($query);
-}
-
 # Uptime. xk++
 sub uptime {
     my $count = 1;
@@ -619,12 +609,12 @@ sub seen {
 
     &seenFlush();      # very evil hack. oh well, better safe than sorry.
 
-    ### TODO: Support &dbGetColInfo(); like in &FactInfo();
+    # TODO: convert to &sqlSelectRowHash();
     my $select = "nick,time,channel,host,message";
     if ($person eq "random") {
        @seen = &randKey("seen", $select);
     } else {
-       @seen = &dbGet("seen", $select, "nick=".&dbQuote($person) );
+       @seen = &sqlSelect("seen", $select, { nick => $person } );
     }
 
     if (scalar @seen < 2) {
@@ -920,22 +910,24 @@ sub textstats_main {
     # even more uglier with channel/time arguments.
     my $c      = $chan;
 #    my $c     = $chan || "PRIVATE";
-    my $where  = "channel=".&dbQuote($c) if (defined $c);
     &DEBUG("not using chan arg") if (!defined $c);
-    my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats"
-               ." WHERE ".$where ))[0];
+
+    # example of converting from RawReturn to sqlSelect.
+    my $where_href = (defined $c) ? { channel => $c } : "";
+    my $sum = &sqlSelect("stats", "SUM(counter)", $where_href);
 
     if (!defined $arg or $arg =~ /^\s*$/) {
        # this is way fucking ugly.
        &DEBUG("_stats: !arg");
 
-       my %hash = &dbGetCol("stats", "nick,counter",
-               $where." ORDER BY counter DESC LIMIT 3", 1);
+       my %hash = &sqlSelectColHash("stats", "nick,counter",
+               $where_href,
+               " ORDER BY counter DESC LIMIT 3", 1
+       );
        my $i;
        my @top;
 
        # unfortunately we have to sort it again!
-       # todo: make dbGetCol return hash and array? too much effort.
        my $tp = 0;
        foreach $i (sort { $b <=> $a } keys %hash) {
            foreach (keys %{ $hash{$i} }) {
@@ -957,8 +949,10 @@ sub textstats_main {
            &pSReply("zero counter for \037$type\037.");
        }
     } else {
-       my %hash = &dbGetCol("stats", "type,counter",
-               "$where AND nick=".&dbQuote($arg) );
+       # TODO add nick to where_href
+       my %hash = &sqlSelectColHash("stats", "type,counter",
+               $where_href, " AND nick=".&sqlQuote($arg)
+       );
        # this is totally fucked... needs to be fixed... and cleaned up.
        my $total;
        my $good;
@@ -968,7 +962,8 @@ sub textstats_main {
        foreach (keys %hash) {
            &DEBUG("_stats: hash{$_} => $hash{$_}");
            # ranking.
-           my @array = &dbGet("stats", "nick",
+           # TODO convert $where to hash
+           my @array = &sqlSelect("stats", "nick", undef,
                $where." ORDER BY counter", 1);
            $good = 0;
            $ii = 0;