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

Method start

src/wechaty/plugin.py:828–888  ·  view source on GitHub ↗

set wechaty to plugins

(self)

Source from the content-addressed store, hash-verified

826 return url
827
828 async def start(self) -> None:
829 """
830 set wechaty to plugins
831 """
832 log.info('start the plugins ...')
833
834 # 1. init the plugins
835 for name, plugin in self._plugins.items():
836 log.info('init %s-plugin ...', name)
837 assert isinstance(plugin, WechatyPlugin)
838 # set wechaty instance to all of the plugin bot attribute
839
840 plugin.set_bot(self._wechaty)
841 await plugin.init_plugin(self._wechaty)
842 await plugin.blueprint(self.app)
843 self.scheduler.start()
844 # check the host & port configuration
845
846 # pylint: disable=W0212
847 host, port = self.endpoint[0], self.endpoint[1]
848 if _check_local_port(port):
849 raise WechatyPluginError(
850 f'local port<{port}> is in use, can"t start plugin server. '
851 'So please use the another valid port'
852 )
853 # 3. list all valid endpoints in web service
854 # checking the number of registered blueprints
855 routes_txt = _list_routes_txt(self.app)
856 if len(routes_txt) == 0:
857 log.warning(
858 'there is not registed blueprint in the plugins, '
859 'so bot will not start the web service'
860 )
861 return
862
863 await self.register_ui_view(self.app)
864 # re-fetch the routes info
865 routes_txt = _list_routes_txt(self.app)
866
867 log.info(
868 '============================starting web service========================')
869 log.info('starting web service at endpoint: <{%s}:{%d}>', host, port)
870
871 shutdown_trigger = await get_shutdown_trigger()
872 task = self.app.run_task(
873 host=host,
874 port=port,
875 shutdown_trigger=shutdown_trigger
876 )
877 loop = asyncio.get_event_loop()
878 loop.create_task(task)
879
880 loop.create_task(
881 shutdown(shutdown_trigger)
882 )
883
884 for route_txt in routes_txt:
885 log.info(route_txt)

Callers

nothing calls this directly

Calls 9

register_ui_viewMethod · 0.95
_check_local_portFunction · 0.85
WechatyPluginErrorClass · 0.85
_list_routes_txtFunction · 0.85
get_shutdown_triggerFunction · 0.85
shutdownFunction · 0.85
set_botMethod · 0.80
init_pluginMethod · 0.80
blueprintMethod · 0.45

Tested by

no test coverage detected