netresearch/matrix-skill / skills/matrix-communication
matrix-communication
FlaggedUse when communicating via Matrix chat, notifying teams, or managing E2EE. Triggers on #room:server references, Matrix URLs, and chat requests.
scripts/_lib/utils.py
View on GitHub# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Netresearch DTT GmbH
"""Utility functions for Matrix scripts.
All functions use ONLY stdlib.
"""
import logging
import socket
from datetime import UTC, datetime
def clean_message(message: str) -> str:
"""Clean message from bash escaping artifacts.
Bash history expansion in interactive shells can escape ! to \\!
when using double quotes. This removes those artifacts.
"""
# Remove backslash before ! (bash history expansion artifact)
return message.replace("\\!", "!")
def prefer_ipv4():
"""Monkey-patch socket.getaddrinfo to prefer IPv4 results.
Workaround for WSL2 environments where IPv6 routes are often
unreachable while IPv4 works fine. Call once at script startup.
"""
_orig = socket.getaddrinfo
socket.getaddrinfo = lambda *a, **kw: sorted(
_orig(*a, **kw), key=lambda r: r[0] != socket.AF_INET
)
def suppress_nio_logging():
"""Suppress noisy matrix-nio crypto/sync warnings.
Sets nio and peewee loggers to ERROR level to hide megolm session
warnings that clutter output during normal operation.
"""
for name in ("nio", "nio.crypto", "nio.responses", "peewee"):
logging.getLogger(name).setLevel(logging.ERROR)
def format_timestamp(ts: int) -> str:
"""Format Matrix timestamp to readable string.
Args:
ts: Unix timestamp in milliseconds
Returns:
Formatted string like "2024-01-15 14:30"
"""
if ts == 0:
return "unknown"
# Local time, intended for human-readable display; converted from an aware UTC value.
dt = datetime.fromtimestamp(ts / 1000, tz=UTC).astimezone()
return dt.strftime("%Y-%m-%d %H:%M")
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |