33 lines
909 B
Python
33 lines
909 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
|
||
|
|
from yuxi.channel.extensions.zulip.client import ZulipAsyncClient
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class ZulipStatus:
|
||
|
|
@staticmethod
|
||
|
|
async def probe_account(account: dict) -> bool:
|
||
|
|
realm_url = account.get("realm_url", "")
|
||
|
|
bot_email = account.get("bot_email", "")
|
||
|
|
bot_api_key = account.get("bot_api_key", "")
|
||
|
|
if not realm_url or not bot_email or not bot_api_key:
|
||
|
|
return False
|
||
|
|
|
||
|
|
client = ZulipAsyncClient(
|
||
|
|
realm_url=realm_url,
|
||
|
|
bot_email=bot_email,
|
||
|
|
bot_api_key=bot_api_key,
|
||
|
|
timeout=10.0,
|
||
|
|
connect_timeout=5.0,
|
||
|
|
)
|
||
|
|
try:
|
||
|
|
result = await client.get_own_user()
|
||
|
|
return result.get("result") == "success"
|
||
|
|
except Exception:
|
||
|
|
return False
|
||
|
|
finally:
|
||
|
|
await client.close()
|