# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# 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
# 
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap
# 
# Path: cardinal/exceptions.py
# class EventRejectedMessage(CardinalException):
#     """Raised when an event callback wants to reject an event."""


import re
import logging
from mediawiki import MediaWiki
from mediawiki.exceptions import DisambiguationError
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import command, event, help
from cardinal.exceptions import EventRejectedMessage
            return "Wikipedia Disambiguation: {options} - {url}".format(
                options=options,
                url=err.url,
            )

        # makes a network call
        def get_summary(p):
            return "{}...".format(p.summary[:self._max_description_length]) \
                if len(p.summary) > self._max_description_length else \
                p.summary
        summary = yield deferToThread(get_summary, p)

        return "Wikipedia: {title} - {summary} - {url}".format(
            title=p.title,
            summary=summary,
            url=p.url,
        )

    @event('urls.detection')
    @defer.inlineCallbacks
    def url_callback(self, cardinal, channel, url):
        match = re.match(ARTICLE_URL_REGEX, url)
        if not match:
            raise EventRejectedMessage

        try:
            article_info = yield self._get_article_info(match.group(1))
        except Exception:
            self.logger.exception("Error reading Wikipedia API for: {}".format(
                match.group(1)))

# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# 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
# 
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap
# 
# Path: cardinal/exceptions.py
# class EventRejectedMessage(CardinalException):
#     """Raised when an event callback wants to reject an event."""


# Path: plugins/wikipedia/plugin.py
import re
import logging
from mediawiki import MediaWiki
from mediawiki.exceptions import DisambiguationError
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from cardinal.decorators import command, event, help
from cardinal.exceptions import EventRejectedMessage

            return "Wikipedia Disambiguation: {options} - {url}".format(
                options=options,
                url=err.url,
            )

        # makes a network call
        def get_summary(p):
            return "{}...".format(p.summary[:self._max_description_length]) \
                if len(p.summary) > self._max_description_length else \
                p.summary
        summary = yield deferToThread(get_summary, p)

        return "Wikipedia: {title} - {summary} - {url}".format(
            title=p.title,
            summary=summary,
            url=p.url,
        )

    @event('urls.detection')
    @defer.inlineCallbacks
    def url_callback(self, cardinal, channel, url):
        match = re.match(ARTICLE_URL_REGEX, url)
        if not match:
            raise EventRejectedMessage

        try:
            article_info = yield self._get_article_info(match.group(1))
        except Exception:
            self.logger.exception("Error reading Wikipedia API for: {}".format(
                match.group(1)))

            raise EventRejectedMessage