Added admin interface to manage channels and enabled plugins (#9)
* Added base admin login/logout flows * Ignore local database * Channel model * Admin interface for channels and plugins * Added database tests along with workflows * Added some docstrings * Ignore .coverage file * Creating plugins docs WIP * Documentation * Black everything * Some documentation * Coverage for the plugins package as well * DB Fixes * Absolute FROM in Dockerfile * Database and logging fixes * Slack: Support private channels * Added pre-commit * black'd * Fixed UserQuery.create * Fixed ChannelPluginQuery.create exists call * Added ChannelPlugin menu for debugging * Ignore sqlite databases * Updated contributing docs
This commit is contained in:
parent
456d144a7d
commit
57b413dd1b
45 changed files with 2210 additions and 421 deletions
|
@ -1,15 +1,61 @@
|
|||
from datetime import datetime
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Text, Optional
|
||||
from typing import Text, Optional, Dict
|
||||
|
||||
import structlog
|
||||
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChannelPlugin:
|
||||
id: int
|
||||
channel_id: int
|
||||
plugin_id: str
|
||||
enabled: bool = False
|
||||
config: dict = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Channel:
|
||||
platform: str
|
||||
platform_channel_id: str
|
||||
channel_raw: dict
|
||||
enabled: bool = False
|
||||
id: Optional[int] = None
|
||||
plugins: Dict[str, ChannelPlugin] = field(default_factory=dict)
|
||||
|
||||
def has_enabled_plugin(self, plugin_id):
|
||||
if plugin_id not in self.plugins:
|
||||
logger.debug("No enabled!", plugin_id=plugin_id, plugins=self.plugins)
|
||||
return False
|
||||
|
||||
return self.plugins[plugin_id].enabled
|
||||
|
||||
@property
|
||||
def channel_name(self):
|
||||
from butterrobot.platforms import PLATFORMS
|
||||
|
||||
return PLATFORMS[self.platform].parse_channel_name_from_raw(self.channel_raw)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Message:
|
||||
text: Text
|
||||
chat: Text
|
||||
# TODO: Move chat references to `.channel.platform_channel_id`
|
||||
channel: Optional[Channel] = None
|
||||
author: Text = None
|
||||
from_bot: bool = False
|
||||
date: Optional[datetime] = None
|
||||
id: Optional[Text] = None
|
||||
reply_to: Optional[Text] = None
|
||||
raw: dict = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass
|
||||
class User:
|
||||
id: int
|
||||
username: Text
|
||||
password: Text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue