ZeroKnight / ZeroBot

My personal IRC/Multi-protocol Bot created (and re-created) for education and amusement.
MIT License
1 stars 0 forks source link

Implement awareness of "available" modules #12

Closed ZeroKnight closed 4 years ago

ZeroKnight commented 4 years ago

ZeroBot should be aware of protocol and feature modules that are available to load, but have not yet been loaded. This is strongly tied to issue #11, and will likely need to be resolved first.

I believe that this could be done rather simply with importlib.util.find_spec, as shown in this example. It could be wrapped up something like the following:

# Possibly in ZeroBot.module somewhere, or in Core
def feature_available(self, module_id: str) -> bool:
    return importlib.util.find_spec(f'ZeroBot.feature.{module_id}') is not None

Be sure to raise NoSuchModule exceptions where appropriate throughout Core; it should accompany anywhere that already raises ModuleNotLoaded for the most part.