mirror of
https://github.com/stijndcl/didier.git
synced 2026-06-29 17:39:57 +02:00
Restructure backend
This commit is contained in:
parent
16f8fedd16
commit
6ba104758b
16 changed files with 108 additions and 42 deletions
0
backend/routes/__init__.py
Normal file
0
backend/routes/__init__.py
Normal file
1
backend/routes/dm/__init__.py
Normal file
1
backend/routes/dm/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .dm_route import dm_blueprint
|
||||
21
backend/routes/dm/dm_route.py
Normal file
21
backend/routes/dm/dm_route.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from backend.ipc_client import ipc_client
|
||||
import json
|
||||
from quart import Blueprint, request, jsonify
|
||||
|
||||
dm_blueprint: Blueprint = Blueprint("dm", __name__, url_prefix="/dm")
|
||||
|
||||
|
||||
@dm_blueprint.route("/", methods=["POST"])
|
||||
async def post_dm():
|
||||
"""
|
||||
Send a DM to the given user
|
||||
"""
|
||||
data = json.loads((await request.body).decode('UTF-8'))
|
||||
|
||||
dm = await ipc_client.request(
|
||||
"send_dm",
|
||||
user=int(data["userid"]),
|
||||
message=data.get("message")
|
||||
)
|
||||
|
||||
return jsonify({"response": dm})
|
||||
1
backend/routes/ping/__init__.py
Normal file
1
backend/routes/ping/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .ping_route import ping_blueprint
|
||||
15
backend/routes/ping/ping_route.py
Normal file
15
backend/routes/ping/ping_route.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from backend.ipc_client import ipc_client
|
||||
from quart import Blueprint, jsonify
|
||||
from time import time
|
||||
|
||||
ping_blueprint: Blueprint = Blueprint("ping", __name__, url_prefix="/ping")
|
||||
|
||||
|
||||
@ping_blueprint.route("/", methods=["GET"])
|
||||
async def get_ping():
|
||||
"""
|
||||
Send a ping request, monitors bot latency and endpoint time
|
||||
"""
|
||||
latency = await ipc_client.request("get_bot_latency")
|
||||
|
||||
return jsonify({"bot_latency": latency, "response_sent": time()})
|
||||
1
backend/routes/stats/__init__.py
Normal file
1
backend/routes/stats/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .stats_route import stats_blueprint
|
||||
1
backend/routes/stats/command_stats/__init__.py
Normal file
1
backend/routes/stats/command_stats/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .command_stats_route import command_stats_blueprint
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
from quart import Blueprint
|
||||
|
||||
command_stats_blueprint: Blueprint = Blueprint("command_stats", __name__, "/commands")
|
||||
|
||||
|
||||
@command_stats_blueprint.route("/", methods=["GET"])
|
||||
def get_commands():
|
||||
return {}, 200
|
||||
14
backend/routes/stats/stats_route.py
Normal file
14
backend/routes/stats/stats_route.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from .command_stats import command_stats_blueprint
|
||||
from quart import Blueprint
|
||||
|
||||
stats_blueprint: Blueprint = Blueprint("stats", __name__, url_prefix="/stats")
|
||||
stats_blueprint.register_blueprint(command_stats_blueprint)
|
||||
|
||||
|
||||
@stats_blueprint.route("/", methods=["GET"])
|
||||
def get_nested_routes():
|
||||
nested_routes = {
|
||||
"commands": "/stats/commands"
|
||||
|
||||
}
|
||||
return {"nested": nested_routes}, 200
|
||||
Loading…
Add table
Add a link
Reference in a new issue