change authentication to over IRC process
This commit is contained in:
		
							parent
							
								
									3ba38bd90d
								
							
						
					
					
						commit
						699f550ba3
					
				| @ -39,40 +39,18 @@ class Twitter(Module): | |||||||
|         Module.__init__(self, config, server, modlist) |         Module.__init__(self, config, server, modlist) | ||||||
| 
 | 
 | ||||||
|         # begin oauth magic |         # begin oauth magic | ||||||
|         consumer_key = 'N2aSGxBP8t3cCgWyF1B2Aw' |         self.consumer_key = 'N2aSGxBP8t3cCgWyF1B2Aw' | ||||||
|         consumer_secret = '0aQPEV4K3MMpicfi2lDtCP5pvjsKaqIpfuWtsPzx8' |         self.consumer_secret = '0aQPEV4K3MMpicfi2lDtCP5pvjsKaqIpfuWtsPzx8' | ||||||
| 
 | 
 | ||||||
|         request_token_url = 'https://api.twitter.com/oauth/request_token' |         self.request_token_url = 'https://api.twitter.com/oauth/request_token' | ||||||
|         access_token_url = 'https://api.twitter.com/oauth/access_token' |         self.access_token_url = 'https://api.twitter.com/oauth/access_token' | ||||||
|         authorize_url = 'https://api.twitter.com/oauth/authorize' |         self.authorize_url = 'https://api.twitter.com/oauth/authorize' | ||||||
| 
 | 
 | ||||||
|         consumer = oauth.Consumer(consumer_key, consumer_secret) |         self.consumer = oauth.Consumer(self.consumer_key, self.consumer_secret) | ||||||
|         client = oauth.Client(consumer) |         self.client = oauth.Client(self.consumer) | ||||||
| 
 | 
 | ||||||
|         # get request token |         # create a default twitter API account, in case we never auth | ||||||
|         resp, content = client.request(request_token_url, "GET") |         self.twit = twitter.Api() | ||||||
|         if resp['status'] != '200': |  | ||||||
|             raise Exception("Invalid response %s." % resp['status']) |  | ||||||
| 
 |  | ||||||
|         request_token = dict(urlparse.parse_qsl(content)) |  | ||||||
| 
 |  | ||||||
|         # have the user auth |  | ||||||
|         print('Go to the following link in your browser:') |  | ||||||
|         print('%s?oauth_token=%s' % (authorize_url, request_token['oauth_token'])) |  | ||||||
| 
 |  | ||||||
|         # verify user auth |  | ||||||
|         oauth_verifier = raw_input('Enter the PIN you are provided: ') |  | ||||||
| 
 |  | ||||||
|         # request access token |  | ||||||
|         token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret']) |  | ||||||
|         token.set_verifier(oauth_verifier) |  | ||||||
|         client = oauth.Client(consumer, token) |  | ||||||
| 
 |  | ||||||
|         resp, content = client.request(access_token_url, "POST") |  | ||||||
|         access_token = dict(urlparse.parse_qsl(content)) |  | ||||||
| 
 |  | ||||||
|         # finally, create the twitter API object |  | ||||||
|         self.twit = twitter.Api(consumer_key, consumer_secret, access_token['oauth_token'], access_token['oauth_token_secret']) |  | ||||||
| 
 | 
 | ||||||
|     def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): |     def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): | ||||||
|         """ |         """ | ||||||
| @ -103,6 +81,30 @@ class Twitter(Module): | |||||||
|                         return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet=tweet)) |                         return self.reply(connection, replypath, self.tweet_or_retweet_text(tweet=tweet)) | ||||||
|                 except twitter.TwitterError as e: |                 except twitter.TwitterError as e: | ||||||
|                     return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e)) |                     return self.reply(connection, replypath, 'Couldn\'t obtain status: ' + str(e)) | ||||||
|  |             elif whats[1] == 'gettoken': | ||||||
|  |                 # get request token | ||||||
|  |                 resp, content = self.client.request(self.request_token_url, "GET") | ||||||
|  |                 if resp['status'] != '200': | ||||||
|  |                     raise Exception("Invalid response %s." % resp['status']) | ||||||
|  | 
 | ||||||
|  |                 self.request_token = dict(urlparse.parse_qsl(content)) | ||||||
|  | 
 | ||||||
|  |                 # have the user auth | ||||||
|  |                 return self.reply(connection, replypath, 'Go to the following link in your browser: %s?oauth_token=%s and then send me the pin.' % (self.authorize_url, self.request_token['oauth_token'])) | ||||||
|  |             elif whats[1] == 'auth' and len(whats) >= 3: | ||||||
|  |                 oauth_verifier = whats[2] | ||||||
|  | 
 | ||||||
|  |                 # request access token | ||||||
|  |                 token = oauth.Token(self.request_token['oauth_token'], self.request_token['oauth_token_secret']) | ||||||
|  |                 token.set_verifier(oauth_verifier) | ||||||
|  |                 client = oauth.Client(self.consumer, token) | ||||||
|  | 
 | ||||||
|  |                 resp, content = client.request(self.access_token_url, "POST") | ||||||
|  |                 self.access_token = dict(urlparse.parse_qsl(content)) | ||||||
|  | 
 | ||||||
|  |                 # finally, create the twitter API object | ||||||
|  |                 self.twit = twitter.Api(self.consumer_key, self.consumer_secret, self.access_token['oauth_token'], self.access_token['oauth_token_secret']) | ||||||
|  |                 return self.reply(connection, replypath, 'The bot is now logged in.') | ||||||
| 
 | 
 | ||||||
|     def tweet_or_retweet_text(self, tweet, print_source=False): |     def tweet_or_retweet_text(self, tweet, print_source=False): | ||||||
|         """ |         """ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user