# Path: will/settings.py
# def auto_key():
# def import_settings(quiet=True):
#         DEPRECATED_BUT_MAPPED_SETTINGS = {
#             "USERNAME": "HIPCHAT_USERNAME",
#             "PASSWORD": "HIPCHAT_PASSWORD",
#             "V1_TOKEN": "HIPCHAT_V1_TOKEN",
#             "V2_TOKEN": "HIPCHAT_V2_TOKEN",
#             "TOKEN": "HIPCHAT_V1_TOKEN",
#             "ROOMS": "HIPCHAT_ROOMS",
#             "NAME": "HIPCHAT_NAME",
#             "HANDLE": "HIPCHAT_HANDLE",
#             "DEFAULT_ROOM": "HIPCHAT_DEFAULT_ROOM",
#             "SLACK_DEFAULT_ROOM": "SLACK_DEFAULT_CHANNEL",
#         }
#             IO_BACKENDS = []
# 
# Path: will/decorators.py
# def require_settings(*setting_names):
#     def wrap(f):
#         def wrapped_f(*args, **kwargs):
#             f(*args, **kwargs)
#         wrapped_f.will_fn_metadata = getattr(f, "will_fn_metadata", {})
#         wrapped_f.will_fn_metadata["required_settings"] = setting_names
#         return wrapped_f
#     return wrap
# 
# Path: will/utils.py
# class Bunch(dict):
#     def __init__(self, **kw):
#         dict.__init__(self, kw)
#         self.__dict__ = self
# 
#     def __getstate__(self):
#         return self
# 
#     def __setstate__(self, state):
#         self.update(state)
#         self.__dict__ = self
# 
# Path: will/backends/generation/base.py
# class GenerationBackend(PubSubMixin, SleepMixin, object):
#     is_will_generationbackend = True
# 
#     def __watch_pubsub(self):
#         while True:
#             try:
#                 m = self.pubsub.get_message()
#                 if m:
#                     self.__generate(m.data)
#             except (KeyboardInterrupt, SystemExit):
#                 pass
#             self.sleep_for_event_loop()
# 
#     def __generate(self, message):
#         ret = self.do_generate(message)
#         try:
#             self.pubsub.publish("generation.complete", ret, reference_message=message)
#         except (KeyboardInterrupt, SystemExit):
#             pass
#         except:
#             logging.critical("Error publishing generation.complete: \n%s" % traceback.format_exc())
# 
#     def do_generate(self, message):
#         # Take message, return a list of possible responses/matches
#         raise NotImplementedError
# 
#     def start(self, name, **kwargs):
#         for k, v in kwargs.items():
#             self.__dict__[k] = v
# 
#         self.name = name
#         self.bootstrap_pubsub()
#         self.subscribe("generation.start")
#         self.__watch_pubsub()
# 
# class GeneratedOption(object):
# 
#     def __init__(self, *args, **kwargs):
#         for o in OPTION_REQUIRED_FIELDS:
#             if o not in kwargs:
#                 raise Exception("Missing '%s' argument to the generator backend." % o)
# 
#         for k, v in kwargs.items():
#             self.__dict__[k] = v
# 
#         return super(GeneratedOption, self).__init__()
# 
#     def __unicode__(self):
#         return "%s - %s" % (self.score, self.context)
# 
#     def __str__(self):
#         return "%s - %s" % (self.score, self.context)


import re
from will import settings
from will.decorators import require_settings
from will.utils import Bunch
from .base import GenerationBackend, GeneratedOption


class RegexBackend(GenerationBackend):

    def do_generate(self, event):
        exclude_list = ["fn", ]
        matches = []

        message = event.data
        for name, l in self.bot.message_listeners.items():
            search_matches = l["regex"].search(message.content)
            if (
                    # The search regex matches and
                    search_matches

                    # It's not from me, or this search includes me, and
                    and (

# Path: will/settings.py
# def auto_key():
# def import_settings(quiet=True):
#         DEPRECATED_BUT_MAPPED_SETTINGS = {
#             "USERNAME": "HIPCHAT_USERNAME",
#             "PASSWORD": "HIPCHAT_PASSWORD",
#             "V1_TOKEN": "HIPCHAT_V1_TOKEN",
#             "V2_TOKEN": "HIPCHAT_V2_TOKEN",
#             "TOKEN": "HIPCHAT_V1_TOKEN",
#             "ROOMS": "HIPCHAT_ROOMS",
#             "NAME": "HIPCHAT_NAME",
#             "HANDLE": "HIPCHAT_HANDLE",
#             "DEFAULT_ROOM": "HIPCHAT_DEFAULT_ROOM",
#             "SLACK_DEFAULT_ROOM": "SLACK_DEFAULT_CHANNEL",
#         }
#             IO_BACKENDS = []
# 
# Path: will/decorators.py
# def require_settings(*setting_names):
#     def wrap(f):
#         def wrapped_f(*args, **kwargs):
#             f(*args, **kwargs)
#         wrapped_f.will_fn_metadata = getattr(f, "will_fn_metadata", {})
#         wrapped_f.will_fn_metadata["required_settings"] = setting_names
#         return wrapped_f
#     return wrap
# 
# Path: will/utils.py
# class Bunch(dict):
#     def __init__(self, **kw):
#         dict.__init__(self, kw)
#         self.__dict__ = self
# 
#     def __getstate__(self):
#         return self
# 
#     def __setstate__(self, state):
#         self.update(state)
#         self.__dict__ = self
# 
# Path: will/backends/generation/base.py
# class GenerationBackend(PubSubMixin, SleepMixin, object):
#     is_will_generationbackend = True
# 
#     def __watch_pubsub(self):
#         while True:
#             try:
#                 m = self.pubsub.get_message()
#                 if m:
#                     self.__generate(m.data)
#             except (KeyboardInterrupt, SystemExit):
#                 pass
#             self.sleep_for_event_loop()
# 
#     def __generate(self, message):
#         ret = self.do_generate(message)
#         try:
#             self.pubsub.publish("generation.complete", ret, reference_message=message)
#         except (KeyboardInterrupt, SystemExit):
#             pass
#         except:
#             logging.critical("Error publishing generation.complete: \n%s" % traceback.format_exc())
# 
#     def do_generate(self, message):
#         # Take message, return a list of possible responses/matches
#         raise NotImplementedError
# 
#     def start(self, name, **kwargs):
#         for k, v in kwargs.items():
#             self.__dict__[k] = v
# 
#         self.name = name
#         self.bootstrap_pubsub()
#         self.subscribe("generation.start")
#         self.__watch_pubsub()
# 
# class GeneratedOption(object):
# 
#     def __init__(self, *args, **kwargs):
#         for o in OPTION_REQUIRED_FIELDS:
#             if o not in kwargs:
#                 raise Exception("Missing '%s' argument to the generator backend." % o)
# 
#         for k, v in kwargs.items():
#             self.__dict__[k] = v
# 
#         return super(GeneratedOption, self).__init__()
# 
#     def __unicode__(self):
#         return "%s - %s" % (self.score, self.context)
# 
#     def __str__(self):
#         return "%s - %s" % (self.score, self.context)


# Path: will/backends/generation/strict_regex.py
import re
from will import settings
from will.decorators import require_settings
from will.utils import Bunch
from .base import GenerationBackend, GeneratedOption



class RegexBackend(GenerationBackend):

    def do_generate(self, event):
        exclude_list = ["fn", ]
        matches = []

        message = event.data
        for name, l in self.bot.message_listeners.items():
            search_matches = l["regex"].search(message.content)
            if (
                    # The search regex matches and
                    search_matches

                    # It's not from me, or this search includes me, and
                    and (

                        message.will_said_it is False