mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 10:03:40 +01:00
Fix server
This commit is contained in:
parent
5449a7d4ce
commit
09542ab7b3
1 changed files with 8 additions and 8 deletions
|
@ -14,15 +14,14 @@ from discord.ext.commands import Paginator
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import FastAPI, Header, HTTPException, Request, dependencies, status, Depends
|
from fastapi import FastAPI, HTTPException, Request, status, Depends, Query
|
||||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials as HTTPAuthCreds
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials as HTTPAuthCreds
|
||||||
from fastapi import WebSocketException as _WSException
|
from fastapi import WebSocketException as _WSException
|
||||||
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
||||||
from starlette.websockets import WebSocket, WebSocketDisconnect
|
from starlette.websockets import WebSocket, WebSocketDisconnect
|
||||||
from websockets.exceptions import WebSocketException
|
from websockets.exceptions import WebSocketException
|
||||||
|
|
||||||
from config import guilds
|
from utils import get_or_none, BridgeBind
|
||||||
from utils import BannedStudentID, Student, VerifyCode, console, get_or_none, BridgeBind
|
|
||||||
from utils.db import AccessTokens
|
from utils.db import AccessTokens
|
||||||
|
|
||||||
SF_ROOT = Path(__file__).parent / "static"
|
SF_ROOT = Path(__file__).parent / "static"
|
||||||
|
@ -323,8 +322,8 @@ async def bridge_bind_new(mx_id: str):
|
||||||
token = secrets.token_urlsafe()
|
token = secrets.token_urlsafe()
|
||||||
app.state.binds[token] = mx_id
|
app.state.binds[token] = mx_id
|
||||||
url = discord.utils.oauth_url(
|
url = discord.utils.oauth_url(
|
||||||
OAUTH_ID,
|
OAUTH_ID,
|
||||||
redirect_uri=BIND_REDIRECT_URI,
|
redirect_uri=BIND_REDIRECT_URI,
|
||||||
scopes=("identify",)
|
scopes=("identify",)
|
||||||
) + f"&state={token}&prompt=none"
|
) + f"&state={token}&prompt=none"
|
||||||
return {
|
return {
|
||||||
|
@ -371,13 +370,13 @@ async def bridge_bind_delete(mx_id: str, code: str = None, state: str = None):
|
||||||
existing: Optional[BridgeBind] = await get_or_none(BridgeBind, matrix_id=mx_id)
|
existing: Optional[BridgeBind] = await get_or_none(BridgeBind, matrix_id=mx_id)
|
||||||
if not existing:
|
if not existing:
|
||||||
raise HTTPException(404, "Not found")
|
raise HTTPException(404, "Not found")
|
||||||
|
|
||||||
if not (code and state) or state not in app.state.binds:
|
if not (code and state) or state not in app.state.binds:
|
||||||
token = secrets.token_urlsafe()
|
token = secrets.token_urlsafe()
|
||||||
app.state.binds[token] = mx_id
|
app.state.binds[token] = mx_id
|
||||||
url = discord.utils.oauth_url(
|
url = discord.utils.oauth_url(
|
||||||
OAUTH_ID,
|
OAUTH_ID,
|
||||||
redirect_uri=BIND_REDIRECT_URI,
|
redirect_uri=BIND_REDIRECT_URI,
|
||||||
scopes=("identify",)
|
scopes=("identify",)
|
||||||
) + f"&state={token}&prompt=none"
|
) + f"&state={token}&prompt=none"
|
||||||
return JSONResponse({"status": "pending", "url": url})
|
return JSONResponse({"status": "pending", "url": url})
|
||||||
|
@ -392,6 +391,7 @@ async def bridge_bind_delete(mx_id: str, code: str = None, state: str = None):
|
||||||
await existing.delete()
|
await existing.delete()
|
||||||
return JSONResponse({"status": "ok"}, 200)
|
return JSONResponse({"status": "ok"}, 200)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/bridge/bind/{mx_id}", dependencies=[Depends(is_authenticated)])
|
@app.get("/bridge/bind/{mx_id}", dependencies=[Depends(is_authenticated)])
|
||||||
async def bridge_bind_fetch(mx_id: str):
|
async def bridge_bind_fetch(mx_id: str):
|
||||||
"""Fetch the discord account associated with a matrix account."""
|
"""Fetch the discord account associated with a matrix account."""
|
||||||
|
|
Loading…
Reference in a new issue