mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-02 13:35:14 +00:00
* feat: add simplex-support-bot-light * feat: package simplex-support-bot-light for docker * docs: document simplex-support-bot-light * fix: make a missing config actionable and bounded * docs: note the attached compose Ctrl+C behaviour * refactor: use the library for startup and custom data * refactor: drop the display-name workaround * style: shorten the startup comment * build: build the core and the library into the image * docs: correct where the image type rule comes from * fix: log what the core said a command got wrong * build: run the container as the operator's uid * docs: keep the container uid in .env * docs: tighten the README
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Everything the handlers need, resolved once at startup."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from dataclasses import dataclass, field
|
|
|
|
from simplex_chat import ChatApi, ChatError
|
|
|
|
from .config import Config
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class BotContext:
|
|
"""API handle plus the ids and config resolved during startup."""
|
|
|
|
api: ChatApi
|
|
user_id: int
|
|
roster_group_id: int
|
|
config: Config
|
|
# Business chats repaired by the startup pass, so the queued event for the
|
|
# same chat does not report the customer a second time.
|
|
repaired: set[int] = field(default_factory=set)
|
|
|
|
async def post_to_roster(self, text: str) -> None:
|
|
"""Send a message to the roster group.
|
|
|
|
Never raises: this is the operator's visibility channel, and a failure
|
|
to report an event must not also discard the event that caused it.
|
|
"""
|
|
try:
|
|
await self.api.api_send_text_message(["group", self.roster_group_id], text)
|
|
except ChatError:
|
|
log.warning("could not post to the roster group: %s", text, exc_info=True)
|