Files
vortex/tui/app/vortex_tui/qr.py
T
Prad NukalaandClaude Fable 5 d57086cd00 feat: unified messaging TUI MVP — Synapse + 7 mautrix bridges + Textual TUI + MCP draft staging
One-command local stack: cp .env.example .env && make up. Idempotent
bootstrap renders Synapse + bridge configs from pristine upstream examples,
provisions databases, registrations, double puppeting, and the admin user.
Textual TUI with bridge manager, in-terminal QR login, and drafts panel.
MCP server exposes read tools and a human-gated draft send workflow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 12:13:13 -04:00

36 lines
1.3 KiB
Python

"""Render QR-ish message payloads as unicode half-block QR codes."""
import qrcode
QR_SCHEMES = ("https://wa.me/", "gmessages://")
def looks_like_qr_payload(body: str, sender_is_bridge_bot: bool) -> bool:
"""Deliberately simple heuristic:
- message starts with a known pairing scheme (whatsapp / gmessages), or
- a bridge-bot message that is a single URL/token: 20-199 chars, no
whitespace, and either contains '://' or is alnum-ish (pairing code).
"""
body = body.strip()
if body.startswith(QR_SCHEMES):
return True
if sender_is_bridge_bot and 20 <= len(body) < 200 and not any(c.isspace() for c in body):
return "://" in body or body.replace("-", "").replace("_", "").isalnum()
return False
def render_qr(text: str) -> str:
"""QR code as text, two matrix rows per output line via half blocks."""
qr = qrcode.QRCode(border=1)
qr.add_data(text)
qr.make(fit=True)
matrix = qr.get_matrix()
if len(matrix) % 2:
matrix.append([False] * len(matrix[0]))
chars = {(True, True): "█", (True, False): "▀", (False, True): "▄", (False, False): " "}
return "\n".join(
"".join(chars[(top[x], bottom[x])] for x in range(len(top)))
for top, bottom in zip(matrix[::2], matrix[1::2])
)