From 165f50e80b31cf4f497eb4674b99a9b26bb9fcd2 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Mon, 14 Sep 2009 16:57:48 +0000 Subject: [PATCH] Notify the user if they have memos waiting if they're unidentified, isntead of remaining silent. Add a USAGE message to ~password. Add a bit of console debugging to ~TWITTER. git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@106 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 25 +++++++++++++++++++++++++ core.pl | 11 +++++++---- irc.pl | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/commands.yaml b/commands.yaml index eceac67..8c7f463 100644 --- a/commands.yaml +++ b/commands.yaml @@ -282,6 +282,10 @@ PASSWORD: |- sub { use Digest::MD5 qw( md5_hex ); my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; + if( $what !~ /[^ ]+ [^ ]+/ ) { + $kernel->post( $src, $replypath, "Usage: PASSWORD ", $dest ); + return; + } my( $old, $new ) = split( / /, $what, 2 ); if( exists( $heap->{ 'users' }->{ uc( $who ) } ) ) { if( $heap->{ 'users' }->{ uc( $who ) } eq md5_hex( $old ) ) { @@ -1571,6 +1575,26 @@ CHECKMEMO: |- DumpFile( "memos.yaml", $heap->{ 'memo' } ); } +COUNTMEMO: |- + sub { + my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; + if( !exists( $heap->{ 'memo' } ) ) { + $heap->{ 'memo' } = {}; + } + if( !exists( $heap->{ 'memo' }->{ uc( $who ) } ) ) { + $kernel->post( $src, $replypath, "No memos found.", $dest ); + return 1; + } + my @memos = @{ $heap->{ 'memo' }->{ uc( $who ) } }; + my $count = scalar @memos; + $kernel->post( + $src, + $replypath, + "You have $count memo".($count==1?"":"s")." waiting. To check your memos, please first REGISTER (if you haven't already) and then IDENTIFY.", + $dest + ); + } + MEMOLIST: |- sub { my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; @@ -1997,6 +2021,7 @@ TWITTER: |- my $response = $userAgent->request( POST $oaRequest->to_url() ); if( !$response->is_success() ) { print( "TWITTER: Error: ".$response->status_line(), "\n" ); + print( "TWITTER: URL was '".$oaRequest->to_url()."'\n" ); if( $response->code == "401" ) { $kernel->post( $src, $replypath, "401 from Twitter: This generally means Destult ". "has been de-authorized to update your Twitter ". diff --git a/core.pl b/core.pl index ce550d2..36f4004 100644 --- a/core.pl +++ b/core.pl @@ -40,9 +40,12 @@ sub seen { } $heap->{ 'seen' }->{ uc( $who ) } = time; if( exists( $heap->{ 'memo' } ) && - exists( $heap->{ 'memo' }->{ uc( $who ) } ) && - exists( $heap->{ 'identified' }->{ $src.uc( $who ) } ) ) { - $kernel->yield( "cmd", $who, "CHECKMEMO", $src, $who, "send_private", $trusted ); + exists( $heap->{ 'memo' }->{ uc( $who ) } ) ) { + if( exists( $heap->{ 'identified' }->{ $src.uc( $who ) } ) ) { + $kernel->yield( "cmd", $who, "CHECKMEMO", $src, $who, "send_private", $trusted ); + } else { + $kernel->yield( "cmd", $who, "COUNTMEMO", $src, $who, "send_private", $trusted ); + } } } @@ -246,7 +249,6 @@ sub advertise { # this should check for hooks stored on the heap. TODO. sub on_public { my( $kernel, $heap, $who, $what, $src, $dest, $replypath, $trusted ) = @_[ KERNEL, HEAP, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5 ]; - $kernel->yield( "seen", $who, $what, $src, $dest, $replypath, $trusted ); my $cmd = ( split( / /, $what, 2 ) )[0]; # Check for the presence of a command if( $cmd =~ /^~.*/ ) { @@ -266,4 +268,5 @@ sub on_public { $kernel->yield( "cmd", $who, "KARMAUP $1", $src, $dest, $replypath, $trusted ); } } + $kernel->yield( "seen", $who, $what, $src, $dest, $replypath, $trusted ); } diff --git a/irc.pl b/irc.pl index 0b8eee4..a57ba85 100644 --- a/irc.pl +++ b/irc.pl @@ -209,8 +209,8 @@ sub on_private { $msg =~ s/(\x3)[0-9]{0,2}//g; $msg =~ s/\x02//g; $cmd = ( split( / /, $msg, 2 ) )[0]; - $kernel->post( "core", "seen", $who, $msg, $self->{ "ssid" }, $who, "send_private", 1 ); $kernel->post( "core", "cmd", $who, $msg, $self->{ "ssid" }, $who, "send_private", 1 ); + $kernel->post( "core", "seen", $who, $msg, $self->{ "ssid" }, $who, "send_private", 1 ); } sub send_public { -- 2.11.0