From beb6f63199c867e81febff6b4bfdddeea2ca7557 Mon Sep 17 00:00:00 2001 From: snowy Date: Sun, 24 Mar 2024 19:57:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E5=90=91=E8=BD=BB?= =?UTF-8?q?=E9=9B=AA=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=8A=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- liteyuki/liteyuki_main/__init__.py | 3 ++ liteyuki/utils/__init__.py | 4 +- liteyuki/utils/liteyuki_api.py | 70 ++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 liteyuki/utils/liteyuki_api.py diff --git a/README.md b/README.md index 815513b..9a37a58 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ port: 20216 # 绑定端口 nickname: [ "liteyuki" ] # 机器人昵称 superusers: [ "1919810" ] # 超级用户 show_icon: true # 是否显示日志等级图标(某些控制台不可用) +auto_report: true # 是否自动上报设备信息给轻雪服务器,该信息仅包含设备型号和系统版本 # 下面是不建议修改,且默认没有列出的配置项,除非你有特殊需求 log_level: "INFO" # 日志等级 @@ -104,7 +105,7 @@ custom_config_1: "custom_value1" ## 用户协议 1. 本项目遵循`MIT`协议,你可以自由使用,修改,分发,但是请保留原作者信息 -2. 轻雪会收集使用者的设备信息,通过安全的方式传输到服务器,用于统计用户数量和设备信息,进行优化 +2. 轻雪会收集使用者的设备信息,通过安全的方式传输到轻雪服务器,用于统计运行时的设备信息,帮助我们改进轻雪 3. 本项目不会收集用户的任何隐私信息,但请注意甄别第三方插件的安全性 ## 鸣谢 diff --git a/liteyuki/liteyuki_main/__init__.py b/liteyuki/liteyuki_main/__init__.py index b996ff8..ac73e0f 100644 --- a/liteyuki/liteyuki_main/__init__.py +++ b/liteyuki/liteyuki_main/__init__.py @@ -6,6 +6,9 @@ from .loader import * from .webdash import * from .core import * from liteyuki.utils.config import config +from liteyuki.utils.liteyuki_api import liteyuki_api + +liteyuki_api.bug_report("test") __author__ = "snowykami" __plugin_meta__ = PluginMetadata( diff --git a/liteyuki/utils/__init__.py b/liteyuki/utils/__init__.py index 67724e3..b4b773e 100644 --- a/liteyuki/utils/__init__.py +++ b/liteyuki/utils/__init__.py @@ -1,15 +1,13 @@ import json import os.path import platform +import sys import nonebot -import sys -import pickle __NAME__ = "LiteyukiBot" __VERSION__ = "6.2.4" # 60201 -import psutil import requests from liteyuki.utils.config import load_from_yaml diff --git a/liteyuki/utils/liteyuki_api.py b/liteyuki/utils/liteyuki_api.py new file mode 100644 index 0000000..b12bedd --- /dev/null +++ b/liteyuki/utils/liteyuki_api.py @@ -0,0 +1,70 @@ +import json +import os.path +import platform + +import nonebot +import psutil +import requests + +from . import __VERSION_I__, __VERSION__, __NAME__ +from .config import config + + +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 = config.get("auto_report", True) + if self.report: + nonebot.logger.info("Auto bug report is 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 / 1024 / 1024:.2f}GB", + "memory_used" : f"{psutil.virtual_memory().used / 1024 / 1024 / 1024:.2f}GB", + "memory_bot" : f"{psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024:.2f}MB", + "disk" : f"{psutil.disk_usage('/').total / 1024 / 1024 / 1024:.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}") + + +liteyuki_api = LiteyukiAPI()