Ejemplo n.º 1
0
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),))
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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), ))
Ejemplo n.º 4
0
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),))