Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Jan 10, 2025
1 parent e5d0ea3 commit ec0f4f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion bots/aiocqhttp/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ async def message_handler(event: Event):
if event.message[0]["type"] == "at":
if event.message[0]["data"]["qq"] == str(qq_account):
event.message = event.message[1:]
if not event.message:
if not event.message or \
event.message[0]["type"] == "text" and event.message[0]["data"]["text"] == ' ':
event.message = [{"type": "text", "data": {"text": f"{command_prefix[0]}help"}}]
prefix = command_prefix
else:
Expand Down
8 changes: 4 additions & 4 deletions bots/web/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import time
from multiprocessing import Process
import uvicorn

sys.path.append(os.getcwd())

Expand All @@ -20,9 +21,8 @@


def run_fastapi():
import uvicorn
from bots.web.api import app as fastapi_app
while True:
from bots.web.api import app as fastapi_app # noqa: E402
Info.client_name = client_name
uvicorn.run(fastapi_app, port=API_PORT, log_level="info")
Logger.error("API Server crashed, is the port occupied?")
Expand All @@ -31,8 +31,8 @@ def run_fastapi():


def run_flask():
if os.path.exists(webui_path):
from bots.web.webui import app as flask_app, generate_config
from bots.web.webui import generate_config, app as flask_app # noqa: E402
if os.path.exists(os.path.join(webui_path, "index.html")):
generate_config()
Logger.info(f"Visit AkariBot WebUI: http://127.0.0.1:{WEBUI_PORT}")
flask_app.run(port=WEBUI_PORT)
Expand Down
9 changes: 4 additions & 5 deletions bots/web/webui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
import time
from flask import Flask, redirect, send_from_directory, url_for
from urllib.parse import urlparse

Expand All @@ -14,11 +13,11 @@
from core.logger import Logger # noqa: E402


if os.path.exists(webui_path):
if os.path.exists(os.path.join(webui_path, "index.html")):

def generate_config():
webui_config_path = os.path.join(webui_path, "config.json")
if os.path.exists(webui_config_path):
if os.path.exists(webui_path):
with open(webui_config_path, "wb") as f:
f.write(json.dumps({"api_url": f"http://127.0.0.1:{API_PORT}"}))

Expand All @@ -41,7 +40,6 @@ def static_files(path):
@app.route("/api/<path:path>")
def api_redirect(path=None):
if path:
from urllib.parse import urlparse
parsed_path = urlparse(path)
if not parsed_path.netloc and not parsed_path.scheme:
return redirect(f"http://127.0.0.1:{API_PORT}/api/{path}")
Expand All @@ -50,7 +48,8 @@ def api_redirect(path=None):
else:
return redirect(f"http://127.0.0.1:{API_PORT}/api")

if __name__ == "__main__" and Config("enable", True, table_name="bot_web") and os.path.exists(webui_path):
if __name__ == "__main__" and Config("enable", True, table_name="bot_web") and \
os.path.exists(os.path.join(webui_path, "index.html")):
generate_config()
Logger.info(f"Visit AkariBot WebUI: http://127.0.0.1:{WEBUI_PORT}")
app.run(port=WEBUI_PORT)
Expand Down

0 comments on commit ec0f4f8

Please sign in to comment.