Exemple #1
0
def tweets(chat, message, args, sender):
    if len(args) == 0:
        chat.SendMessage("Provide a user")
        return

    num = 0
    if len(args) == 2:
        num = int(args[1])

    if num > 300:
        chat.SendMessage("Unable to process")
        return
    api = get_api()
    if api is None:
        return
    try:
        user = api.get_user(args[0])
        if not user:
            chat.SendMessage("User not found")
            return

        user_timeline = api.user_timeline(id=user.id, count=num + 1)
    except tweepy.error.TweepError:
        chat.SendMessage("Unable to find tweet.")
        return

    if not user_timeline:
        chat.SendMessage("Timeline not found")
        return

    chat.SendMessage(format_status(user_timeline[num]))
Exemple #2
0
def twitter_url(chat, message, args, sender, found):
    match = re.search("(?:(?:www.twitter.com|twitter.com)/(?:[-_a-zA-Z0-9]+)/status/)([0-9]+)", message)
    tweet_id = match.group(1)
    api = get_api()
    if api is None:
        return
    try:
        tweet = api.get_status(tweet_id)
    except tweepy.error.TweepError:
        print ("Failed to retrieve tweet data.")
        return

    chat.SendMessage(format_status(tweet))
Exemple #3
0
def twitter_listen(chat, message, args, sender):
    if len(args) == 0:
        chat.SendMessage("Provide a user to listen to.")
        return
    api = get_api()
    if api is None:
        return
    user = api.get_user(args[0])
    if not user:
        chat.SendMessage("User not found")
        return
    conf = config.config()
    listens = conf.get("twitter_listens", None)
    if listens is None:
        conf["twitter_listens"] = {}
        listens = {}
    if args[0] in listens:
        user_json = listens[args[0]]
        chats = user_json["chats"]
        if chat.Name in chats:
            chat.SendMessage("This chat is already listening to that user's tweets!")
            return

    username_list = [args[0]]
    userids = []

    for username in username_list:
        user = api.get_user(screen_name=username)
        userids.append(str(user.id))
    streams.update({chat: args[0]})
    chat.SendMessage("Updated with new stream for {}".format(args[0]))
    args[0] = args[0].lower()
    if args[0] in listens:
        chats = listens[args[0]]["chats"]
        chats.append(chat.Name)
        conf["twitter_listens"][args[0]]["chats"] = chats
    else:
        chats = [chat.Name]
        conf["twitter_listens"][args[0]] = {}
        listens.update({args[0]: {}})
        conf["twitter_listens"][args[0]]["chats"] = chats
        conf["twitter_listens"][args[0]]["id"] = userids[0]

    config.save(conf)
    load_streams()