33 lines
916 B
Python
33 lines
916 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
import secrets
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class TwitterPairing:
|
||
|
|
def __init__(self):
|
||
|
|
self._codes: dict[str, str] = {}
|
||
|
|
|
||
|
|
async def generate_code(self, peer_id: str) -> str:
|
||
|
|
code = secrets.token_hex(3).upper()
|
||
|
|
self._codes[peer_id] = code
|
||
|
|
logger.info("Twitter pairing code generated for %s: %s", peer_id, code)
|
||
|
|
return code
|
||
|
|
|
||
|
|
async def verify_code(self, peer_id: str, code: str) -> bool:
|
||
|
|
stored = self._codes.get(peer_id, "")
|
||
|
|
if stored and stored.upper() == code.upper().strip():
|
||
|
|
self._codes.pop(peer_id, None)
|
||
|
|
return True
|
||
|
|
return False
|
||
|
|
|
||
|
|
def normalize_allow_entry(self, entry: str) -> str:
|
||
|
|
return str(entry).strip()
|
||
|
|
|
||
|
|
async def notify_approval(
|
||
|
|
self, config: dict, peer_id: str, account_id: str | None = None
|
||
|
|
) -> None:
|
||
|
|
pass
|