Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions bases/bot_detector/website/api/account_search.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from bot_detector.website.core.config import BD_API, templates
from fastapi import APIRouter, Form, Request
from fastapi.responses import HTMLResponse

router = APIRouter()


@router.get("/account-search")
async def get_account_search(request: Request) -> HTMLResponse:
return templates.TemplateResponse("pages/account_search.html", {"request": request})


@router.post("/account-search")
async def post_account_search(
request: Request, username: str = Form(...)
) -> HTMLResponse:
# You can access the submitted username using the "username" variable
prediction = await BD_API.get_prediction(name=username)
response = {"request": request, "prediction": prediction}
return templates.TemplateResponse("pages/account_search.html", response)
from urllib.parse import urlencode

from bot_detector.website.core.config import BD_API, templates
from fastapi import APIRouter, Request
from fastapi.responses import RedirectResponse, Response

router = APIRouter()


@router.get("/account-search")
async def get_account_search(request: Request, name: str = "") -> Response:
stripped = name.strip()
if name != stripped:
url = "/account-search"
if stripped:
url = f"{url}?{urlencode({'name': stripped})}"
return RedirectResponse(url=url, status_code=303)
predictions: list = []
if stripped:
predictions = await BD_API.get_prediction(name=stripped)
response = {"request": request, "predictions": predictions, "name": stripped}
return templates.TemplateResponse("pages/account_search.html", response)
66 changes: 26 additions & 40 deletions bases/bot_detector/website/app/controllers/bot_detector.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
import aiohttp


class BotDetector:
def __init__(
self, token: str, base_url: str = "https://api.prd.osrsbotdetector.com"
):
self.base_url = base_url
self.session = aiohttp.ClientSession()
self.token = token

async def get_prediction(self, name: str):
url = f"{self.base_url}/v1/prediction?name={name}"
async with self.session.get(url) as response:
data = await response.json()
return data

async def get_xp_change(self, player_id: str):
url = f"{self.base_url}/v1/hiscore/XPChange?token={self.token}&player_id={player_id}"
async with self.session.get(url) as response:
data = await response.json()
return data

async def get_highscore_latest(self, player_id: str):
url = f"{self.base_url}/v1/hiscore/Latest?token={self.token}&player_id={player_id}"
async with self.session.get(url) as response:
data = await response.json()
return data

async def get_player(self, player_name: str):
url = f"{self.base_url}/v1/player?token={self.token}&player_name={player_name}"
async with self.session.get(url) as response:
data = await response.json()
return data

async def get_project_stats(self):
url = f"{self.base_url}/site/dashboard/projectstats"
async with self.session.get(url) as response:
data = await response.json()
return data
import aiohttp


class BotDetector:
def __init__(
self, token: str, base_url: str = "https://api.prd.osrsbotdetector.com"
):
self.base_url = base_url
self.session = aiohttp.ClientSession()
self.token = token

async def get_prediction(self, name: str) -> list:
url = f"{self.base_url}/v2/player/prediction"
params = {"name": name, "breakdown": "true"}
async with self.session.get(url, params=params) as response:
if response.status == 404:
return []
response.raise_for_status()
data: list = await response.json()
return data

async def get_project_stats(self):
url = f"{self.base_url}/site/dashboard/projectstats"
async with self.session.get(url) as response:
data = await response.json()
return data
6 changes: 3 additions & 3 deletions bases/bot_detector/website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
rel="stylesheet">

<!-- Custom stylesheets for the application -->
<link rel="stylesheet" href="static/boot.botdetector.css">
<link rel="stylesheet" href="static/core.botdetector.css">
<link rel="stylesheet" href="static/ember.botdetector.css">
<link rel="stylesheet" href="{{ url_for('static', path='boot.botdetector.css') }}">
<link rel="stylesheet" href="{{ url_for('static', path='core.botdetector.css') }}">
<link rel="stylesheet" href="{{ url_for('static', path='ember.botdetector.css') }}">
</head>

<body>
Expand Down
6 changes: 3 additions & 3 deletions bases/bot_detector/website/templates/head.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% block head %}
<!-- Include custom scripts -->
<script src="/static/scripts.js"></script>
<script src="{{ url_for('static', path='scripts.js') }}"></script>

<!-- Include Bootstrap JavaScript dependencies -->
<script src="/static/popper.min.js"></script>
<script src="/static/bootstrap.min.js"></script>
<script src="{{ url_for('static', path='popper.min.js') }}"></script>
<script src="{{ url_for('static', path='bootstrap.min.js') }}"></script>
{% endblock %}
Loading
Loading