add trips permissions
This commit is contained in:
@@ -112,7 +112,55 @@ class C2Client:
|
||||
logger.error(f"C2 delete_trip failed: {e}")
|
||||
return False
|
||||
|
||||
async def join_trip(self, trip_id: str, user_id: str, username: str) -> bool:
|
||||
async def invite_to_trip(self, trip_id: str, discord_user_id: str) -> bool:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(
|
||||
f"{self.base}/trips/{trip_id}/invite/{discord_user_id}",
|
||||
headers=self._headers(),
|
||||
)
|
||||
r.raise_for_status()
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"C2 invite_to_trip failed: {e}")
|
||||
return False
|
||||
|
||||
async def set_trip_visibility(self, trip_id: str, visibility: str) -> bool:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.put(
|
||||
f"{self.base}/trips/{trip_id}/visibility",
|
||||
json={"visibility": visibility},
|
||||
headers=self._headers(),
|
||||
)
|
||||
r.raise_for_status()
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"C2 set_trip_visibility failed: {e}")
|
||||
return False
|
||||
|
||||
async def link_discord_account(self, code: str, discord_user_id: str, discord_username: str) -> dict:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(
|
||||
f"{self.base}/auth/link",
|
||||
json={"code": code, "discord_user_id": discord_user_id, "discord_username": discord_username},
|
||||
headers=self._headers(),
|
||||
)
|
||||
if r.status_code == 404:
|
||||
return {"error": "invalid_code"}
|
||||
if r.status_code == 410:
|
||||
return {"error": "expired"}
|
||||
if r.status_code == 409:
|
||||
return {"error": "already_linked"}
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
logger.error(f"C2 link_discord_account failed: {e}")
|
||||
return {"error": "failed"}
|
||||
|
||||
async def join_trip(self, trip_id: str, user_id: str, username: str) -> bool | str:
|
||||
"""Returns True on success, 'private' on 403, False on other errors."""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(
|
||||
@@ -120,6 +168,8 @@ class C2Client:
|
||||
json={"discord_user_id": user_id, "discord_username": username},
|
||||
headers=self._headers(),
|
||||
)
|
||||
if r.status_code == 403:
|
||||
return "private"
|
||||
r.raise_for_status()
|
||||
return True
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user