mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-18 16:03:28 +08:00
初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
This commit is contained in:
commit
ba3836f00f
579 changed files with 83112 additions and 0 deletions
49
extensions/whatsapp/api.py
Normal file
49
extensions/whatsapp/api.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Iterable
|
||||
|
||||
WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS: tuple[str, ...] = ("whatsapp", "legacy_outbound_send")
|
||||
|
||||
_GROUP_SUFFIX = "@g.us"
|
||||
_USER_SUFFIX = "@s.whatsapp.net"
|
||||
|
||||
|
||||
def is_whatsapp_group_jid(value: str) -> bool:
|
||||
return str(value or "").strip().lower().endswith(_GROUP_SUFFIX)
|
||||
|
||||
|
||||
def is_whatsapp_user_target(value: str) -> bool:
|
||||
v = str(value or "").strip().lower()
|
||||
return v.endswith(_USER_SUFFIX) or bool(re.fullmatch(r"\+?\d{6,20}", v))
|
||||
|
||||
|
||||
def looks_like_whatsapp_target_id(value: str) -> bool:
|
||||
v = str(value or "").strip().lower()
|
||||
return is_whatsapp_group_jid(v) or is_whatsapp_user_target(v)
|
||||
|
||||
|
||||
def normalize_whatsapp_target(value: str) -> str:
|
||||
raw = str(value or "").strip()
|
||||
if not raw:
|
||||
raise ValueError("whatsapp target is required")
|
||||
low = raw.lower()
|
||||
if low.endswith(_GROUP_SUFFIX) or low.endswith(_USER_SUFFIX):
|
||||
return low
|
||||
digits = re.sub(r"[^\d+]", "", raw)
|
||||
if digits.startswith("+"):
|
||||
digits = digits[1:]
|
||||
if not digits:
|
||||
raise ValueError(f"invalid whatsapp target: {value}")
|
||||
return f"{digits}{_USER_SUFFIX}"
|
||||
|
||||
|
||||
def normalize_whatsapp_allow_from_entries(entries: Iterable[str] | None) -> tuple[str, ...]:
|
||||
out: list[str] = []
|
||||
for item in entries or ():
|
||||
try:
|
||||
out.append(normalize_whatsapp_target(str(item)))
|
||||
except Exception:
|
||||
continue
|
||||
return tuple(sorted(set(out)))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue