From: pdbogen Date: Sat, 6 Jun 2009 20:16:20 +0000 (+0000) Subject: Factoids can now do something with an "argument," by including $arg. Only works for... X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=4ea926f942abe351b14ce6a32d1ef713060d73c2;p=destult.git Factoids can now do something with an "argument," by including $arg. Only works for one-word factoids. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@101 088b83a4-0077-4247-935c-42ec02c2848b --- diff --git a/commands.yaml b/commands.yaml index 0c30718..31c17be 100644 --- a/commands.yaml +++ b/commands.yaml @@ -378,20 +378,29 @@ PARSE: |- 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 { @@ -414,9 +423,10 @@ PARSE: |- 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 ); } diff --git a/core.pl b/core.pl index 7ab74ac..ce550d2 100644 --- a/core.pl +++ b/core.pl @@ -185,7 +185,12 @@ sub cmd { } 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 } ); + } } }