Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

there is not twitter support. it's unsecure right now because i haven…

…'t added nick serv authentication, but that's just a matter of writing in a simple call back.
  • Loading branch information...
commit 8d7f236a4abbd4444d966e72506e5358820a9a74 1 parent 539ff8a
uberj authored
View
40 derp/plugins/tweet.py
@@ -0,0 +1,40 @@
+from zope.interface import implements
+from twisted.plugin import IPlugin
+from icommand import ICommand
+
+import twitter
+from ConfigParser import ConfigParser
+TWIT_CONFIG = "/home/uberj/Herp/derp/derp/plugins/twitter.cfg"
+
+class Tweet(object):
+ implements(IPlugin,ICommand)
+ commands = {'tweet':'tweet'}
+ name = "Tweet"
+ def __init__( self ):
+ self.authenticate()
+
+ def tweet(self, bundle):
+ text = bundle['sensory_input']
+ user = bundle['user']
+ if user == self.user:
+ twitter.Twitter(auth=self.oauth).statuses.update(status=text)
+ else:
+ return "Nice try "+user
+
+ def authenticate( self ):
+ self.oauth = None
+ print "Authenticating..."
+ config = ConfigParser()
+ config.read(TWIT_CONFIG)
+ self.user = config.get('twitter','user')
+ consumer_key = config.get('twitter','consumer_key')
+ consumer_secret = config.get('twitter','consumer_secret')
+ token_key = config.get('twitter','token_key')
+ token_secret = config.get('twitter','token_secret')
+
+ self.oauth = twitter.OAuth(token_key, token_secret,consumer_key, consumer_secret)
+
+ print "Authenticated!"
+ return
+
+tweet = Tweet()
View
8 derp/plugins/twitter.default.cfg
@@ -0,0 +1,8 @@
+[twitter]
+user=
+consumer_key=
+consumer_secret=
+token_key=
+token_secret=
+
+
View
65 derp/plugins/twitter.py
@@ -1,65 +0,0 @@
-from zope.interface import implements
-from twisted.plugin import IPlugin
-from icommand import ICommand
-
-from twitter import TwitterHTTPError,oauth_dance
-from ConfigParser import ConfigParser
-config = "twitter.cfg"
-
-class Twitter(object):
- implements(IPlugin,ICommand)
- commands = {'tweet':'tweet'}
- name = "Twitter"
- twitter = None
- def tweet(self, bundle):
- text = bundle['sensory_input']
-
- # Function taken from Rob McGuire-Dale
- # https://github.com/robatron/twitswarm/blob/master/twitswarm.py
- def authenticate(self):
- config = ConifgParser()
- config.read(config)
- app_name = "irc-bot-uberj"
- app_name = config.get('twitter','app_name')
- consumer_key = config.get('twitter','consumer_key')
- consumer_secret = config.get('twitter','consumer_secret')
- oauth = None
- print "Authenticating..."
- try:
- oauth_file = open("oauth.dat", 'r')
- oauth = pickle.load(oauth_file)
- except IOError:
- print "Oauth file not found. Starting twitter oauth dance."
- try:
- token_key, token_secret = oauth_dance.oauth_dance(
- app_name, consumer_key,
- consumer_secret)
- oauth = twitter.OAuth(token_key, token_secret,consumer_key, consumer_secret)
- oauth_file = open("oauth.dat",'w')
- pickle.dump(oauth, oauth_file)
- except TwitterHTTPError:
- print "Authentication error!"
- print "ding!"
- return
- self.oauth = Twitter(auth=oauth)
- print "Authenticated!"
-
- def authenticate(self):
- self.oauth = None
- print "Authenticating..."
- config = ConifgParser()
- config.read(config)
- app_name = "irc-bot-uberj"
- consumer_key = config.get('twitter','consumer_key')
- consumer_secret = config.get('twitter','consumer_secret')
- token_key = config.get('twitter','token_key')
- token_secret = config.get('twitter','token_secret')
-
- try:
- self.oauth = twitter.OAuth(token_key, token_secret,consumer_key, consumer_secret)
- except TwitterHTTPError:
- print "Authentication error!"
- return "ding!"
-
- self.twitter = Twitter(auth=oauth)
- print "Authenticated!"
Please sign in to comment.
Something went wrong with that request. Please try again.