def handle_twitterfriends(bot, ievent): """ no arguments - show friends timeline (your normal twitter feed). """ if not go: ievent.reply( "the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples" ) return try: token = get_token(ievent.user.data.name) if not token: ievent.reply( "you are not logged in yet .. run the twitter-auth command.") return key, secret = getcreds(getdatadir()) token = tweepy.oauth.OAuthToken(key, secret).from_string(token) twitter = twitterapi(key, secret, token) method = getattr(twitter, "friends_timeline") result = method() res = [] for item in result: try: res.append("%s - %s" % (item.author.screen_name, item.text)) except Exception, ex: handle_exception() ievent.reply("results: ", res)
def handle_twittercmnd(bot, ievent): """ arguments: <API cmnd> - do a twitter API cmommand. """ if not go: ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data//config dir. see .jsb/data/examples") ; return if not ievent.args: ievent.missing('<API cmnd>') ; return target = strippedtxt(ievent.args[0]) try: from jsb.utils.twitter import get_token token = get_token(ievent.user.data.name) if not token: ievent.reply("you are not logged in yet .. run the twitter-auth command.") ; return key, secret = getcreds(getdatadir()) token = tweepy.oauth.OAuthToken(key, secret).from_string(token) twitter = twitterapi(key, secret, token) cmndlist = dir(twitter) cmnds = [] for cmnd in cmndlist: if cmnd.startswith("_") or cmnd == "auth": continue else: cmnds.append(cmnd) if target not in cmnds: ievent.reply("choose one of: %s" % ", ".join(cmnds)) ; return try: method = getattr(twitter, target) except AttributeError: ievent.reply("choose one of: %s" % ", ".join(cmnds)) ; return result = method() res = [] for item in result: try: res.append("%s - %s" % (item.screen_name, item.text)) except AttributeError: try: res.append("%s - %s" % (item.screen_name, item.description)) except AttributeError: try: res.append(unicode(item.__getstate__())) except AttributeError: res.append(dir(i)) ; res.append(unicode(item)) ievent.reply("result of %s: " % target, res) except KeyError: ievent.reply('you are not logged in yet. see the twitter-auth command.') except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e),))
def handle_twittercmnd(bot, ievent): """ arguments: <API cmnd> - do a twitter API cmommand. """ if not go: ievent.reply( "the twitter plugin needs the credentials.py file in the .jsb/data//config dir. see .jsb/data/examples" ) return if not ievent.args: ievent.missing('<API cmnd>') return target = strippedtxt(ievent.args[0]) try: from jsb.utils.twitter import get_token token = get_token(ievent.user.data.name) if not token: ievent.reply( "you are not logged in yet .. run the twitter-auth command.") return key, secret = getcreds(getdatadir()) token = tweepy.oauth.OAuthToken(key, secret).from_string(token) twitter = twitterapi(key, secret, token) cmndlist = dir(twitter) cmnds = [] for cmnd in cmndlist: if cmnd.startswith("_") or cmnd == "auth": continue else: cmnds.append(cmnd) if target not in cmnds: ievent.reply("choose one of: %s" % ", ".join(cmnds)) return try: method = getattr(twitter, target) except AttributeError: ievent.reply("choose one of: %s" % ", ".join(cmnds)) return result = method() res = [] for item in result: try: res.append("%s - %s" % (item.screen_name, item.text)) except AttributeError: try: res.append("%s - %s" % (item.screen_name, item.description)) except AttributeError: try: res.append(unicode(item.__getstate__())) except AttributeError: res.append(dir(i)) res.append(unicode(item)) ievent.reply("result of %s: " % target, res) except KeyError: ievent.reply( 'you are not logged in yet. see the twitter-auth command.') except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e), ))
def handle_twitter(bot, ievent): """ arguments: <txt> - send a twitter message. """ creds = getcreds() from jsb.utils.twitter import go if not go: ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples") ; return txt = ievent.rest if ievent.ispipelined: txt = ievent.wait() if not txt: ievent.missing('<txt>') ; return else: if ievent.chan: taglist = ievent.chan.data.taglist if taglist: for tag in taglist: txt += " %s" % tag twitter_out(ievent.user.data.name, txt, ievent) ; ievent.reply("tweet posted")
def handle_twitterfriends(bot, ievent): """ no arguments - show friends timeline (your normal twitter feed). """ if not go: ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples") ; return try: token = get_token(ievent.user.data.name) if not token: ievent.reply("you are not logged in yet .. run the twitter-auth command.") ; return key , secret = getcreds(getdatadir()) token = tweepy.oauth.OAuthToken(key, secret).from_string(token) twitter = twitterapi(key, secret, token) method = getattr(twitter, "friends_timeline") result = method() res = [] for item in result: try: res.append("%s - %s" % (item.author.screen_name, item.text)) except Exception, ex: handle_exception() ievent.reply("results: ", res) except KeyError: ievent.reply('you are not logged in yet. see the twitter-auth command.') except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e),))
def handle_twitter(bot, ievent): """ arguments: <txt> - send a twitter message. """ creds = getcreds() from jsb.utils.twitter import go if not go: ievent.reply( "the twitter plugin needs the credentials.py file in the .jsb/data/config dir. see .jsb/data/examples" ) return txt = ievent.rest if ievent.ispipelined: txt = ievent.wait() if not txt: ievent.missing('<txt>') return else: if ievent.chan: taglist = ievent.chan.data.taglist if taglist: for tag in taglist: txt += " %s" % tag twitter_out(ievent.user.data.name, txt, ievent) ievent.reply("tweet posted")
def init(): from jsb.utils.twitter import getcreds creds = getcreds()