コード例 #1
0
ファイル: setting_service.py プロジェクト: Budabot/Tyrbot
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "setting"):
                 setting_name, value, description, extended_description, obj = getattr(method, "setting")
                 self.register(inst.module_name, setting_name, value, obj, description, extended_description)
コード例 #2
0
ファイル: command_service.py プロジェクト: Budabot/Tyrbot
    def start(self):
        access_levels = {}

        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command, extended_description = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    help_text = self.get_help_file(inst.module_name, help_file)

                    command_key = self.get_command_key(
                        cmd_name.lower(),
                        sub_command.lower() if sub_command else "")
                    al = access_levels.get(command_key, None)
                    if al is not None and al != access_level.lower():
                        raise Exception(
                            "Different access levels specified for forms of command '%s'"
                            % command_key)
                    access_levels[command_key] = access_level

                    self.register(handler, cmd_name, params, access_level,
                                  description, inst.module_name, help_text,
                                  sub_command, extended_description)
コード例 #3
0
    def start(self):
        access_levels = {}

        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command, extended_description = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    help_text = self.get_help_file(module, help_file)

                    # TODO move this check to register()
                    if len(inspect.signature(
                            handler).parameters) != len(params) + 1:
                        raise Exception(
                            "Incorrect number of arguments for handler '%s.%s()'"
                            % (handler.__module__, handler.__name__))

                    command_key = self.get_command_key(
                        cmd_name.lower(),
                        sub_command.lower() if sub_command else "")
                    al = access_levels.get(command_key, None)
                    if al is not None and al != access_level.lower():
                        raise Exception(
                            "Different access levels specified for forms of command '%s'"
                            % command_key)
                    access_levels[command_key] = access_level

                    self.register(handler, cmd_name, params, access_level,
                                  description, module, help_text, sub_command,
                                  extended_description)
コード例 #4
0
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "event"):
                 attrs = getattr(method, "event")
                 handler = getattr(inst, name)
                 self.register(handler, attrs.event_type, attrs.description, inst.module_name, attrs.is_hidden, attrs.is_enabled)
コード例 #5
0
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "event"):
                 event_type, description = getattr(method, "event")
                 handler = getattr(inst, name)
                 module = self.util.get_module_name(handler)
                 self.register(handler, event_type, description, module)
コード例 #6
0
ファイル: setting_service.py プロジェクト: fatpower/Tyrbot-1
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "setting"):
                 setting_name, value, description, obj = getattr(method, "setting")
                 handler = getattr(inst, name)
                 module = self.util.get_module_name(handler)
                 self.register(setting_name, value, description, obj, module)
コード例 #7
0
 def start(self):
     # process decorators
     for _, inst in Registry.get_all_instances().items():
         for name, method in get_attrs(inst).items():
             if hasattr(method, "command"):
                 cmd_name, params, access_level, description, help_file, sub_command = getattr(method, "command")
                 handler = getattr(inst, name)
                 module = self.util.get_module_name(handler)
                 help_text = self.get_help_file(module, help_file)
                 self.register(handler, cmd_name, params, access_level, description, module, help_text, sub_command)
コード例 #8
0
ファイル: event_manager.py プロジェクト: ilons/Budabot_python
    def post_start(self):
        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in inst.__class__.__dict__.items():
                if hasattr(method, "event"):
                    event_type, description = getattr(method, "event")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    self.register(handler, event_type, description, module)

        # remove events that are no longer registered
        self.db.exec("DELETE FROM event_config WHERE verified = 0")

        self.db.exec(
            "DELETE FROM timer_event WHERE handler NOT IN (SELECT handler FROM event_config WHERE event_type = ?)",
            ["timer"])
コード例 #9
0
    def post_start(self):
        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in self.get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    help_text = self.get_help_file(module, help_file)
                    self.register(handler, cmd_name, params, access_level,
                                  description, module, help_text, sub_command)

        # process deferred register calls
        for args in self.deferred_register:
            self.do_register(**args)

        self.db.exec("DELETE FROM command_config WHERE verified = 0")
コード例 #10
0
    def start(self):
        # process decorators
        for _, inst in Registry.get_all_instances().items():
            for name, method in get_attrs(inst).items():
                if hasattr(method, "command"):
                    cmd_name, params, access_level, description, help_file, sub_command, extended_description, check_access, aliases = getattr(
                        method, "command")
                    handler = getattr(inst, name)
                    module = self.util.get_module_name(handler)
                    help_text = self.get_help_file(module, help_file)
                    self.register(handler, cmd_name, params, access_level,
                                  description, module, help_text, sub_command,
                                  extended_description, check_access)
                    if len(inspect.signature(
                            handler).parameters) != len(params) + 1:
                        raise Exception(
                            "Incorrect number of arguments for handler '%s.%s()'"
                            % (handler.__module__, handler.__name__))

                    if aliases:
                        for alias in aliases:
                            self.command_alias_service.add_alias(
                                alias, cmd_name)