# Path: cardinal/exceptions.py
# class CommandNotFoundError(CardinalException):
#     """Raised when a given command isn't loaded."""
# 
# class ConfigNotFoundError(CardinalException):
#     """Raised when an expected plugin config isn't found."""
# 
# class EventAlreadyExistsError(CardinalException):
#     """Raised durring attempt to register an event name already registered."""
# 
# class EventCallbackError(CardinalException):
#     """Raised when there is an error with a callback."""
# 
# class EventDoesNotExistError(CardinalException):
#     """Raised during attempt to register a callback for a nonexistent event."""
# 
# class EventRejectedMessage(CardinalException):
#     """Raised when an event callback wants to reject an event."""
# 
# class PluginError(CardinalException):
#     """Raised when a plugin is invalid in some way."""


import os
import re
import string
import logging
import importlib
import inspect
import linecache
import random
import json
from collections import defaultdict
from copy import copy
from importlib import reload
from cardinal.exceptions import (
    CommandNotFoundError,
    ConfigNotFoundError,
    EventAlreadyExistsError,
    EventCallbackError,
    EventDoesNotExistError,
    EventRejectedMessage,
    PluginError,
)
from twisted.internet import defer
        callbacks = self.registered_callbacks[name]
        self.logger.debug(
            "Calling %d callbacks for event: %s" %
            (len(callbacks), name)
        )

        cb_deferreds = []
        for callback_id, callback in callbacks.items():
            d = defer.maybeDeferred(
                callback, self.cardinal, *params)

            # It is necessary to pass callback_id in to this function in order
            # to make sure it doesn't change when the loop iterates
            def success(_result, callback_id=callback_id):
                self.logger.debug(
                    "Callback {} accepted event '{}'"
                    .format(callback_id, name)
                )

                return True
            d.addCallback(success)

            # It is necessary to pass callback_id in to this function in order
            # to make sure it doesn't change when the loop iterates
            def eventRejectedErrback(failure, callback_id=callback_id):
                # If this exception is received, the plugin told us not to set
                # the called flag true, so we can just log it and continue on.
                # This might happen if a plugin realizes the event does not
                # apply to it and wants the original caller to handle it
                # normally.

# Path: cardinal/exceptions.py
# class CommandNotFoundError(CardinalException):
#     """Raised when a given command isn't loaded."""
# 
# class ConfigNotFoundError(CardinalException):
#     """Raised when an expected plugin config isn't found."""
# 
# class EventAlreadyExistsError(CardinalException):
#     """Raised durring attempt to register an event name already registered."""
# 
# class EventCallbackError(CardinalException):
#     """Raised when there is an error with a callback."""
# 
# class EventDoesNotExistError(CardinalException):
#     """Raised during attempt to register a callback for a nonexistent event."""
# 
# class EventRejectedMessage(CardinalException):
#     """Raised when an event callback wants to reject an event."""
# 
# class PluginError(CardinalException):
#     """Raised when a plugin is invalid in some way."""


# Path: cardinal/plugins.py
import os
import re
import string
import logging
import importlib
import inspect
import linecache
import random
import json
from collections import defaultdict
from copy import copy
from importlib import reload
from cardinal.exceptions import (
    CommandNotFoundError,
    ConfigNotFoundError,
    EventAlreadyExistsError,
    EventCallbackError,
    EventDoesNotExistError,
    EventRejectedMessage,
    PluginError,
)
from twisted.internet import defer

        callbacks = self.registered_callbacks[name]
        self.logger.debug(
            "Calling %d callbacks for event: %s" %
            (len(callbacks), name)
        )

        cb_deferreds = []
        for callback_id, callback in callbacks.items():
            d = defer.maybeDeferred(
                callback, self.cardinal, *params)

            # It is necessary to pass callback_id in to this function in order
            # to make sure it doesn't change when the loop iterates
            def success(_result, callback_id=callback_id):
                self.logger.debug(
                    "Callback {} accepted event '{}'"
                    .format(callback_id, name)
                )

                return True
            d.addCallback(success)

            # It is necessary to pass callback_id in to this function in order
            # to make sure it doesn't change when the loop iterates
            def eventRejectedErrback(failure, callback_id=callback_id):
                # If this exception is received, the plugin told us not to set
                # the called flag true, so we can just log it and continue on.
                # This might happen if a plugin realizes the event does not
                # apply to it and wants the original caller to handle it
                # normally.

                failure.trap(EventRejectedMessage)