Permalink
Browse files

twitter here we come

  • Loading branch information...
1 parent cd063b2 commit 539ff8a482014cb11afde25db28dc261432fc1f1 uberj committed May 9, 2011
View
3 .gitignore
@@ -1,5 +1,8 @@
+derp/plugins/twitter_notes
derp/plugins/dropin.*
logfile
db/
*.pyc
test.py
+derp/plugins/twitter.cfg
+derp/tests/
View
0 derp/IBOT/ibot/__init__.py
No changes.
View
12 derp/IBOT/ibot/iiterator.py
@@ -1,12 +0,0 @@
-from twisted.plugin import getPlugins,IPlugin
-import plugins
-
-def main():
- for command in getPlugins(IPlugin,plugins):
- print "In the loop"
- bundle = "blah"
- print command.cmd(bundle)
-
-if __name__=='__main__':
- main()
-
View
0 derp/IBOT/ibot/plugins/__init__.py
No changes.
View
3 derp/IBOT/ibot/plugins/__init__.py.bak
@@ -1,3 +0,0 @@
-from twisted.plugin import pluginPackagePaths
-__path__.extend(pluginPackagePaths(__name__))
-__all__ = []
View
14 derp/IBOT/ibot/plugins/command.py
@@ -1,14 +0,0 @@
-from zope.interface import implements
-from twisted.plugin import IPlugin
-from icommand import ICommand
-
-class Command(object):
- implements(IPlugin,ICommand)
-
- def __init__(self):
- self.x=3
- self.command = "ping"
- def cmd(self,bundle):
- print bundle
- print "asdf?"
-bot_command = Command()
View
95 derp/IBOT/ibot/plugins/dropin.cache
@@ -1,95 +0,0 @@
-(dp1
-S'icommand'
-p2
-ccopy_reg
-_reconstructor
-p3
-(ctwisted.plugin
-CachedDropin
-p4
-c__builtin__
-object
-p5
-NtRp6
-(dp7
-S'moduleName'
-p8
-S'ibot.plugins.icommand'
-p9
-sS'description'
-p10
-NsS'plugins'
-p11
-(lp12
-sbsS'command'
-p13
-g3
-(g4
-g5
-NtRp14
-(dp15
-S'moduleName'
-p16
-S'ibot.plugins.command'
-p17
-sS'description'
-p18
-NsS'plugins'
-p19
-(lp20
-g3
-(ctwisted.plugin
-CachedPlugin
-p21
-g5
-NtRp22
-(dp23
-S'provided'
-p24
-(lp25
-ctwisted.plugin
-IPlugin
-p26
-acibot.plugins.icommand
-ICommand
-p27
-asS'dropin'
-p28
-g14
-sS'name'
-p29
-S'bot_command'
-p30
-sg18
-NsbasbsS'something'
-p31
-g3
-(g4
-g5
-NtRp32
-(dp33
-g8
-S'ibot.plugins.something'
-p34
-sg10
-Nsg11
-(lp35
-g3
-(g21
-g5
-NtRp36
-(dp37
-S'provided'
-p38
-(lp39
-g26
-ag27
-asS'dropin'
-p40
-g32
-sS'name'
-p41
-S'bot_command'
-p42
-sg10
-Nsbasbs.
View
11 derp/IBOT/ibot/plugins/icommand.py
@@ -1,11 +0,0 @@
-from zope.interface import Interface, Attribute
-
-class ICommand(Interface):
- def cmd(bundle):
- """
- blah blag
- @ type bundle blah
- @ param bundle blah
- """
-
- command = Attribute("""The name of the command that the bot will pasre and look for.""")
View
14 derp/IBOT/ibot/plugins/something.py
@@ -1,14 +0,0 @@
-from zope.interface import implements
-from twisted.plugin import IPlugin
-from icommand import ICommand
-
-class Command(object):
- implements(IPlugin,ICommand)
-
- def __init__(self):
- self.x=3
- self.command = "ping"
- def cmd(self,bundle):
- print bundle
-
-bot_command = Command()
View
12 derp/IBOT/iiterator.py
@@ -1,12 +0,0 @@
-
-def main():
- from twisted.plugin import getPlugins,IPlugin,getCache
- from ibot import plugins
- for command in getPlugins(IPlugin,plugins):
- print "In the loop"
- bundle = "blah"
- print getCache(plugins)
- command.cmd(bundle)
-
-if __name__=='__main__':
- main()
View
3 derp/IBOT/reg_class.py
@@ -1,3 +0,0 @@
-def cmd():
- print "hello"
- print "again"
View
36 derp/brain.py
@@ -44,25 +44,6 @@ def __init__( self, channel ):
self.thoughts={}
self.load_plugins()
- def personal_message( self, protocol, user, channel, msg):
-
- if user == "NickServ":
- print user+" "+channel+" "+msg
- if not self.irc_auth.q_auth(): # We haven't confirmed anything
- self.irc_auth.new_line( msg )
- else:
- print "No auth yet, in phase: "+str(self.irc_auth.phase)
-
- con_msg = msg.split(' ')
- if con_msg[0] == "!loadplugins":
- self.irc_auth.reset_auth()
- protocol.msg("NickServ","info "+user)
- self.config.read(GLOBAL_CONFIG)
- print "Attempting to load plugins..."
- # This function will check for a succesful auth
- reactor.callLater(3,self.load_plugins)
-
-
def contemplate(self,protocol,user,channel,msg):
# We have a table for that channel. Write to it.
@@ -96,6 +77,23 @@ def contemplate(self,protocol,user,channel,msg):
print msg
return None
+ def personal_message( self, protocol, user, channel, msg):
+
+ if user == "NickServ":
+ print user+" "+channel+" "+msg
+ if not self.irc_auth.q_auth(): # We haven't confirmed anything
+ self.irc_auth.new_line( msg )
+ else:
+ print "No auth yet, in phase: "+str(self.irc_auth.phase)
+
+ con_msg = msg.split(' ')
+ if con_msg[0] == "!loadplugins":
+ self.irc_auth.reset_auth()
+ protocol.msg("NickServ","info "+user)
+ self.config.read(GLOBAL_CONFIG)
+ print "Attempting to load plugins..."
+ # This function will check for a succesful auth
+ reactor.callLater(3,self.load_plugins)
# Credit Goes to dwestbrook on stack overflow
# http://stackoverflow.com/questions/211100/pythons-import-doesnt-work-as-expected
View
2 derp/plugins/jokes.py
@@ -32,7 +32,7 @@ def re_troll(self,bundle):
print channel
cursor = bundle['cursor']
sql = "select * from '%s'\
- where user='uberj' and\
+ where user='manatee' and\
date>%s and\
msg='OMG!!! Ponies!!!'" % (re.escape(channel),str(time.time()-10))
print sql
View
65 derp/plugins/twitter.py
@@ -0,0 +1,65 @@
+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!"
View
4 derp/test_db_setup.py
@@ -1,4 +0,0 @@
-import sqlite3
-DATABASE = "db/channel_log"
-conn = sqlite3.connect(DATABASE)
-cursor = conn.cursor()
View
5 herpderp.py
@@ -58,6 +58,7 @@ def signedOn(self):
def joined(self, channel):
"""This will get called when the bot joins the channel."""
self.logger.log("[I have joined %s]" % channel)
+ print "Joined channel: "+str(channel)
def privmsg(self, user, channel, msg):
"""This will get called when the bot receives a message."""
@@ -67,19 +68,17 @@ def privmsg(self, user, channel, msg):
# Check to see if they're sending me a private message
if channel == self.nickname:
- self.factory.brain.personal_message( self, user, channel, msg )
+ self.factory.brain.personal_message(self,user,channel,msg)
return
# Otherwise check to see if it is a message directed at me
if msg.startswith(self.nickname + ":"):
msg = "%s: I've been derping really hard lately. I can't respond." % user
- print channel
self.msg(channel, msg)
self.logger.log("<%s> %s" % (self.nickname, msg))
# If it is not a pm and not an action, then it must be someone speaking. Pass
# their words into the brain and write it's response to the wire.
- print "HERE"
response = self.factory.brain.contemplate(self,user,channel,msg)
if response:
self.msg(channel,response)

0 comments on commit 539ff8a

Please sign in to comment.