# Path: cardinal/decorators.py
# def event(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Event must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.events = triggers
#         return f
# 
#     return wrap
# 
# Path: cardinal/exceptions.py
# class EventRejectedMessage(CardinalException):
#     """Raised when an event callback wants to reject an event."""


import re
import requests
import twitter
from urllib.parse import urlparse
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import event
from cardinal.exceptions import EventRejectedMessage

        if not all([consumer_key, consumer_secret]):
            raise Exception(
                "Twitter plugin requires consumer_key and consumer_secret"
            )

        self.api = twitter.Api(
            consumer_key=consumer_key,
            consumer_secret=consumer_secret,
            application_only_auth=True,
        )

    @defer.inlineCallbacks
    def get_tweet(self, tweet_id):
        tweet = yield deferToThread(self.api.GetStatus,
                                    tweet_id)

        return tweet

    @defer.inlineCallbacks
    def follow_short_link(self, url):
        r = yield deferToThread(requests.get,
                                url)

        # Twitter returns 400 in normal operation
        if not r.ok and r.status_code != 400:
            r.raise_for_status()

        return r.url


# Path: cardinal/decorators.py
# def event(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Event must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.events = triggers
#         return f
# 
#     return wrap
# 
# Path: cardinal/exceptions.py
# class EventRejectedMessage(CardinalException):
#     """Raised when an event callback wants to reject an event."""


# Path: plugins/twitter/plugin.py
import re
import requests
import twitter
from urllib.parse import urlparse
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import event
from cardinal.exceptions import EventRejectedMessage


        if not all([consumer_key, consumer_secret]):
            raise Exception(
                "Twitter plugin requires consumer_key and consumer_secret"
            )

        self.api = twitter.Api(
            consumer_key=consumer_key,
            consumer_secret=consumer_secret,
            application_only_auth=True,
        )

    @defer.inlineCallbacks
    def get_tweet(self, tweet_id):
        tweet = yield deferToThread(self.api.GetStatus,
                                    tweet_id)

        return tweet

    @defer.inlineCallbacks
    def follow_short_link(self, url):
        r = yield deferToThread(requests.get,
                                url)

        # Twitter returns 400 in normal operation
        if not r.ok and r.status_code != 400:
            r.raise_for_status()

        return r.url


    @event('urls.detection')