feat: add context manager support to FragmentClient; update README and tests

This commit is contained in:
bohd4nx
2026-03-16 19:21:43 +02:00
parent 20b73444ab
commit c5edfad06f
5 changed files with 114 additions and 26 deletions
+14 -5
View File
@@ -37,14 +37,14 @@ class FragmentClient:
Example::
client = FragmentClient(
async with FragmentClient(
seed="word1 word2 ...",
api_key="AAABBB...",
cookies={"stel_ssid": "...", "stel_dt": "...", ...},
)
print(await client.get_wallet())
result = await client.purchase_premium("@username", months=6)
print(result.transaction_id)
) as client:
print(await client.get_wallet())
result = await client.purchase_premium("@username", months=6)
print(result.transaction_id)
"""
def __init__(
@@ -88,6 +88,15 @@ class FragmentClient:
self.cookies: dict = cookies
self.wallet_version: WalletVersion = version # type: ignore[assignment]
async def __aenter__(self) -> "FragmentClient":
return self
async def __aexit__(self, *_: object) -> None:
pass
def __repr__(self) -> str:
return f"FragmentClient(wallet_version='{self.wallet_version}', cookies={len(self.cookies)} keys)"
async def purchase_premium(self, username: str, months: int, show_sender: bool = True) -> PremiumResult:
"""Purchase Telegram Premium for a user.