# Path: responsebot/common/constants.py
# TWITTER_NON_TWEET_EVENTS = ['access_revoked', 'block', 'unblock', 'favorite', 'unfavorite', 'follow', 'unfollow',
#     'list_created', 'list_destroyed', 'list_updated', 'list_member_added', 'list_member_removed',
#     'list_user_subscribed', 'list_user_unsubscribed', 'quoted_tweet', 'user_update']
# 
# Path: responsebot/models.py
# class TweetFilter(object):
#     """
#     Define criteria to filter tweets from Twitter's public stream. See `track` and `follow` parameters in `here <https://dev.twitter.com/streaming/overview/request-parameters>`_.
#     """
#     def __init__(self, track=[], follow=[]):
#         """
# 
#         :param track: A list of keywords to follow (each could also be a @mention or a #hashtag)
#         :param follow: A list of user ID strings to follow
#         :return:
#         """
#         self.track = track
#         self.follow = follow
# 
#     def match_tweet(self, tweet, user_stream):
#         """
#         Check if a tweet matches the defined criteria
# 
#         :param tweet: The tweet in question
#         :type tweet: :class:`~responsebot.models.Tweet`
#         :return: True if matched, False otherwise
#         """
#         if user_stream:
#             if len(self.track) > 0:
#                 return self.is_tweet_match_track(tweet)
# 
#             return True
# 
#         return self.is_tweet_match_track(tweet) or self.is_tweet_match_follow(tweet)
# 
#     def is_tweet_match_track(self, tweet):
#         tweet_text = tweet.text.lower()
#         for value in self.track:
#             if value.lower() in tweet_text:
#                 return True
# 
#         return False
# 
#     def is_tweet_match_follow(self, tweet):
#         user_mentions = [x['id'] for x in tweet.entities.get('user_mentions', [])]
#         for value in self.follow:
#             int_value = int(value)
#             if tweet.user.id == int_value or int_value in user_mentions:
#                 return True
# 
#         return False


import logging
from responsebot.common.constants import TWITTER_NON_TWEET_EVENTS
from responsebot.models import TweetFilter
            )

    def on_tweet(self, tweet):
        """
        Callback to receive tweet from :class:`~responsebot.responsebot_stream.ResponseBotStream`. Tries to forward the
        received tweet to registered handlers.

        :param tweet: An object containing a tweet's text and metadata
        :type tweet: :class:`~responsebot.models.Tweet`
        """
        logging.info(u'Received tweet: `{message}`'.format(message=tweet.text))

        for handler in self.handlers:
            if not handler.catch_self_tweets and self.is_self_tweet(tweet):
                continue

            if not handler.filter.match_tweet(tweet=tweet, user_stream=self.client.config.get('user_stream')):
                continue

            handler.on_tweet(tweet)

    def on_event(self, event):
        """
        Callback to receive events from :class:`~responsebot.responsebot_stream.ResponseBotStream`. Tries to forward the
        received event to registered handlers.

        :param event: The received event
        :type event: :class:`~responsebot.models.Event`
        error from a custom handler
        """

# Path: responsebot/common/constants.py
# TWITTER_NON_TWEET_EVENTS = ['access_revoked', 'block', 'unblock', 'favorite', 'unfavorite', 'follow', 'unfollow',
#     'list_created', 'list_destroyed', 'list_updated', 'list_member_added', 'list_member_removed',
#     'list_user_subscribed', 'list_user_unsubscribed', 'quoted_tweet', 'user_update']
# 
# Path: responsebot/models.py
# class TweetFilter(object):
#     """
#     Define criteria to filter tweets from Twitter's public stream. See `track` and `follow` parameters in `here <https://dev.twitter.com/streaming/overview/request-parameters>`_.
#     """
#     def __init__(self, track=[], follow=[]):
#         """
# 
#         :param track: A list of keywords to follow (each could also be a @mention or a #hashtag)
#         :param follow: A list of user ID strings to follow
#         :return:
#         """
#         self.track = track
#         self.follow = follow
# 
#     def match_tweet(self, tweet, user_stream):
#         """
#         Check if a tweet matches the defined criteria
# 
#         :param tweet: The tweet in question
#         :type tweet: :class:`~responsebot.models.Tweet`
#         :return: True if matched, False otherwise
#         """
#         if user_stream:
#             if len(self.track) > 0:
#                 return self.is_tweet_match_track(tweet)
# 
#             return True
# 
#         return self.is_tweet_match_track(tweet) or self.is_tweet_match_follow(tweet)
# 
#     def is_tweet_match_track(self, tweet):
#         tweet_text = tweet.text.lower()
#         for value in self.track:
#             if value.lower() in tweet_text:
#                 return True
# 
#         return False
# 
#     def is_tweet_match_follow(self, tweet):
#         user_mentions = [x['id'] for x in tweet.entities.get('user_mentions', [])]
#         for value in self.follow:
#             int_value = int(value)
#             if tweet.user.id == int_value or int_value in user_mentions:
#                 return True
# 
#         return False


# Path: responsebot/listeners/responsebot_listener.py
import logging
from responsebot.common.constants import TWITTER_NON_TWEET_EVENTS
from responsebot.models import TweetFilter

            )

    def on_tweet(self, tweet):
        """
        Callback to receive tweet from :class:`~responsebot.responsebot_stream.ResponseBotStream`. Tries to forward the
        received tweet to registered handlers.

        :param tweet: An object containing a tweet's text and metadata
        :type tweet: :class:`~responsebot.models.Tweet`
        """
        logging.info(u'Received tweet: `{message}`'.format(message=tweet.text))

        for handler in self.handlers:
            if not handler.catch_self_tweets and self.is_self_tweet(tweet):
                continue

            if not handler.filter.match_tweet(tweet=tweet, user_stream=self.client.config.get('user_stream')):
                continue

            handler.on_tweet(tweet)

    def on_event(self, event):
        """
        Callback to receive events from :class:`~responsebot.responsebot_stream.ResponseBotStream`. Tries to forward the
        received event to registered handlers.

        :param event: The received event
        :type event: :class:`~responsebot.models.Event`
        error from a custom handler
        """

        if event.event not in TWITTER_NON_TWEET_EVENTS: