Add karma. Yaaay karma.
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Tue, 16 Sep 2008 22:06:31 +0000 (22:06 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Tue, 16 Sep 2008 22:06:31 +0000 (22:06 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@60 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml
irc.pl

index 02565f2..d36f09a 100644 (file)
@@ -1583,3 +1583,57 @@ GETLINE: |-
     }
     $kernel->post( $src, $replypath, substr( $text, 0, 354 ), $dest );
   }
+
+KARMADOWN: |-
+  sub {
+    my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    if( !exists( $heap->{ "karma" } ) ) {
+      if( -e "karma.yaml" ) {
+        $heap->{ "karma" } = LoadFile( "karma.yaml" );
+      } else {
+        $heap->{ "karma" } = {};
+      }
+    }
+    if( !exists( $heap->{ "karma" }->{ uc( $what ) } ) ) {
+      $heap->{ "karma" }->{ uc( $what ) } = -1;
+    } else {
+      $heap->{ "karma" }->{ uc( $what ) }--;
+    }
+    DumpFile( "karma.yaml", $heap->{ 'karma' } );
+  }
+
+KARMAUP: |-
+  sub {
+    my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    if( !exists( $heap->{ "karma" } ) ) {
+      if( -e "karma.yaml" ) {
+        $heap->{ "karma" } = LoadFile( "karma.yaml" );
+      } else {
+        $heap->{ "karma" } = {};
+      }
+    }
+    if( !exists( $heap->{ "karma" }->{ uc( $what ) } ) ) {
+      $heap->{ "karma" }->{ uc( $what ) } = 1;
+    } else {
+      $heap->{ "karma" }->{ uc( $what ) }++;
+    }
+    DumpFile( "karma.yaml", $heap->{ 'karma' } );
+  }
+
+KARMA: |-
+  sub {
+    my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    if( !exists( $heap->{ "karma" } ) ) {
+      if( -e "karma.yaml" ) {
+        $heap->{ "karma" } = LoadFile( "karma.yaml" );
+      } else {
+        $kernel->post( $src, $replypath, "$what has no karma.", $dest );
+        return;
+      }
+    }
+    if( exists( $heap->{ "karma" }->{ uc( $what ) } ) ) {
+      $kernel->post( $src, $replypath, "$what has ".$heap->{ "karma" }->{ uc( $what ) }." karma", $dest );
+    } else {
+      $kernel->post( $src, $replypath, "$what has no karma.", $dest );
+    }
+  }
diff --git a/irc.pl b/irc.pl
index a1cf78b..fd8730f 100644 (file)
--- a/irc.pl
+++ b/irc.pl
@@ -203,13 +203,20 @@ sub on_public {
        }
        if( $cmd =~ /^[~].*/ ) {
                $kernel->post( "core", "cmd", $who, $msg, $self->{ "ssid" }, $dest->[0], "send_public_to" );
-       } elsif( $msg =~ m!(https?://[^[:space:]]+)!i && $self->{ "trapEnabled" } == 1 && length($1) >= 30 ) {
-               print( "IRC : URL Trapped: '$1' from $who\n" );
-               my $url = $1;
-               if( $self->{ "trap" } ) {
-                       $kernel->post( "core", "cmd", $who, "SHORTEN ".$self->{ "trap" }." $url", $self->{ "ssid" }, $dest->[0], "send_public_to" );
-               } else {
-                       $kernel->post( "core", "cmd", $who, "SHORTEN $url", $self->{ "ssid" }, $dest->[0], "send_public_to" );
+       } else {
+               if( $msg =~ m!(https?://[^[:space:]]+)!i && $self->{ "trapEnabled" } == 1 && length($1) >= 30 ) {
+                       print( "IRC : URL Trapped: '$1' from $who\n" );
+                       my $url = $1;
+                       if( $self->{ "trap" } ) {
+                               $kernel->post( "core", "cmd", $who, "SHORTEN ".$self->{ "trap" }." $url", $self->{ "ssid" }, $dest->[0], "send_public_to" );
+                       } else {
+                               $kernel->post( "core", "cmd", $who, "SHORTEN $url", $self->{ "ssid" }, $dest->[0], "send_public_to" );
+                       }
+               }
+               if( $msg =~ m/(.+)--$/ ) {
+                       $kernel->post( "core", "cmd", $who, "KARMADOWN $1", $self->{ "ssid"}, $dest->[0], "send_public_to" );
+               } elsif( $msg =~ m/(.+)\+\+$/ ) {
+                       $kernel->post( "core", "cmd", $who, "KARMAUP $1", $self->{ "ssid"}, $dest->[0], "send_public_to" );
                }
        }
 }