mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-24 22:26:30 +01:00
Per-person photo commands, where the mechanism is public and the album is not. Nothing identifying is in this repository: who the people are, what fires their photos and which file shows whom all live in one directory outside it, and the tests, the docs and the offline e2e run use three invented people instead. Several names in one message intersect -- "!alfa beta" is a photo with both -- and where an entry offers a choice the bot picks among the readings that actually have a photo, so a question the album could answer is not refused. A combination nobody photographed gets one line rather than silence, which from the group's side is indistinguishable from a broken bot. Scoping is enforced in the dispatcher, not in the handler: a command the group is not allowed resolves to nothing, so it is not answered, not counted as a command, and never named in a log line outside its own groups. A handler that quietly returned would leak all three. Commands are named by pseudonym (pack:p1), so the journal and command_uses say somebody asked for a photo and nothing about whose. Video works: the attachment goes out as data:video/mp4;filename=...;base64, which is the container's own spelling, read off its /swagger/doc.json. Told it is a photo, Signal renders a clip as an unplayable file. tool/tagger.py serves one page on loopback to fill the album in -- names are typed into the page, never as arguments, and it prints how many photos each command would have when it stops, because a command with zero is dead on arrival. Also renames the real people who were still sitting in the stats test fixtures. They remain in the history; the point is that nothing new is added to it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017w1HZ3cZ7neL3rFdQ6VMBA
98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
|
|
"""In-process transport double used by the unit tests.
|
|
|
|
This is the fast path: no sockets, no server, no event loop scheduling games.
|
|
The protocol-faithful HTTP/WebSocket fake lives in the ``fake_signal`` package
|
|
and is what the end-to-end script drives.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import AsyncIterator, Iterable
|
|
|
|
from signal_bot.quoting import Quote
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class SentMessage:
|
|
"""One outbound call captured by the fake."""
|
|
|
|
recipient: str
|
|
text: str | None = None
|
|
image_base64: str | None = None
|
|
caption: str = ""
|
|
quote: Quote | None = None
|
|
media_type: str = ""
|
|
filename: str = ""
|
|
|
|
|
|
@dataclass
|
|
class FakeTransport:
|
|
"""Replays canned frames and records everything the bot sends."""
|
|
|
|
frames: list[str] = field(default_factory=list)
|
|
sent: list[SentMessage] = field(default_factory=list)
|
|
attachments: list[str] = field(default_factory=list)
|
|
deleted: list[str] = field(default_factory=list)
|
|
|
|
def queue(self, frames: Iterable[str]) -> None:
|
|
"""Add frames to be yielded by the next receive() iteration."""
|
|
self.frames.extend(frames)
|
|
|
|
async def receive(self) -> AsyncIterator[str]:
|
|
"""Yield every queued frame once, then stop."""
|
|
for frame in list(self.frames):
|
|
yield frame
|
|
|
|
async def send_text(self, text: str, recipient: str, quote: Quote | None = None) -> None:
|
|
"""Record a text send."""
|
|
self.sent.append(SentMessage(recipient=recipient, text=text, quote=quote))
|
|
|
|
async def send_image(
|
|
self,
|
|
image_base64: str,
|
|
recipient: str,
|
|
quote: Quote | None = None,
|
|
caption: str = "",
|
|
) -> None:
|
|
"""Record an image send."""
|
|
await self.send_media(image_base64, recipient, quote, caption)
|
|
|
|
async def send_media(
|
|
self,
|
|
payload_base64: str,
|
|
recipient: str,
|
|
quote: Quote | None = None,
|
|
caption: str = "",
|
|
media_type: str = "",
|
|
filename: str = "",
|
|
) -> None:
|
|
"""Record an attachment send, type and filename included."""
|
|
self.sent.append(
|
|
SentMessage(
|
|
recipient=recipient,
|
|
image_base64=payload_base64,
|
|
quote=quote,
|
|
caption=caption,
|
|
media_type=media_type,
|
|
filename=filename,
|
|
)
|
|
)
|
|
|
|
async def list_attachments(self) -> list[str]:
|
|
"""Return the configured attachment ids."""
|
|
return list(self.attachments)
|
|
|
|
async def delete_attachment(self, attachment_id: str) -> None:
|
|
"""Record an attachment deletion."""
|
|
self.deleted.append(attachment_id)
|
|
|
|
@property
|
|
def texts(self) -> list[str]:
|
|
"""Every text body sent so far, in order."""
|
|
return [m.text for m in self.sent if m.text is not None]
|