# 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/util.py
# def is_action(message):
#     """Checks if a message is a /me message."""
#     return message.startswith("\x01ACTION")
# 
# def parse_action(nick, message):
#     """Parses a /me message like an IRC client might.
# 
#     e.g. "/me dances." -> "* Cardinal dances."
#     """
#     if not is_action(message):
#         raise ValueError("This message is not an ACTION message")
# 
#     message = message[len("\x01ACTION "):]
#     if message and message[-1] == "\x01":
#         message = message[:-1]
# 
#     return "* {}{}".format(
#         nick,
#         " " + message if message else "",
#     )


import re
from collections import defaultdict
from cardinal.decorators import event
from cardinal.util import (
    is_action,
    parse_action,
)
    @event('irc.privmsg')
    def on_msg(self, cardinal, user, channel, message):
        new_message = self.substitute(user, channel, message)
        if new_message is not None:
            old_message = self.history[channel][user.nick]
            if self.should_send_correction(old_message, new_message):
                self.history[channel][user.nick] = new_message

                # In the 11th hour, make sure that we correctly handle /me
                if is_action(new_message):
                    new_message = parse_action(new_message)

                cardinal.sendMsg(channel, '{} meant: {}'.format(
                                    user.nick, new_message))
        else:
            self.history[channel][user.nick] = message

    @event('irc.part')
    def on_part(self, cardinal, leaver, channel, message):
        if leaver.nick == cardinal.nickname:
            try:
                del self.history[channel]
            except KeyError:
                pass
        else:
            try:
                del self.history[channel][leaver.nick]
            except KeyError:
                pass


# 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/util.py
# def is_action(message):
#     """Checks if a message is a /me message."""
#     return message.startswith("\x01ACTION")
# 
# def parse_action(nick, message):
#     """Parses a /me message like an IRC client might.
# 
#     e.g. "/me dances." -> "* Cardinal dances."
#     """
#     if not is_action(message):
#         raise ValueError("This message is not an ACTION message")
# 
#     message = message[len("\x01ACTION "):]
#     if message and message[-1] == "\x01":
#         message = message[:-1]
# 
#     return "* {}{}".format(
#         nick,
#         " " + message if message else "",
#     )


# Path: plugins/sed/plugin.py
import re
from collections import defaultdict
from cardinal.decorators import event
from cardinal.util import (
    is_action,
    parse_action,
)

    @event('irc.privmsg')
    def on_msg(self, cardinal, user, channel, message):
        new_message = self.substitute(user, channel, message)
        if new_message is not None:
            old_message = self.history[channel][user.nick]
            if self.should_send_correction(old_message, new_message):
                self.history[channel][user.nick] = new_message

                # In the 11th hour, make sure that we correctly handle /me
                if is_action(new_message):
                    new_message = parse_action(new_message)

                cardinal.sendMsg(channel, '{} meant: {}'.format(
                                    user.nick, new_message))
        else:
            self.history[channel][user.nick] = message

    @event('irc.part')
    def on_part(self, cardinal, leaver, channel, message):
        if leaver.nick == cardinal.nickname:
            try:
                del self.history[channel]
            except KeyError:
                pass
        else:
            try:
                del self.history[channel][leaver.nick]
            except KeyError:
                pass


    @event('irc.kick')