Spaces:
Runtime error
Runtime error
Create integrations/cf_worker2.py
Browse files
bot/integrations/cf_worker2.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PATH: bot/integrations/cf_worker2.py
|
| 2 |
+
from bot.config import Workers
|
| 3 |
+
from bot.integrations.http import post_json
|
| 4 |
+
from bot.core.settings import ROTATE_AFTER
|
| 5 |
+
|
| 6 |
+
def _h():
|
| 7 |
+
return {"Authorization": f"Bearer {Workers.HF_API_KEY}", "Content-Type": "application/json"}
|
| 8 |
+
|
| 9 |
+
async def allow_user(tg_id: int) -> dict:
|
| 10 |
+
return await post_json(f"{Workers.WORKER2_URL}/api/allow_user", _h(), {"tg_id": str(tg_id)})
|
| 11 |
+
|
| 12 |
+
async def disallow_user(tg_id: int) -> dict:
|
| 13 |
+
return await post_json(f"{Workers.WORKER2_URL}/api/disallow_user", _h(), {"tg_id": str(tg_id)})
|
| 14 |
+
|
| 15 |
+
async def is_allowed(tg_id: int) -> bool:
|
| 16 |
+
j = await post_json(f"{Workers.WORKER2_URL}/api/is_allowed", _h(), {"tg_id": str(tg_id)})
|
| 17 |
+
return bool(j.get("ok") and j.get("allowed") is True)
|
| 18 |
+
|
| 19 |
+
async def pick_profile(tg_id: int, channel_id: str, rotate_after: int = ROTATE_AFTER) -> dict:
|
| 20 |
+
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)})
|
| 21 |
+
|
| 22 |
+
async def access_token(tg_id: int, profile_id: str) -> dict:
|
| 23 |
+
return await post_json(f"{Workers.WORKER2_URL}/api/access_token", _h(), {"tg_id": str(tg_id), "profile_id": profile_id})
|
| 24 |
+
|
| 25 |
+
async def record_upload(tg_id: int, profile_id: str) -> dict:
|
| 26 |
+
return await post_json(f"{Workers.WORKER2_URL}/api/record_upload", _h(), {"tg_id": str(tg_id), "profile_id": profile_id})
|
| 27 |
+
|
| 28 |
+
async def stats_today() -> dict:
|
| 29 |
+
return await post_json(f"{Workers.WORKER2_URL}/api/stats_today", _h(), {})
|