-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot_config.py
More file actions
118 lines (87 loc) · 3.08 KB
/
Copy pathbot_config.py
File metadata and controls
118 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""Bot configuration using chatom backend configurations.
This module provides configuration classes that wrap chatom's
backend-specific configurations with bot-specific settings.
"""
from typing import List, Optional, Set
from ccflow import BaseModel
from pydantic import Field
from .backends import (
DiscordConfig as ChatomDiscordConfig,
SlackConfig as ChatomSlackConfig,
SymphonyConfig as ChatomSymphonyConfig,
TelegramConfig as ChatomTelegramConfig,
)
__all__ = (
"BackendConfig",
"BotConfig",
"DiscordConfig",
"SlackConfig",
"SymphonyConfig",
"TelegramConfig",
)
class BackendConfig(BaseModel):
"""Base configuration for a bot backend.
This wraps a chatom backend config with bot-specific settings.
The bot name is auto-detected from the backend if not provided.
"""
bot_name: str = Field(
default="",
description="Name of the bot. Auto-detected from backend if empty.",
)
channels: Set[str] = Field(
default_factory=set,
description="Channels/rooms to subscribe to. Empty means all.",
)
user_access_channels: List[str] = Field(
default_factory=list,
description="If non-empty, only users from these channels can interact with the bot.",
)
query_user_access_seconds: int = Field(
default=300,
description="How frequently to query user access channels. 0 means only at startup.",
)
unauthorized_msg: Optional[str] = Field(
default="You are not authorized to interact with this bot.",
description="Message to send when unauthorized user interacts. None means no message.",
)
class DiscordConfig(BackendConfig):
"""Discord bot configuration."""
config: ChatomDiscordConfig = Field(
default_factory=ChatomDiscordConfig,
description="Chatom Discord configuration.",
)
class SlackConfig(BackendConfig):
"""Slack bot configuration."""
config: ChatomSlackConfig = Field(
default_factory=ChatomSlackConfig,
description="Chatom Slack configuration.",
)
class SymphonyConfig(BackendConfig):
"""Symphony bot configuration."""
config: ChatomSymphonyConfig = Field(
default_factory=ChatomSymphonyConfig,
description="Chatom Symphony configuration.",
)
set_presence_seconds: int = Field(
default=0,
description="Seconds between presence updates. 0 means never.",
)
class TelegramConfig(BackendConfig):
"""Telegram bot configuration."""
config: ChatomTelegramConfig = Field(
default_factory=ChatomTelegramConfig,
description="Chatom Telegram configuration.",
)
class BotConfig(BaseModel):
"""Main bot configuration.
Configure which backends the bot should connect to and
their respective settings.
"""
discord: Optional[DiscordConfig] = None
slack: Optional[SlackConfig] = None
symphony: Optional[SymphonyConfig] = None
telegram: Optional[TelegramConfig] = None
ratelimit_seconds: float = Field(
default=1.0,
description="Minimum seconds between message outputs.",
)