MCPcopy Index your code
hub / github.com/wechaty/python-wechaty / add_plugin

Method add_plugin

src/wechaty/plugin.py:726–767  ·  view source on GitHub ↗

add plugin to the manager, if the plugin name exist, it will not to be installed TODO(wj-Mcat): should support: - [ ] load plugin from local dir - [ ] load plugin from plugin contrib store - [ ] load plugin from github url

(self, plugin: Union[str, WechatyPlugin])

Source from the content-addressed store, hash-verified

724 return None
725
726 def add_plugin(self, plugin: Union[str, WechatyPlugin]) -> None:
727 """add plugin to the manager, if the plugin name exist, it will not to
728 be installed
729
730 TODO(wj-Mcat): should support:
731 - [ ] load plugin from local dir
732 - [ ] load plugin from plugin contrib store
733 - [ ] load plugin from github url
734
735 """
736 if isinstance(plugin, str):
737 regex = re.compile(
738 r'^(?:http|ftp)s?://' # http:// or https://
739 r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}'
740 r'\.?|[A-Z0-9-]{2,}\.?)|'
741 r'localhost|' # localhost...
742 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
743 r'(?::\d+)?' # optional port
744 r'(?:/?|[/?]\S+)$', re.IGNORECASE)
745 if regex.match(plugin) is None:
746 # load plugin from local file
747 plugin_instance = self._load_plugin_from_local_file(plugin)
748 else:
749 plugin_instance = self._load_plugin_from_github_url(plugin)
750 if plugin_instance is None:
751 raise WechatyPluginError(f'can"t load plugin {plugin}')
752 else:
753 if plugin.name in self._plugins:
754 log.warning('plugin : %s has exist', plugin.name)
755 return
756 plugin_instance = plugin
757
758 # set the scheduler
759 self.static_file_cacher.add_dir(plugin_instance.cache_dir)
760
761 plugin_instance.scheduler = self.scheduler
762 self._plugins[plugin_instance.name] = plugin_instance
763 # default wechaty plugin status is Running
764 self._plugin_status[plugin_instance.name] = PluginStatus.Running
765
766 # TODO(wj-Mcat): disable this event hook
767 # await plugin_instance.on_loaded()
768
769 def plugins(self) -> Iterable[WechatyPlugin]:
770 """get all of registered plugins

Callers 1

useMethod · 0.80

Calls 4

WechatyPluginErrorClass · 0.85
add_dirMethod · 0.80

Tested by

no test coverage detected