csbot.plugins.webserver module

Creates a web server using aiohttp so that other plugins can register URL handlers.

To register a URL handler, a plugin should hook the webserver.build event and create a sub-application, for example:

class MyPlugin(Plugin):
    @Plugin.hook('webserver.build')
    def create_app(self, e):
        with e['webserver'].create_subapp('/my_plugin') as app:
            app.add_routes([web.get('/{item}', self.request_handler)])

    async def request_handler(self, request):
        return web.Response(text=f'No {request.match_info["item"]} here, oh dear!')

Configuration

The following configuration options are supported in the [webserver] config section:

Setting Description
host Hostname/IP address to listen on. Default: localhost.
port Port to listen on. Default: 1337.

Module contents

class csbot.plugins.webserver.WebServer(bot)[source]

Bases: csbot.plugin.Plugin

CONFIG_DEFAULTS = {'host': 'localhost', 'port': 1337}
setup()[source]

Plugin setup.

  • Replace all ProvidedByPlugin attributes.
  • Fire all plugin integration methods.
  • Register all commands provided by the plugin.
teardown()[source]

Plugin teardown.

  • Unregister all commands provided by the plugin.
create_subapp(prefix)[source]