glados.plugin module — GLaDOS 0.0.1-alpha1 documentation

# glados.plugin module

class `glados.plugin.` `GladosPlugin`(name, bot, **kwargs)

  Bases: `object`

  Parent class for a GLaDOS Plugin

  Parameters

    - name (str) – the name of the plugin

    - bot (GladosBot) – the GLaDOS bot that this plugin will use

    - kwargs –

  Examples

      >>> def mock_function(request):
      ...     print("Mock Function")
      >>> plugin = GladosPlugin("mock", None)
      >>> plugin.add_route(RouteType.SendMessage, "send_message", mock_function)
      >>> from glados import GladosRoute
      >>> plugin.routes[0].__dict__ == GladosRoute(RouteType.SendMessage, "send_message", mock_function).__dict__
      True
      >>> try:
      ...     plugin.add_route(RouteType.SendMessage, "send_message", mock_function)
      ... except GladosPathExistsError:
      ...     print("Got Error")
      Got Error

  `add_route`(route_type, route, function)

    Add a new route to the plugin

    Parameters

      - route_type (RouteType) – what type of route this is this

      - route (Union[EventRoutes, str]) – what is the route to be added

      - function (Callable) – the function to be executed when this route runs

  property `routes`

    List all routes for the plugin.

    Examples

        >>> from plugin import GladosPlugin
        >>> from router import RouteType, GladosRoute
        >>> plugin = GladosPlugin("mockPlugin", None)
        >>> plugin.routes
        []
        >>> plugin.add_route(RouteType.SendMessage, "send_message", (lambda x: 1))
        >>> r = plugin.routes[0] # type: GladosRoute
        >>> r.route == "send_message"
        True
        >>> r.function("NULL")
        1

  `send_request`(request, **kwargs)

    This is the function to be called when sending a request to a plugin.

    This function is responsible for validating the slack signature if needed. It also returns and empty string if the function called returns None.

    Parameters

      - request (GladosRequest) – the request object to be sent

      - kwargs –