how to fix///
This commit is contained in:
parent
dd18be4e7e
commit
bebccbd350
|
@ -56,7 +56,9 @@ async def grant_tab(request: RequestSchema):
|
||||||
@app.post("/grant_subscribe/")
|
@app.post("/grant_subscribe/")
|
||||||
async def grant_tab(request: RequestSchema):
|
async def grant_tab(request: RequestSchema):
|
||||||
profile = await get_profile(schema=request)
|
profile = await get_profile(schema=request)
|
||||||
|
print('profile')
|
||||||
await database.update_subscription(user=profile)
|
await database.update_subscription(user=profile)
|
||||||
|
print('yesss')
|
||||||
|
|
||||||
|
|
||||||
async def get_profile(schema: RequestSchema) -> UserSchema:
|
async def get_profile(schema: RequestSchema) -> UserSchema:
|
||||||
|
|
|
@ -141,8 +141,11 @@ class Database:
|
||||||
async def update_subscription(self, user: UserSchema):
|
async def update_subscription(self, user: UserSchema):
|
||||||
async with self.AsyncSessionLocal() as session:
|
async with self.AsyncSessionLocal() as session:
|
||||||
try:
|
try:
|
||||||
|
print(1)
|
||||||
await self.delete_expired_subscriptions()
|
await self.delete_expired_subscriptions()
|
||||||
|
print(2)
|
||||||
await self.delete_expired_tab_users()
|
await self.delete_expired_tab_users()
|
||||||
|
print(3)
|
||||||
expiry_datetime = datetime.datetime.fromtimestamp(user.expiry, datetime.timezone.utc)
|
expiry_datetime = datetime.datetime.fromtimestamp(user.expiry, datetime.timezone.utc)
|
||||||
if user.has_sub:
|
if user.has_sub:
|
||||||
subscription = await session.execute(select(Subscribe).where(Subscribe.discord == user.discord_id and Subscribe.nickname == user.username))
|
subscription = await session.execute(select(Subscribe).where(Subscribe.discord == user.discord_id and Subscribe.nickname == user.username))
|
||||||
|
@ -156,10 +159,14 @@ class Database:
|
||||||
else:
|
else:
|
||||||
new_subscription = Subscribe(discord=user.discord_id, nickname=user.username, expiry=expiry_datetime)
|
new_subscription = Subscribe(discord=user.discord_id, nickname=user.username, expiry=expiry_datetime)
|
||||||
session.add(new_subscription)
|
session.add(new_subscription)
|
||||||
|
print(4)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
await self.grant_tab_by_username(user=user)
|
await self.grant_tab_by_username(user=user)
|
||||||
|
print(5)
|
||||||
await self.grant_permissions_by_uuid(user=user)
|
await self.grant_permissions_by_uuid(user=user)
|
||||||
|
print(6)
|
||||||
await discord_role(str(user.discord_id))
|
await discord_role(str(user.discord_id))
|
||||||
|
print(7)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Ошибка при выполнении запроса:", e)
|
print("Ошибка при выполнении запроса:", e)
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
|
@ -173,12 +180,14 @@ class Database:
|
||||||
print("Ошибка при удалении устаревших подписок:", e)
|
print("Ошибка при удалении устаревших подписок:", e)
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
|
|
||||||
async def discord_role(discord_id: int):
|
async def discord_role(discord_id: str):
|
||||||
params = {"user_id": discord_id, "token": configs.TOKEN_DS}
|
params = {"user_id": discord_id, "token": configs.TOKEN_DS}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
|
print(66)
|
||||||
response = await client.get(configs.DS_URL, params=params)
|
response = await client.get(configs.DS_URL, params=params)
|
||||||
|
print(666)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
return data
|
return data
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
|
|
Loading…
Reference in New Issue