Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions csp_bot/config/conf.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,6 +33,9 @@ gateway:
- /commands/schedule
- /commands/thanks
- /commands/troutslap
settings:
PORT: ${port}
AUTHENTICATE: ${authenticate}

hydra:
run:
Expand Down
1 change: 1 addition & 0 deletions csp_bot/config/gateway/all.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _global_
defaults:
- /modules
- _self_

discord_bot_name: ???
Expand Down
1 change: 1 addition & 0 deletions csp_bot/config/gateway/discord.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _global_
defaults:
- /modules
- _self_

bot_name: ???
Expand Down
1 change: 1 addition & 0 deletions csp_bot/config/gateway/mixed.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _global_
defaults:
- /modules
- _self_

discord_bot_name: ???
Expand Down
1 change: 1 addition & 0 deletions csp_bot/config/gateway/slack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _global_
defaults:
- /modules
- _self_

bot_name: ???
Expand Down
1 change: 1 addition & 0 deletions csp_bot/config/gateway/symphony.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# @package _global_
defaults:
- /modules
- _self_

bot_name: ???
Expand Down
12 changes: 12 additions & 0 deletions csp_bot/config/modules.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 14 additions & 3 deletions csp_bot/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -63,3 +73,4 @@ def start(self, *args, **kwargs):


Gateway = CspBotGateway
Settings = GatewaySettings
33 changes: 24 additions & 9 deletions csp_bot/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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
Expand Down