1
0
forked from sass/tipibot

Added Fienta integration

This commit is contained in:
AlacrisDevs
2026-04-29 22:38:47 +03:00
parent a4a447867f
commit 3c2b4342a2
12 changed files with 1336 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
"""Destructively recreate economy PocketBase collections for dev + economy profiles.
"""Destructively recreate TipiBOT PocketBase collections.
Usage:
python scripts/reset_pb_collections.py --confirm
@@ -6,6 +6,8 @@ Usage:
This will DELETE and recreate the collections configured by:
- PB_ECONOMY_COLLECTION_DEV
- PB_ECONOMY_COLLECTION_ECONOMY
- PB_ECONOMY_COLLECTION_LAN
- PB_FIENTA_COLLECTION_LAN
"""
from __future__ import annotations
@@ -114,6 +116,51 @@ def _collection_payload(name: str) -> dict:
}
def _fienta_collection_payload(name: str) -> dict:
fields = [
_text_field("registration_key", required=True),
_text_field("order_id"),
_text_field("ticket_code"),
_text_field("order_status"),
_text_field("order_url"),
_text_field("payment_time"),
_text_field("game"),
_text_field("kind"),
_text_field("ticket_type_id"),
_text_field("ticket_title"),
_text_field("ticket_group_title"),
_text_field("team_name"),
_text_field("discord_username"),
_text_field("nickname"),
_text_field("country"),
_text_field("country_code"),
_text_field("riot_id"),
_text_field("steam64_id"),
_text_field("vrs_ranking"),
_bool_field("is_main"),
_bool_field("is_reserve"),
_bool_field("is_manager"),
_bool_field("is_captain"),
_bool_field("sheet_public"),
_bool_field("blocked_country"),
_bool_field("active"),
_bool_field("roles_synced"),
_text_field("last_sync_error"),
_text_field("updated_at"),
]
return {
"name": name,
"type": "base",
"fields": fields,
"listRule": None,
"viewRule": None,
"createRule": None,
"updateRule": None,
"deleteRule": None,
}
async def _auth_token(session: aiohttp.ClientSession) -> str:
async with session.post(
f"{PB_URL}/api/collections/_superusers/auth-with-password",
@@ -138,8 +185,12 @@ async def _delete_if_exists(session: aiohttp.ClientSession, headers: dict[str, s
print(f"[DELETE] {name}")
async def _create_collection(session: aiohttp.ClientSession, headers: dict[str, str], name: str) -> None:
payload = _collection_payload(name)
async def _create_collection(
session: aiohttp.ClientSession,
headers: dict[str, str],
name: str,
payload: dict,
) -> None:
async with session.post(f"{PB_URL}/api/collections", json=payload, headers=headers) as resp:
if resp.status not in (200, 201):
raise RuntimeError(f"Create failed for {name} ({resp.status}): {await resp.text()}")
@@ -154,10 +205,17 @@ async def main() -> None:
if not args.confirm:
raise SystemExit("Refusing to run without --confirm (this operation deletes collections).")
targets = []
for name in [config.PB_ECONOMY_COLLECTION_DEV, config.PB_ECONOMY_COLLECTION_ECONOMY]:
if name and name not in targets:
targets.append(name)
targets: list[tuple[str, dict]] = []
for name in [
config.PB_ECONOMY_COLLECTION_DEV,
config.PB_ECONOMY_COLLECTION_ECONOMY,
config.PB_ECONOMY_COLLECTION_LAN,
]:
if name and all(existing != name for existing, _ in targets):
targets.append((name, _collection_payload(name)))
fienta_name = config.PB_FIENTA_COLLECTION_LAN
if fienta_name and all(name != fienta_name for name, _ in targets):
targets.append((fienta_name, _fienta_collection_payload(fienta_name)))
if not targets:
raise SystemExit("No target collections configured.")
@@ -167,12 +225,12 @@ async def main() -> None:
token = await _auth_token(session)
headers = {"Authorization": token}
for name in targets:
for name, payload in targets:
await _delete_if_exists(session, headers, name)
await _create_collection(session, headers, name)
await _create_collection(session, headers, name, payload)
print("\nDone. Collections recreated:")
for name in targets:
for name, _ in targets:
print(f" - {name}")