[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Factoid-Lookup Query



I was kinda waiting for someone to write a patch like this, but no-one 
has... This basically allows you to use a regex to search an infobot's 
factoids. It has been written for Infobot 0.44.3.
On large infobot's this may be slow - on my 'hacked' desktop version of 
infobot 0.44.3 with 10,000 factoids it takes about 5 seconds on my Pentium 
90 with 16mgs of RAM.
As yet, it's only been tested on my infobot, so if anyone finds any bugs, 
(1) I won't be surprised (2) Please tell me about them.
I added the following code to extras.pl, though I'd of thought it can be 
added to myroutines.pl too.

-- Add to Extras.pl --
if ($message =~ m/^fq (is|are) (.+)/i) {
	my @dbquery_keys = getDBMKeys($1);
	my $dbquery_regex = $2;
	($dbquery_retvar, $dbquery_numfound) = '';
	$dbquery_regex =~ s/^\/(.*)\/$/$1/;
	if (eval { $line =~ /($dbquery_regex)?/ }) {
		foreach $dbquery_key (@dbquery_keys) {
			if ($dbquery_key =~ m/$dbquery_regex/i) {
				$dbquery_retvar .= "\n$dbquery_key";
				$dbquery_numfound++;
			}
		}
			if ($dbquery_retvar) {
			&msg($who, "Found: $dbquery_numfound result(s) $dbquery_retvar");
		} else {
			&msg($who, "Sorry, nothing found matching $dbquery_regex");
		}
		} else {
		&msg($who, "$dbquery_regex an invalid regex...");
	}
	return "NOREPLY";
}

-- End Code --

Using that exactly as it is above, you'd type 'fq is .*w$' to find factoids 
ending in w in the 'is' database.
Finally, is there enough interest in using 0.44.3 as a console-mode bot to 
warrant me posting my patch that allows me to?

-- Pete Sergeant
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com