From fa4af87af811ee8834b32425bc0996b26a03dbdf Mon Sep 17 00:00:00 2001 From: pdbogen Date: Tue, 16 Sep 2008 22:06:31 +0000 Subject: [PATCH] Add karma. Yaaay karma. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@60 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ irc.pl | 21 ++++++++++++++------- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/commands.yaml b/commands.yaml index 02565f2..d36f09a 100644 --- a/commands.yaml +++ b/commands.yaml @@ -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 --- 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" ); } } } -- 2.11.0