From bf69f09bd443e4471f191ab562beff5dc4ba50b5 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Mon, 22 Jun 2009 01:42:00 +0000 Subject: [PATCH] Modified to work with OAuth 1.0a git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@102 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/commands.yaml b/commands.yaml index 31c17be..7735988 100644 --- a/commands.yaml +++ b/commands.yaml @@ -1927,6 +1927,7 @@ TWITTER: |- my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; use Net::OAuth; + $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; use Digest::MD5 qw( md5_hex ); use HTTP::Request::Common; use LWP::UserAgent; @@ -1941,13 +1942,7 @@ TWITTER: |- $heap->{ 'twitterUsers' } = {}; } } - - my $len = length $what; - if( $len > 140 ) { - $kernel->post( $src, $replypath, "Your tweet exceed the 140-character limit by ".($len - 140)." character".($len>141?"s":""), $dest ); - return; - } - + if( exists( $heap->{ 'twitterUsers' }->{ uc( $who ) } ) ) { if( $heap->{ 'twitterUsers' }->{ uc( $who ) }->{ "state" } == 0 ) { my $oaRequest = Net::OAuth->request( "access token" )->new( @@ -1960,6 +1955,7 @@ TWITTER: |- nonce => $nonce, token => $heap->{ 'twitterUsers' }->{ uc( $who ) }->{ "request_token" }, token_secret => $heap->{ 'twitterUsers' }->{ uc( $who ) }->{ "request_secret" }, + verifier => $what, ); $oaRequest->sign(); my $response = $userAgent->request( POST $oaRequest->to_url() ); @@ -1978,7 +1974,15 @@ TWITTER: |- }; $kernel->post( $src, $replypath, "Congratulations! Destult now has a token to access your Twitter account. You shouldn't need to do this again.", $dest ); DumpFile( "twitterUsers.yaml", $heap->{ 'twitterUsers' } ); + return; } + + my $len = length $what; + if( $len > 140 ) { + $kernel->post( $src, $replypath, "Your tweet exceed the 140-character limit by ".($len - 140)." character".($len>141?"s":""), $dest ); + return; + } + my $oaRequest = Net::OAuth->request( "protected resource" )->new( consumer_key => $Destult::config{ "TWITTER_C_K" }, consumer_secret => $Destult::config{ "TWITTER_C_S" }, @@ -2016,7 +2020,8 @@ TWITTER: |- request_method => 'POST', signature_method => 'HMAC-SHA1', timestamp => time, - nonce => $nonce + nonce => $nonce, + callback => "oob", ); $oaRequest->sign(); @@ -2033,7 +2038,7 @@ TWITTER: |- $kernel->post( $src, $replypath, "You must grant Destult write access to your Twitter account. ". "To do so, please visit: ". "http://twitter.com/oauth/authorize?oauth_token=".($oaResponse->token)." ". - "and then re-run this command.", $dest ); + "and then re-run this command with the PIN given by Twitter as the argument.", $dest ); $heap->{ 'twitterUsers' }->{ uc( $who ) } = { request_token => $oaResponse->token, request_secret => $oaResponse->token_secret, @@ -2046,6 +2051,15 @@ TWITTER: |- DETWITTER: |- sub { my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; + + if( !exists( $heap->{ 'twitterUsers' } ) ) { + if( -e 'twitterUsers.yaml' ) { + $heap->{ 'twitterUsers' } = LoadFile( 'twitterUsers.yaml' ); + } else { + $heap->{ 'twitterUsers' } = {}; + } + } + if( exists( $heap->{ 'twitterUsers' }->{ uc( $who ) } ) ) { delete $heap->{ 'twitterUsers' }->{ uc( $who ) }; DumpFile( "twitterUsers.yaml", $heap->{ 'twitterUsers' } ); -- 2.11.0