understanding's picture
Create integrations/cf_worker2.py
223ca08 verified
raw
history blame
1.5 kB
# PATH: bot/integrations/cf_worker2.py
from bot.config import Workers
from bot.integrations.http import post_json
from bot.core.settings import ROTATE_AFTER
def _h():
return {"Authorization": f"Bearer {Workers.HF_API_KEY}", "Content-Type": "application/json"}
async def allow_user(tg_id: int) -> dict:
return await post_json(f"{Workers.WORKER2_URL}/api/allow_user", _h(), {"tg_id": str(tg_id)})
async def disallow_user(tg_id: int) -> dict:
return await post_json(f"{Workers.WORKER2_URL}/api/disallow_user", _h(), {"tg_id": str(tg_id)})
async def is_allowed(tg_id: int) -> bool:
j = await post_json(f"{Workers.WORKER2_URL}/api/is_allowed", _h(), {"tg_id": str(tg_id)})
return bool(j.get("ok") and j.get("allowed") is True)
async def pick_profile(tg_id: int, channel_id: str, rotate_after: int = ROTATE_AFTER) -> dict:
return await post_json(f"{Workers.WORKER2_URL}/api/pick_profile", _h(), {"tg_id": str(tg_id), "channel_id": str(channel_id), "rotate_after": int(rotate_after)})
async def access_token(tg_id: int, profile_id: str) -> dict:
return await post_json(f"{Workers.WORKER2_URL}/api/access_token", _h(), {"tg_id": str(tg_id), "profile_id": profile_id})
async def record_upload(tg_id: int, profile_id: str) -> dict:
return await post_json(f"{Workers.WORKER2_URL}/api/record_upload", _h(), {"tg_id": str(tg_id), "profile_id": profile_id})
async def stats_today() -> dict:
return await post_json(f"{Workers.WORKER2_URL}/api/stats_today", _h(), {})