|
@@ -4,8 +4,6 @@ Chatto Platform Config
|
|
|
|
|
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
-import dataclasses
|
|
|
|
|
-import json
|
|
|
|
|
import sys
|
|
import sys
|
|
|
import os
|
|
import os
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
@@ -65,6 +63,7 @@ class ChattoConstants:
|
|
|
WS_AUTH_TIMEOUT = 20.0
|
|
WS_AUTH_TIMEOUT = 20.0
|
|
|
WS_MAX_MESSAGE_BYTES = 4_000_000
|
|
WS_MAX_MESSAGE_BYTES = 4_000_000
|
|
|
WS_PING_INTERVAL = 30.0
|
|
WS_PING_INTERVAL = 30.0
|
|
|
|
|
+ WS_PING_FAILURE_THRESHOLD = 3
|
|
|
WS_RECONNECT_INITIAL_BACKOFF = 1.0
|
|
WS_RECONNECT_INITIAL_BACKOFF = 1.0
|
|
|
WS_RECONNECT_MAX_BACKOFF = 30.0
|
|
WS_RECONNECT_MAX_BACKOFF = 30.0
|
|
|
|
|
|
|
@@ -99,7 +98,7 @@ class ChattoConstants:
|
|
|
UPLOAD_CHUNK_SIZE = 256 * 1024
|
|
UPLOAD_CHUNK_SIZE = 256 * 1024
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _get_env_or_extra_str_opt(env_var: str, extra_val: Optional[str], default: Optional[str] = None) -> Optional[str]:
|
|
|
|
|
|
|
+def _get_env_or_extra_str_opt(env_var: str, extra_val: Optional[str | bool], default: Optional[str] = None) -> Optional[str]:
|
|
|
"""Get a value from environment variable or extra config."""
|
|
"""Get a value from environment variable or extra config."""
|
|
|
env_value = os.getenv(env_var)
|
|
env_value = os.getenv(env_var)
|
|
|
if env_value is not None:
|
|
if env_value is not None:
|
|
@@ -108,11 +107,13 @@ def _get_env_or_extra_str_opt(env_var: str, extra_val: Optional[str], default: O
|
|
|
if extra_val is not None:
|
|
if extra_val is not None:
|
|
|
if isinstance(extra_val, str):
|
|
if isinstance(extra_val, str):
|
|
|
return extra_val.strip()
|
|
return extra_val.strip()
|
|
|
|
|
+ elif isinstance(extra_val, bool):
|
|
|
|
|
+ return str(extra_val)
|
|
|
else:
|
|
else:
|
|
|
- logger.error("extra_val: " + extra_val + " is supposed to be str, but " + str(type(extra_val)) + " was found.")
|
|
|
|
|
|
|
+ logger.error("extra_val: %s is supposed to be str, but %s was found.", extra_val, str(type(extra_val)))
|
|
|
|
|
|
|
|
if default is not None:
|
|
if default is not None:
|
|
|
- logger.info("Chatto: Defaulting to '%s'", default)
|
|
|
|
|
|
|
+ logger.debug("Chatto: Defaulting to '%s'", default)
|
|
|
return default.strip()
|
|
return default.strip()
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
@@ -124,13 +125,13 @@ def _get_env_or_extra_str(env_var: str, extra_val: Optional[str], default: Optio
|
|
|
return ""
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _get_env_or_extra_truthy(env_var: str, extra_val: Optional[str], default: bool = False) -> bool:
|
|
|
|
|
|
|
+def _get_env_or_extra_truthy(env_var: str, extra_val: Optional[str | bool], default: bool = False) -> bool:
|
|
|
"""Get a boolean value from environment variable or extra config."""
|
|
"""Get a boolean value from environment variable or extra config."""
|
|
|
- return utils.is_truthy_value(_get_env_or_extra_str(env_var, extra_val, "False"), default)
|
|
|
|
|
|
|
+ return utils.is_truthy_value(_get_env_or_extra_str(env_var, str(extra_val), "False"), default)
|
|
|
|
|
|
|
|
|
|
|
|
|
def _split_str_to_list(mystring: str) -> list:
|
|
def _split_str_to_list(mystring: str) -> list:
|
|
|
- logger.info("mystring: " + mystring)
|
|
|
|
|
|
|
+ logger.info("mystring: %s", mystring)
|
|
|
return list(c for c in mystring.split(","))
|
|
return list(c for c in mystring.split(","))
|
|
|
|
|
|
|
|
|
|
|
|
@@ -175,7 +176,7 @@ class ConfigField(Generic[T]):
|
|
|
def __set__(self, instance: Any, value: T) -> None:
|
|
def __set__(self, instance: Any, value: T) -> None:
|
|
|
self.value = value
|
|
self.value = value
|
|
|
self._type = type(value)
|
|
self._type = type(value)
|
|
|
- logger.info("Chatto: configuration field '" + self.field_name + "' set to '" + str(value) + "'")
|
|
|
|
|
|
|
+ logger.info("Chatto: configuration field '%s' set to '%s'", self.field_name, str(value))
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
def __str__(self) -> str:
|
|
|
return str(self.value)
|
|
return str(self.value)
|
|
@@ -226,8 +227,10 @@ class ChattoConfiguration:
|
|
|
self.home_channel.value = _get_env_or_extra_str(self.home_channel.env_name, pconfig.extra.get(self.home_channel.field_name))
|
|
self.home_channel.value = _get_env_or_extra_str(self.home_channel.env_name, pconfig.extra.get(self.home_channel.field_name))
|
|
|
|
|
|
|
|
self.allowed_users.value = _get_env_or_extra_list(self.allowed_users.env_name, pconfig.extra.get(self.allowed_users.field_name))
|
|
self.allowed_users.value = _get_env_or_extra_list(self.allowed_users.env_name, pconfig.extra.get(self.allowed_users.field_name))
|
|
|
|
|
+ logger.info("self.allowed_users.value: %s", self.allowed_users.value)
|
|
|
|
|
|
|
|
self.require_mention.value = _get_env_or_extra_truthy(self.require_mention.env_name, pconfig.extra.get(self.require_mention.field_name))
|
|
self.require_mention.value = _get_env_or_extra_truthy(self.require_mention.env_name, pconfig.extra.get(self.require_mention.field_name))
|
|
|
|
|
+ logger.info("self.require_mention.value: %s", self.require_mention.value)
|
|
|
|
|
|
|
|
# free_response_channels: room IDs where the bot responds without being mentioned via "@botname"
|
|
# free_response_channels: room IDs where the bot responds without being mentioned via "@botname"
|
|
|
self.free_response_channels_list.value = _get_env_or_extra_list(self.free_response_channels_list.env_name,
|
|
self.free_response_channels_list.value = _get_env_or_extra_list(self.free_response_channels_list.env_name,
|
|
@@ -239,4 +242,6 @@ class ChattoConfiguration:
|
|
|
self.auto_thread.value = _get_env_or_extra_truthy(self.auto_thread.env_name, pconfig.extra.get(self.auto_thread.field_name))
|
|
self.auto_thread.value = _get_env_or_extra_truthy(self.auto_thread.env_name, pconfig.extra.get(self.auto_thread.field_name))
|
|
|
|
|
|
|
|
self.allow_all_users.value = _get_env_or_extra_truthy(self.allow_all_users.env_name, pconfig.extra.get(self.allow_all_users.field_name))
|
|
self.allow_all_users.value = _get_env_or_extra_truthy(self.allow_all_users.env_name, pconfig.extra.get(self.allow_all_users.field_name))
|
|
|
- self.reactions.value = _get_env_or_extra_truthy(self.reactions.env_name, pconfig.extra.get(self.reactions.field_name))
|
|
|
|
|
|
|
+ self.reactions.value = _get_env_or_extra_truthy(self.reactions.env_name, pconfig.extra.get(self.reactions.field_name))
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("ChattoConfiguration: %s", self)
|