# Everything else in this file is configuration-specific.
-import os, time, re
+import os, time, re, twitter
# Most command implementations are stored in a separate module.
import commands as c
#do an expiry run every hour
expirevery=60*60
+# non-authenticated twitter api instance
+twitapi = twitter.Api()
+
# Command processing: whenever something is said that the bot can hear,
# "command" is invoked and must decide what to do. This configuration
# defines a couple of special cases (for karma) but is otherwise driven
"help": c.helpq,
# "game": (c.gameq,game),
"say": c.sayq,
- "do": c.doq }
+ "do": c.doq,
+ "twit": (c.twitterq,twitapi) }
# disconnect and hop annoy people
# "disconnect": c.disconnq,
# "hop": c.disconnq }
# eg !trout, ~trout etc.
def command(bot, cmd, nick, conn, public):
- global urldb,lastexp,expirelen,expirevery
+ global urldb,lastexp,expirelen,expirevery,twitapi
ours=0
try:
if public and cmd[0] in triggers:
# Part of Acrobat.
-import string, cPickle, random, urllib, sys, time, re, os
+import string, cPickle, random, urllib, sys, time, re, os, twitter
from irclib import irc_lower, nm_to_n
# query karma
urlstring.replace(middle,"/hi/")
return urlstring
+
+#get tweet text
+def twitterq(bot,cmd,nick,conn,public,twitapi):
+
+ if (not urlre.search(cmd)):
+ bot.automsg(False,nick,"Please use 'twit' only with http URLs")
+ return
+
+ urlstring = urlre.search(cmd).group(1)
+ if (urlstring.find("twitter.com") !=-1):
+ stringout = getTweet(urlstring,twitapi)
+ if public:
+ conn.action(bot.channel,stringout)
+ else:
+ bot.automsg(public, nick, stringout)
+
+def getTweet(urlstring,twitapi):
+ parts = string.split(urlstring,'/')
+ tweetID = parts[-1]
+ status = twitapi.GetStatus(tweetID)
+ tweeter_screen = status.user.screen_name
+ tweeter_name = status.user.name
+ tweetText = status.text
+ stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText)
+ return stringout