def probe(self, _, line): for subclass in get_all_subclasses(base.BaseServer): if subclass.provides(self.base): self.spec_extension = subclass.__name__ self.load_extension(subclass) return # Load a stub extension. *sigh* _logger.warning("No IRC daemon specific extension found!") self.spec_extension = base.BaseServer self.load_extension(base.BaseServer)
def __init__(self, **kwargs): # Iterate over all packages in the plugins submodule so # get_all_subclasses can find all the plugins in there. for _, name, _ in iter_modules(plugins.__path__, 'seabird.plugins.'): __import__(name) # Update extensions to ensure we have bot_recommended and maybe add all # the seabird plugins if none are defined. extensions = kwargs.get('extensions') if not extensions: extensions = [] for cls in get_all_subclasses(BaseExtension): if not cls.__module__.startswith('seabird.plugins.'): continue extensions.append(cls.__name__) extensions = bot_recommended + extensions kwargs['extensions'] = extensions super().__init__(**kwargs)
def get_extension(name, prefer_builtin=True): """Get the class of a builtin extension by string. :returns: The extension class if found, else None. """ # Attempt autodiscovery first extensions = [ c for c in get_all_subclasses(BaseExtension) if c.__name__ == name ] if not extensions: # None found, try an import from the builtins. try: module_name = _builtin_extension_modules[name] except KeyError: return None # The below shouldn't fail, ever. module = import_module("PyIRC.extensions.%s" % module_name) return getattr(module, name) elif len(extensions) == 1: # We got only one. :p return extensions[0] else: extension_pref = None for extension in reversed(extensions): qualname = extension.__qualname__ if (extension_pref is None or prefer_builtin is qualname.startswith("PyIRC.extensions.")): # prefer_builtins controls the behaviour of this condition. # Yes, it's actually correct. extension_pref = extension return extension_pref
def get_extension(name, prefer_builtin=True): """Get the class of a builtin extension by string. :returns: The extension class if found, else None. """ # Attempt autodiscovery first extensions = [c for c in get_all_subclasses(BaseExtension) if c.__name__ == name] if not extensions: # None found, try an import from the builtins. try: module_name = _builtin_extension_modules[name] except KeyError: return None # The below shouldn't fail, ever. module = import_module("PyIRC.extensions.%s" % module_name) return getattr(module, name) elif len(extensions) == 1: # We got only one. :p return extensions[0] else: extension_pref = None for extension in reversed(extensions): qualname = extension.__qualname__ if (extension_pref is None or prefer_builtin is qualname.startswith("PyIRC.extensions.")): # prefer_builtins controls the behaviour of this condition. # Yes, it's actually correct. extension_pref = extension return extension_pref