sub {
use YAML qw(LoadFile DumpFile);
my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
- print( "PARSE: $what is ".$heap->{ 'db' }->{ uc( $what ) }."\n" );
+ my $factoid = $what;
+ my $arg="";
+ if( !exists( $heap->{ 'db' }->{ uc( $what ) } ) ) {
+ ($factoid,$arg) = split( / /, $what, 2 );
+ if( !exists( $heap->{ 'db' }->{ uc( $factoid ) } ) ) {
+ $kernel->post( $src, $replypath, "Attempted to parse non-existent factoid '$what'", $dest );
+ return;
+ }
+ }
+ print( "PARSE: $factoid is ".$heap->{ 'db' }->{ uc( $factoid ) }."\n" );
if( !exists( $heap->{ 'factoidAccess' } ) && -e 'factoidAccess.yaml' ) {
$heap->{ 'factoidAccess' } = LoadFile( 'factoidAccess.yaml' );
}
- if( exists( $heap->{ 'factoidAccess' }->{ uc( $what ) } ) &&
+ if( exists( $heap->{ 'factoidAccess' }->{ uc( $factoid ) } ) &&
( !exists( $heap->{ 'identified' }->{ $src.uc( $who ) } ) ||
- accessLevel( $kernel, $heap, uc( $who ), $src ) < $heap->{ 'factoidAccess' }->{ uc( $what ) } ) ) {
- $kernel->post( $src, $replypath, "$who: An access level of ".$heap->{ 'factoidAccess' }->{ uc( $what ) }." is required for the factoid '$what'", $dest );
+ accessLevel( $kernel, $heap, uc( $who ), $src ) < $heap->{ 'factoidAccess' }->{ uc( $factoid ) } ) ) {
+ $kernel->post( $src, $replypath, "$who: An access level of ".$heap->{ 'factoidAccess' }->{ uc( $factoid ) }." is required for the factoid '$factoid'", $dest );
return;
}
- my( $response, $author ) = split( / -- /, $heap->{ 'db' }->{ uc( $what ) } );
+ my( $response, $author ) = split( / -- /, $heap->{ 'db' }->{ uc( $factoid ) } );
if( $author ) {
$author = " -- ".$author;
} else {
return;
} else {
my @responses = split( /\|/, $response );
- $response = "$what is ".$responses[ int( rand( scalar( @responses ) ) ) ].$author;
+ $response = "$factoid is ".$responses[ int( rand( scalar( @responses ) ) ) ].$author;
}
$response =~ s/\$nick/$who/gi;
+ $response =~ s/\$arg/$arg/gi;
$kernel->post( "$src", $replypath, $response, $dest );
}
} elsif( exists( $heap->{ 'db' }->{ uc( $what ) } ) && !$noparse ) {
&{ $heap->{ 'commands' }->{ 'PARSE' } }( $kernel, $heap, $who, $what, $src, { dest => $dest, src=>$who, no_throttle => $no_throttle, trusted => $trusted }, $replypath );
} else {
- $kernel->post( $src, "send_private", "Huh?", { dest => $who, src => $who, trusted => $trusted } );
+ my( $first, $rest ) = split( / /, $what, 2 );
+ if( exists( $heap->{ 'db' }->{ uc( $first ) } ) ) {
+ &{ $heap->{ 'commands' }->{ 'PARSE' } }( $kernel, $heap, $who, $what, $src, { dest => $dest, src=>$who, no_throttle => $no_throttle, trusted => $trusted }, $replypath );
+ } else {
+ $kernel->post( $src, "send_private", "Huh?", { dest => $who, src => $who, trusted => $trusted } );
+ }
}
}