# 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/backends/execution/base.py
# class ExecutionBackend(object):
#     is_will_execution_backend = True
# 
#     def handle_execution(self, message, context):
#         raise NotImplementedError
# 
#     def no_response(self, message):
#         self.bot.pubsub.publish(
#             "message.no_response",
#             message.data,
#             reference_message=message.data.original_incoming_event
#         )
# 
#     def not_allowed(self, message, explanation):
# 
#         self.bot.pubsub.publish(
#             "message.outgoing.%s" % message.data.backend,
#             Event(
#                 type="reply",
#                 content=explanation,
#                 source_message=message,
#             ),
#             reference_message=message.data.original_incoming_event
#         )
# 
#     def execute(self, message, option):
#         if "acl" in option.context:
#             acl = option.context["acl"]
#             if type(acl) == type("test"):
#                 acl = [acl]
# 
#             allowed = True
#             if len(acl) > 0:
#                 allowed = verify_acl(message, acl)
# 
#             if not allowed:
#                 acl_list = ""
#                 more_than_one_s = ""
#                 if len(acl) > 1:
#                     more_than_one_s = "s"
#                 for i in range(0, len(acl)):
#                     if i == 0:
#                         acl_list = "%s" % acl[i]
#                     elif i == len(acl) - 1:
#                         acl_list = "%s or %s" % (acl_list, acl[i])
#                     else:
#                         acl_list = "%s, %s" % (acl_list, acl[i])
#                 explanation = "Sorry, but I don't have you listed in the %s group%s, which is required to do what you asked." % (acl_list, more_than_one_s)
# 
#                 self.not_allowed(
#                     message,
#                     explanation
#                 )
#                 return
# 
#         if "say_content" in option.context:
#             # We're coming from a generation engine like a chatterbot, which doesn't *do* things.
#             self.bot.pubsub.publish(
#                 "message.outgoing.%s" % message.data.backend,
#                 Event(
#                     type="reply",
#                     content=option.context["say_content"],
#                     source_message=message,
#                 ),
#                 reference_message=message.data.original_incoming_event
#             )
#         else:
#             module = imp.load_source(option.context.plugin_info["parent_name"], option.context.plugin_info["parent_path"])
#             cls = getattr(module, option.context.plugin_info["name"])
# 
#             instantiated_module = cls(message=message)
#             method = getattr(instantiated_module, option.context.function_name)
# 
#             thread_args = [message, ] + option.context["args"]
# 
#             self.run_execute(
#                 method,
#                 *thread_args,
#                 **option.context.search_matches
#             )
# 
#     def run_execute(self, target, *args, **kwargs):
#         try:
#             t = Process(
#                 target=target,
#                 args=args,
#                 kwargs=kwargs,
#             )
#             self.bot.running_execution_threads.append(t)
#             t.start()
#         except (KeyboardInterrupt, SystemExit):
#             pass
#         except:
#             logging.critical("Error running %s: \n%s" % (target, traceback.format_exc()))
# 
#     def __init__(self, bot=None, *args, **kwargs):
#         self.bot = bot
#         if not bot:
#             raise Exception("Can't proceed without an instance of bot passed to the backend.")
#         super(ExecutionBackend, self).__init__(*args, **kwargs)


import logging
import traceback
import requests
import warnings
from will import settings
from will.decorators import require_settings
from .base import ExecutionBackend




class AllBackend(ExecutionBackend):

    def handle_execution(self, message):
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            try:
                had_one_reply = False
                for m in message.generation_options:
                    self.execute(message, m)
                    had_one_reply = True

                if not had_one_reply:
                    self.no_response(message)

                return {}
            except:

# 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/backends/execution/base.py
# class ExecutionBackend(object):
#     is_will_execution_backend = True
# 
#     def handle_execution(self, message, context):
#         raise NotImplementedError
# 
#     def no_response(self, message):
#         self.bot.pubsub.publish(
#             "message.no_response",
#             message.data,
#             reference_message=message.data.original_incoming_event
#         )
# 
#     def not_allowed(self, message, explanation):
# 
#         self.bot.pubsub.publish(
#             "message.outgoing.%s" % message.data.backend,
#             Event(
#                 type="reply",
#                 content=explanation,
#                 source_message=message,
#             ),
#             reference_message=message.data.original_incoming_event
#         )
# 
#     def execute(self, message, option):
#         if "acl" in option.context:
#             acl = option.context["acl"]
#             if type(acl) == type("test"):
#                 acl = [acl]
# 
#             allowed = True
#             if len(acl) > 0:
#                 allowed = verify_acl(message, acl)
# 
#             if not allowed:
#                 acl_list = ""
#                 more_than_one_s = ""
#                 if len(acl) > 1:
#                     more_than_one_s = "s"
#                 for i in range(0, len(acl)):
#                     if i == 0:
#                         acl_list = "%s" % acl[i]
#                     elif i == len(acl) - 1:
#                         acl_list = "%s or %s" % (acl_list, acl[i])
#                     else:
#                         acl_list = "%s, %s" % (acl_list, acl[i])
#                 explanation = "Sorry, but I don't have you listed in the %s group%s, which is required to do what you asked." % (acl_list, more_than_one_s)
# 
#                 self.not_allowed(
#                     message,
#                     explanation
#                 )
#                 return
# 
#         if "say_content" in option.context:
#             # We're coming from a generation engine like a chatterbot, which doesn't *do* things.
#             self.bot.pubsub.publish(
#                 "message.outgoing.%s" % message.data.backend,
#                 Event(
#                     type="reply",
#                     content=option.context["say_content"],
#                     source_message=message,
#                 ),
#                 reference_message=message.data.original_incoming_event
#             )
#         else:
#             module = imp.load_source(option.context.plugin_info["parent_name"], option.context.plugin_info["parent_path"])
#             cls = getattr(module, option.context.plugin_info["name"])
# 
#             instantiated_module = cls(message=message)
#             method = getattr(instantiated_module, option.context.function_name)
# 
#             thread_args = [message, ] + option.context["args"]
# 
#             self.run_execute(
#                 method,
#                 *thread_args,
#                 **option.context.search_matches
#             )
# 
#     def run_execute(self, target, *args, **kwargs):
#         try:
#             t = Process(
#                 target=target,
#                 args=args,
#                 kwargs=kwargs,
#             )
#             self.bot.running_execution_threads.append(t)
#             t.start()
#         except (KeyboardInterrupt, SystemExit):
#             pass
#         except:
#             logging.critical("Error running %s: \n%s" % (target, traceback.format_exc()))
# 
#     def __init__(self, bot=None, *args, **kwargs):
#         self.bot = bot
#         if not bot:
#             raise Exception("Can't proceed without an instance of bot passed to the backend.")
#         super(ExecutionBackend, self).__init__(*args, **kwargs)


# Path: will/backends/execution/all.py
import logging
import traceback
import requests
import warnings
from will import settings
from will.decorators import require_settings
from .base import ExecutionBackend





class AllBackend(ExecutionBackend):

    def handle_execution(self, message):
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            try:
                had_one_reply = False
                for m in message.generation_options:
                    self.execute(message, m)
                    had_one_reply = True

                if not had_one_reply:
                    self.no_response(message)

                return {}
            except:

                logging.critical(