From ca89fa7efdd77dbe017af58ae0be0b198c463186 Mon Sep 17 00:00:00 2001 From: snowy Date: Sat, 24 Aug 2024 21:19:51 +0800 Subject: [PATCH] =?UTF-8?q?:arrow=5Fdown:=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BE=9D=E8=B5=96=E9=97=AE=E9=A2=98=EF=BC=8C=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E8=AF=B7=E5=8B=BF=E4=BD=BF=E7=94=A8=E6=B8=85=E5=8D=8E?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E6=BA=90=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 60 ++++++------ src/liteyuki_main/loader.py | 6 +- .../liteyuki_uniblacklist/api.py | 1 - src/utils/__init__.py | 44 +-------- src/utils/base/ly_api.py | 91 ------------------- 5 files changed, 28 insertions(+), 174 deletions(-) delete mode 100644 src/utils/base/ly_api.py diff --git a/requirements.txt b/requirements.txt index bb3690a4..2a219ab8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,36 +1,28 @@ -aiohttp~=3.9.3 -aiofiles~=23.2.1 -colored~=2.2.4 -GitPython~=3.1.42 -httpx~=0.27.0 -nb-cli~=1.4.1 -nonebot2[fastapi,httpx,websockets]~=2.3.3 -nonebot-adapter-onebot~=2.4.3 -nonebot-plugin-alconna~=0.46.3 -nonebot_plugin_apscheduler~=0.4.0 -nonebot-adapter-satori~=0.11.5 -liteyukibot-plugin-htmlrender~=0.1.0 -pyppeteer~=2.0.0 +aiohttp>=3.9.3 +aiofiles>=23.2.1 +colored>=2.2.4 +GitPython>=3.1.43 +httpx>=0.27.0 +liteyukibot-plugin-htmlrender>=0.1.0 +nonebot2[fastapi,httpx,websockets]>=2.3.3 +nonebot-adapter-onebot>=2.4.3 +nonebot-plugin-alconna>=0.46.3 +nonebot_plugin_apscheduler>=0.4.0 +nonebot-adapter-satori>=0.11.5 +pyppeteer>=2.0.0 markdown>=3.3.6 zhDateTime>=1.0.3 -numpy<2.0.0 -packaging~=23.1 -psutil~=5.9.8 -py-cpuinfo~=9.0.0 -pydantic~=2.7.0 -Pygments~=2.17.2 -pyppeteer~=2.0.0 -pytz~=2024.1 -PyYAML~=6.0.1 -pillow~=10.0.0 -pdm-backend~=2.3.3 -starlette~=0.36.3 -toml~=0.10.2 -loguru~=0.7.2 -importlib_metadata~=7.0.2 -requests~=2.31.0 -watchdog~=4.0.0 -jieba~=0.42.1 -aiosqlite3~=0.3.0 -fastapi~=0.110.0 -python-dotenv~=1.0.1 \ No newline at end of file +numpy>=2.1.0 +packaging>=23.1 +psutil>=5.9.8 +py-cpuinfo>=9.0.0 +Pygments>=2.17.2 +pyppeteer>=2.0.0 +pytz>=2024.1 +PyYAML>=6.0.1 +pillow>=10.0.0 +toml>=0.10.2 +importlib_metadata>=7.0.2 +watchdog>=4.0.0 +jieba>=0.42.1 +python-dotenv>=1.0.1 \ No newline at end of file diff --git a/src/liteyuki_main/loader.py b/src/liteyuki_main/loader.py index e86ce88b..41b6a591 100644 --- a/src/liteyuki_main/loader.py +++ b/src/liteyuki_main/loader.py @@ -8,10 +8,6 @@ from src.utils.base.data_manager import InstalledPlugin, plugin_db from src.utils.base.resource import load_resources from src.utils.message.tools import check_for_package -from liteyuki import get_bot - -from nonebot_plugin_apscheduler import scheduler - load_resources() init_log() @@ -29,7 +25,7 @@ async def load_plugins(): for installed_plugin in installed_plugins: if not check_for_package(installed_plugin.module_name): nonebot.logger.error( - f"{installed_plugin.module_name} not installed, but in loading database. please run `npm fixup` in chat to reinstall it.") + f"{installed_plugin.module_name} not installed, but still in loader index.") else: nonebot.load_plugin(installed_plugin.module_name) nonebot.plugin.load_plugins("plugins") diff --git a/src/nonebot_plugins/liteyuki_uniblacklist/api.py b/src/nonebot_plugins/liteyuki_uniblacklist/api.py index 52ca276c..0e631844 100644 --- a/src/nonebot_plugins/liteyuki_uniblacklist/api.py +++ b/src/nonebot_plugins/liteyuki_uniblacklist/api.py @@ -1,7 +1,6 @@ import datetime import aiohttp -import httpx import nonebot from nonebot import require from nonebot.exception import IgnoredException diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 83d44906..50886ac1 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,50 +1,18 @@ -import json -import os.path -import platform import sys -import time import nonebot __NAME__ = "LiteyukiBot" __VERSION__ = "6.3.2" # 60201 -import requests - from src.utils.base.config import load_from_yaml, config from src.utils.base.log import init_log from git import Repo - major, minor, patch = map(int, __VERSION__.split(".")) __VERSION_I__ = major * 10000 + minor * 100 + patch -def register_bot(): - url = "https://api.liteyuki.icu/register" - data = { - "name" : __NAME__, - "version" : __VERSION__, - "version_i": __VERSION_I__, - "python" : f"{platform.python_implementation()} {platform.python_version()}", - "os" : f"{platform.system()} {platform.version()} {platform.machine()}" - } - try: - nonebot.logger.info("Waiting for register to Liteyuki...") - resp = requests.post(url, json=data, timeout=(10, 15)) - if resp.status_code == 200: - data = resp.json() - if liteyuki_id := data.get("liteyuki_id"): - with open("data/liteyuki/liteyuki.json", "wb") as f: - f.write(json.dumps(data).encode("utf-8")) - nonebot.logger.success(f"Register {liteyuki_id} to Liteyuki successfully") - else: - raise ValueError(f"Register to Liteyuki failed: {data}") - - except Exception as e: - nonebot.logger.warning(f"Register to Liteyuki failed, but it's no matter: {e}") - - def init(): """ 初始化 @@ -67,18 +35,8 @@ def init(): # temp_data.data["start_time"] = time.time() # common_db.save(temp_data) - # 在加载完成语言后再初始化日志 - nonebot.logger.info("Liteyuki is initializing...") - - if not os.path.exists("data/liteyuki/liteyuki.json"): - register_bot() - - if not os.path.exists("pyproject.toml"): - with open("pyproject.toml", "w", encoding="utf-8") as f: - f.write("[tool.nonebot]\n") - nonebot.logger.info( - f"Run Liteyuki with Python{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} " + f"Run Liteyuki-NoneBot with Python{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} " f"at {sys.executable}" ) nonebot.logger.info(f"{__NAME__} {__VERSION__}({__VERSION_I__}) is running") diff --git a/src/utils/base/ly_api.py b/src/utils/base/ly_api.py deleted file mode 100644 index 81e45684..00000000 --- a/src/utils/base/ly_api.py +++ /dev/null @@ -1,91 +0,0 @@ -import json -import os.path -import platform - -import aiohttp -import nonebot -import psutil -import requests - -from .config import load_from_yaml -from .. import __NAME__, __VERSION_I__, __VERSION__ - - -class LiteyukiAPI: - def __init__(self): - self.liteyuki_id = None - if os.path.exists("data/liteyuki/liteyuki.json"): - with open("data/liteyuki/liteyuki.json", "rb") as f: - self.data = json.loads(f.read()) - self.liteyuki_id = self.data.get("liteyuki_id") - self.report = load_from_yaml("config.yml").get("auto_report", True) - - if self.report: - nonebot.logger.info("Auto report enabled") - - @property - def device_info(self) -> dict: - """ - 获取设备信息 - Returns: - - """ - return { - "name" : __NAME__, - "version" : __VERSION__, - "version_i" : __VERSION_I__, - "python" : f"{platform.python_implementation()} {platform.python_version()}", - "os" : f"{platform.system()} {platform.version()} {platform.machine()}", - "cpu" : f"{psutil.cpu_count(logical=False)}c{psutil.cpu_count()}t{psutil.cpu_freq().current}MHz", - "memory_total": f"{psutil.virtual_memory().total / 1024 ** 3:.2f}GB", - "memory_used" : f"{psutil.virtual_memory().used / 1024 ** 3:.2f}GB", - "memory_bot" : f"{psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2:.2f}MB", - "disk" : f"{psutil.disk_usage('/').total / 1024 ** 3:.2f}GB" - } - - def bug_report(self, content: str): - """ - 提交bug报告 - Args: - content: - - Returns: - - """ - if self.report: - nonebot.logger.warning(f"Reporting bug...: {content}") - url = "https://api.liteyuki.icu/bug_report" - data = { - "liteyuki_id": self.liteyuki_id, - "content" : content, - "device_info": self.device_info - } - resp = requests.post(url, json=data) - if resp.status_code == 200: - nonebot.logger.success(f"Bug report sent successfully, report_id: {resp.json().get('report_id')}") - else: - nonebot.logger.error(f"Bug report failed: {resp.text}") - else: - nonebot.logger.warning(f"Bug report is disabled: {content}") - - def register(self): - pass - - - async def heartbeat_report(self): - """ - 提交心跳,预留接口 - Returns: - - """ - url = "https://api.liteyuki.icu/heartbeat" - data = { - "liteyuki_id": self.liteyuki_id, - "version" : __VERSION__, - } - async with aiohttp.ClientSession() as session: - async with session.post(url, json=data) as resp: - if resp.status == 200: - nonebot.logger.success("Heartbeat sent successfully") - else: - nonebot.logger.error(f"Heartbeat failed: {await resp.text()}") \ No newline at end of file