diff --git a/csp_bot/config/conf.yaml b/csp_bot/config/conf.yaml index 0604530..5709174 100644 --- a/csp_bot/config/conf.yaml +++ b/csp_bot/config/conf.yaml @@ -1,20 +1,29 @@ defaults: - commands@commands + - modules@modules - override hydra/job_logging: custom - _self_ start: # Options passed to gateway.start function - realtime: True - block: True - show: False - rest: False - ui: False + realtime: true + block: true + show: false + rest: true + ui: false + +authenticate: False +port: 8000 gateway: _target_: csp_bot.Gateway modules: - /modules/bot + - /modules/mount_rest + - /modules/mount_controls + - /modules/mount_channels_graph + - /modules/mount_outputs + - /modules/mount_api_key_middleware commands: - /commands/help - /commands/delaytest @@ -24,6 +33,9 @@ gateway: - /commands/schedule - /commands/thanks - /commands/troutslap + settings: + PORT: ${port} + AUTHENTICATE: ${authenticate} hydra: run: diff --git a/csp_bot/config/gateway/all.yaml b/csp_bot/config/gateway/all.yaml index db239de..37fd6c6 100644 --- a/csp_bot/config/gateway/all.yaml +++ b/csp_bot/config/gateway/all.yaml @@ -1,5 +1,6 @@ # @package _global_ defaults: + - /modules - _self_ discord_bot_name: ??? diff --git a/csp_bot/config/gateway/discord.yaml b/csp_bot/config/gateway/discord.yaml index 6b67898..02e2a9f 100644 --- a/csp_bot/config/gateway/discord.yaml +++ b/csp_bot/config/gateway/discord.yaml @@ -1,5 +1,6 @@ # @package _global_ defaults: + - /modules - _self_ bot_name: ??? diff --git a/csp_bot/config/gateway/mixed.yaml b/csp_bot/config/gateway/mixed.yaml index fdec03e..2bf1a01 100644 --- a/csp_bot/config/gateway/mixed.yaml +++ b/csp_bot/config/gateway/mixed.yaml @@ -1,5 +1,6 @@ # @package _global_ defaults: + - /modules - _self_ discord_bot_name: ??? diff --git a/csp_bot/config/gateway/slack.yaml b/csp_bot/config/gateway/slack.yaml index dc0c5a9..c087cf7 100644 --- a/csp_bot/config/gateway/slack.yaml +++ b/csp_bot/config/gateway/slack.yaml @@ -1,5 +1,6 @@ # @package _global_ defaults: + - /modules - _self_ bot_name: ??? diff --git a/csp_bot/config/gateway/symphony.yaml b/csp_bot/config/gateway/symphony.yaml index b7f5efb..90970e4 100644 --- a/csp_bot/config/gateway/symphony.yaml +++ b/csp_bot/config/gateway/symphony.yaml @@ -1,5 +1,6 @@ # @package _global_ defaults: + - /modules - _self_ bot_name: ??? diff --git a/csp_bot/config/modules.yaml b/csp_bot/config/modules.yaml new file mode 100644 index 0000000..88d11d0 --- /dev/null +++ b/csp_bot/config/modules.yaml @@ -0,0 +1,12 @@ + +modules: + mount_rest: + _target_: csp_gateway.MountRestRoutes + mount_controls: + _target_: csp_gateway.MountControls + mount_channels_graph: + _target_: csp_gateway.MountChannelsGraph + mount_outputs: + _target_: csp_gateway.MountOutputsFolder + mount_api_key_middleware: + _target_: csp_gateway.MountAPIKeyMiddleware diff --git a/csp_bot/gateway/gateway.py b/csp_bot/gateway/gateway.py index b31248f..ec3c4c3 100644 --- a/csp_bot/gateway/gateway.py +++ b/csp_bot/gateway/gateway.py @@ -3,14 +3,16 @@ from typing import List from csp import ts -from csp_gateway import Controls -from csp_gateway.server.gateway import ( +from csp_gateway import ( + Controls, Gateway as BaseGateway, GatewayChannels as GatewayChannelsBase, GatewayModule, + GatewaySettings as BaseGatewaySettings, ) -from pydantic import root_validator +from pydantic import Field, root_validator +from csp_bot import __version__ from csp_bot.commands import BaseCommandModel from csp_bot.structs import BotCommand, Message @@ -25,7 +27,15 @@ class GatewayChannels(GatewayChannelsBase): """Channel for webserver/graph admin. """ +class GatewaySettings(BaseGatewaySettings): + # Override from csp-gateway + TITLE: str = "CSP Bot" + DESCRIPTION: str = "# Welcome to CSP Bot API\nContains REST/Websocket interfaces to underlying CSP Gateway engine" + VERSION: str = __version__ + + class CspBotGateway(BaseGateway): + settings: GatewaySettings = Field(default_factory=GatewaySettings) commands: List[BaseCommandModel] = [] @root_validator(pre=True) @@ -63,3 +73,4 @@ def start(self, *args, **kwargs): Gateway = CspBotGateway +Settings = GatewaySettings diff --git a/csp_bot/structs.py b/csp_bot/structs.py index 5bbd1e1..21041a5 100644 --- a/csp_bot/structs.py +++ b/csp_bot/structs.py @@ -51,19 +51,34 @@ class CommandVariant(Enum): class Message(GatewayStruct): user: str - user_email: str # email of the author, for mentions - user_id: str # uid of the author, for mentions - tags: [str] # list of user ids in message, for mentions + """username of the user, specific to the platform""" + + user_email: str + """email of the author, for mentions""" + + user_id: str + """uid of the author, for mentions, specific to the platform""" + + tags: [str] + """list of user ids in message, for mentions""" msg: str + """plain text payload of the message""" - reaction: str # emote, for backends that support emote reactions - thread: str # thread id, for backends that support threads + reaction: str + """emote, for backends that support emote reactions""" - channel: str # name of channel/room - backend: str # TODO: Backend + thread: str + """thread id, for backends that support threads""" + + channel: str + """name of channel/room""" + + backend: str + """Backend, e.g. slack, symphony, discord""" - raw: object # raw message payload + _raw: object + """raw message payload, private to avoid serialization""" @staticmethod def from_raw_message(adapter_type: str, msg: Union[BaseDiscordMessage, BaseSlackMessage, BaseSymphonyMessage]) -> "Message": @@ -74,7 +89,7 @@ def from_raw_message(adapter_type: str, msg: Union[BaseDiscordMessage, BaseSlack ret.tags = msg.tags if hasattr(msg, "tags") else [] ret.msg = msg.msg if hasattr(msg, "msg") else "" ret.backend = adapter_type - ret.raw = msg + ret._raw = msg if adapter_type == "symphony": ret.channel = msg.room if msg.room != "DM" else msg.room_id # not supported