Move parsing/handling of IRC messages into the core, to pave the way towards configur...
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Tue, 28 Oct 2008 15:48:39 +0000 (15:48 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Tue, 28 Oct 2008 15:48:39 +0000 (15:48 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@72 088b83a4-0077-4247-935c-42ec02c2848b

core.pl

diff --git a/core.pl b/core.pl
index 8706b37..0b8a2fb 100644 (file)
--- a/core.pl
+++ b/core.pl
@@ -29,6 +29,7 @@ POE::Session->create(
                unidentify => \&unidentify,
                advertise => \&advertise,
                seen => \&seen,
+               core_public => \&on_public,
        },
 ) or die( "Unable to create core POE session." );
 
@@ -207,3 +208,29 @@ sub advertise {
                $kernel->delay_set( "advertise", $period, $which );
        }
 }
+
+# This is called whenever a public message is received, from any source. In the future,
+# this should check for hooks stored on the heap. TODO.
+sub on_public {
+       my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_[ KERNEL, HEAP, ARG0, ARG1, ARG2, ARG3, ARG4 ];
+       $kernel->yield( "seen", $who, $what, $src, $dest, $replypath );
+       my $cmd = ( split( / /, $what, 2 ) )[0];
+       # Check for the presence of a command
+       if( $cmd =~ /^~.*/ ) {
+               $kernel->yield( "cmd", $who, $what, $src, $dest, $replypath );
+       } else {
+               # Handle URLs
+               # TODO: Find a new place to put trap config
+               if( $what =~ m!(https?://[^[:space:]]+)!i ) {
+                       print( "IRC : URL Trapped: '$1' from $who\n" );
+                       my $url = $1;
+                       $kernel->yield( "cmd", $who, "TITLE $url", $src, $dest, $replypath );
+               }
+               # Handle Karma
+               if( $what =~ m/^([^ ]+)--$/ ) {
+                       $kernel->yield( "cmd", $who, "KARMADOWN $1", $src, $dest, $replypath );
+               } elsif( $what =~ m/^([^ ]+)\+\+$/ && $what !~ m/DC\+\+$/i ) {
+                       $kernel->yield( "cmd", $who, "KARMAUP $1", $src, $dest, $replypath );
+               }
+       }
+}