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;
$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(
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() );
};
$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" },
request_method => 'POST',
signature_method => 'HMAC-SHA1',
timestamp => time,
- nonce => $nonce
+ nonce => $nonce,
+ callback => "oob",
);
$oaRequest->sign();
$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,
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' } );