# Path: utils/time_utils.py
# def parse_time(time):
# 
# Path: autoexec/autoexec_rules_manager.py
# class AutoexecRulesManager:
# 
#     def get_all_rules(self):
#         result = []
# 
#         f = utils.config_file.get_field("autoexec")
#         if not f:
#             return result
# 
#         json_arr = json.loads(f)
# 
#         for rule in json_arr:
#             result.append(autoexec.autoexec.AutoexecRule.from_json(rule).__dict__)
# 
#         return result
# 
#     def add_rule(self, rule):
#         if self.get_by_id(rule.id) is not None:
#             self.replace(rule.id, rule)
#             return 0
# 
#         if type(rule) is not autoexec.autoexec.AutoexecRule:
#             raise TypeError("value must be instance if AutoexecRule")
# 
#         rules = self.get_all_rules()
#         rules.append(rule.__dict__)
#         _json = json.dumps(rules)
#         utils.config_file.set_field(AUTOEXEC, _json)
# 
#     def get_by_id(self, id):
#         rules = self.get_all_rules()
#         for rule in rules:
#             if rule['id'] == id:
#                 return rule
# 
#     def remove(self, id):
#         rule = self.get_by_id(id)
#         if rule is None:
#             raise Exception("No such rule")
#         rules = self.get_all_rules()
#         rules.remove(rule)
#         _json = json.dumps(rules)
#         utils.config_file.set_field(AUTOEXEC, _json)
# 
#     def replace(self, id, rule):
#         self.remove(id)
#         self.add_rule(rule)
# 
# Path: autoexec/autoexec.py
# class AutoexecRule:
#     id = None
#     ticks = None
#     time_each = None
#     time_when = None
#     action = None
#     action_value = None
# 
#     def from_json(d):
#         s = AutoexecRule(force=True)
#         s.__dict__.update(d)
#         return s
# 
#     def __init__(self, time_each=None, time_when=None, action_type=None, force=False):
#         if not force:
# 
#             if not time_each:
#                 time_each = None
# 
#             if not time_when:
#                 time_when = None
# 
#             print("%s%s" % (time_each, time_when))
# 
#             if time_each == None and time_when == None:
#                 raise AttributeError("You must specify time when it action will be go")
# 
#             if time_each != None and time_when != None:
#                 raise AttributeError("You can't specify each and when parameters in the same time")
# 
#             if time_when is not None:
#                 self.time_when = time_utils.parse_time(time_when)
# 
#             if time_each is not None:
#                 self.time_each = time_utils.parse_time(time_each)
# 
#         pass
# 
# Path: autoexec/autoexec_action_type.py
# class AutoexecActionType():
#     ACTION_HC_CONSOLE = 1
#     ACTION_MESSAGE_SEND = 2


from threading import Thread
from time import sleep
from utils import time_utils
from autoexec.autoexec_rules_manager import AutoexecRulesManager
from autoexec.autoexec import AutoexecRule
from autoexec.autoexec_action_type import AutoexecActionType
                        from console import bot_console
import bot_header

    def stop(self):
        self.print("Stopping AutoExec thread...")
        self.enabled = False
        bot_header.AUTO_EXEC_THREAD_INSTANCE = None


    def print(self, text):
        print("[::AEXEC] %s" % text)

    def v(self, text):
        bot_header.v("[::AEXEC] %s" % text)

    def update_rules_list(self, q=False):
        if not q:
            self.print("Updating rules list...")
        self.aexec_rules = self.mgr.get_all_rules()


    def __init__(self, interval='1s', exec_py_code=False):
        super().__init__()
        self.interval = time_utils.parse_time(interval)
        self.exec_py_code = exec_py_code


    def run(self):
        self.v("run()")
        self.print("Getting rules...")
        while self.enabled:
            for rule in self.aexec_rules:

# Path: utils/time_utils.py
# def parse_time(time):
# 
# Path: autoexec/autoexec_rules_manager.py
# class AutoexecRulesManager:
# 
#     def get_all_rules(self):
#         result = []
# 
#         f = utils.config_file.get_field("autoexec")
#         if not f:
#             return result
# 
#         json_arr = json.loads(f)
# 
#         for rule in json_arr:
#             result.append(autoexec.autoexec.AutoexecRule.from_json(rule).__dict__)
# 
#         return result
# 
#     def add_rule(self, rule):
#         if self.get_by_id(rule.id) is not None:
#             self.replace(rule.id, rule)
#             return 0
# 
#         if type(rule) is not autoexec.autoexec.AutoexecRule:
#             raise TypeError("value must be instance if AutoexecRule")
# 
#         rules = self.get_all_rules()
#         rules.append(rule.__dict__)
#         _json = json.dumps(rules)
#         utils.config_file.set_field(AUTOEXEC, _json)
# 
#     def get_by_id(self, id):
#         rules = self.get_all_rules()
#         for rule in rules:
#             if rule['id'] == id:
#                 return rule
# 
#     def remove(self, id):
#         rule = self.get_by_id(id)
#         if rule is None:
#             raise Exception("No such rule")
#         rules = self.get_all_rules()
#         rules.remove(rule)
#         _json = json.dumps(rules)
#         utils.config_file.set_field(AUTOEXEC, _json)
# 
#     def replace(self, id, rule):
#         self.remove(id)
#         self.add_rule(rule)
# 
# Path: autoexec/autoexec.py
# class AutoexecRule:
#     id = None
#     ticks = None
#     time_each = None
#     time_when = None
#     action = None
#     action_value = None
# 
#     def from_json(d):
#         s = AutoexecRule(force=True)
#         s.__dict__.update(d)
#         return s
# 
#     def __init__(self, time_each=None, time_when=None, action_type=None, force=False):
#         if not force:
# 
#             if not time_each:
#                 time_each = None
# 
#             if not time_when:
#                 time_when = None
# 
#             print("%s%s" % (time_each, time_when))
# 
#             if time_each == None and time_when == None:
#                 raise AttributeError("You must specify time when it action will be go")
# 
#             if time_each != None and time_when != None:
#                 raise AttributeError("You can't specify each and when parameters in the same time")
# 
#             if time_when is not None:
#                 self.time_when = time_utils.parse_time(time_when)
# 
#             if time_each is not None:
#                 self.time_each = time_utils.parse_time(time_each)
# 
#         pass
# 
# Path: autoexec/autoexec_action_type.py
# class AutoexecActionType():
#     ACTION_HC_CONSOLE = 1
#     ACTION_MESSAGE_SEND = 2


# Path: autoexec/autoexec_thread.py
from threading import Thread
from time import sleep
from utils import time_utils
from autoexec.autoexec_rules_manager import AutoexecRulesManager
from autoexec.autoexec import AutoexecRule
from autoexec.autoexec_action_type import AutoexecActionType
                        from console import bot_console
import bot_header


    def stop(self):
        self.print("Stopping AutoExec thread...")
        self.enabled = False
        bot_header.AUTO_EXEC_THREAD_INSTANCE = None


    def print(self, text):
        print("[::AEXEC] %s" % text)

    def v(self, text):
        bot_header.v("[::AEXEC] %s" % text)

    def update_rules_list(self, q=False):
        if not q:
            self.print("Updating rules list...")
        self.aexec_rules = self.mgr.get_all_rules()


    def __init__(self, interval='1s', exec_py_code=False):
        super().__init__()
        self.interval = time_utils.parse_time(interval)
        self.exec_py_code = exec_py_code


    def run(self):
        self.v("run()")
        self.print("Getting rules...")
        while self.enabled:
            for rule in self.aexec_rules:

                rule = AutoexecRule.from_json(rule)