butterrobot/butterrobot/platforms/debug.py
Felipe Martin Garcia 57b413dd1b
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
2022-02-05 13:00:20 +01:00

44 lines
1.2 KiB
Python

import uuid
from datetime import datetime
import structlog
from butterrobot.platforms.base import Platform, PlatformMethods
from butterrobot.objects import Message, Channel
logger = structlog.get_logger(__name__)
class DebugMethods(PlatformMethods):
@classmethod
def send_message(self, message: Message):
logger.debug(
"Outgoing message", message=message.__dict__, platform=DebugPlatform.ID
)
class DebugPlatform(Platform):
ID = "debug"
methods = DebugMethods
@classmethod
def parse_incoming_message(cls, request):
request_data = request["json"]
logger.debug("Parsing message", data=request_data, platform=cls.ID)
return Message(
id=str(uuid.uuid4()),
date=datetime.now(),
text=request_data["text"],
from_bot=bool(request_data.get("from_bot", False)),
author=request_data.get("author", "Debug author"),
chat=request_data.get("chat", "Debug chat ID"),
channel=Channel(
platform=cls.ID,
platform_channel_id=request_data.get("chat"),
channel_raw={},
),
raw={},
)