mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-14 13:47:24 +08:00
feat: 自动向轻雪服务器上报错误信息
This commit is contained in:
parent
45f9afb73c
commit
beb6f63199
@ -63,6 +63,7 @@ port: 20216 # 绑定端口
|
|||||||
nickname: [ "liteyuki" ] # 机器人昵称
|
nickname: [ "liteyuki" ] # 机器人昵称
|
||||||
superusers: [ "1919810" ] # 超级用户
|
superusers: [ "1919810" ] # 超级用户
|
||||||
show_icon: true # 是否显示日志等级图标(某些控制台不可用)
|
show_icon: true # 是否显示日志等级图标(某些控制台不可用)
|
||||||
|
auto_report: true # 是否自动上报设备信息给轻雪服务器,该信息仅包含设备型号和系统版本
|
||||||
|
|
||||||
# 下面是不建议修改,且默认没有列出的配置项,除非你有特殊需求
|
# 下面是不建议修改,且默认没有列出的配置项,除非你有特殊需求
|
||||||
log_level: "INFO" # 日志等级
|
log_level: "INFO" # 日志等级
|
||||||
@ -104,7 +105,7 @@ custom_config_1: "custom_value1"
|
|||||||
|
|
||||||
## 用户协议
|
## 用户协议
|
||||||
1. 本项目遵循`MIT`协议,你可以自由使用,修改,分发,但是请保留原作者信息
|
1. 本项目遵循`MIT`协议,你可以自由使用,修改,分发,但是请保留原作者信息
|
||||||
2. 轻雪会收集使用者的设备信息,通过安全的方式传输到服务器,用于统计用户数量和设备信息,进行优化
|
2. 轻雪会收集使用者的设备信息,通过安全的方式传输到轻雪服务器,用于统计运行时的设备信息,帮助我们改进轻雪
|
||||||
3. 本项目不会收集用户的任何隐私信息,但请注意甄别第三方插件的安全性
|
3. 本项目不会收集用户的任何隐私信息,但请注意甄别第三方插件的安全性
|
||||||
|
|
||||||
## 鸣谢
|
## 鸣谢
|
||||||
|
@ -6,6 +6,9 @@ from .loader import *
|
|||||||
from .webdash import *
|
from .webdash import *
|
||||||
from .core import *
|
from .core import *
|
||||||
from liteyuki.utils.config import config
|
from liteyuki.utils.config import config
|
||||||
|
from liteyuki.utils.liteyuki_api import liteyuki_api
|
||||||
|
|
||||||
|
liteyuki_api.bug_report("test")
|
||||||
|
|
||||||
__author__ = "snowykami"
|
__author__ = "snowykami"
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import platform
|
import platform
|
||||||
|
import sys
|
||||||
|
|
||||||
import nonebot
|
import nonebot
|
||||||
import sys
|
|
||||||
import pickle
|
|
||||||
|
|
||||||
__NAME__ = "LiteyukiBot"
|
__NAME__ = "LiteyukiBot"
|
||||||
__VERSION__ = "6.2.4" # 60201
|
__VERSION__ = "6.2.4" # 60201
|
||||||
|
|
||||||
import psutil
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from liteyuki.utils.config import load_from_yaml
|
from liteyuki.utils.config import load_from_yaml
|
||||||
|
70
liteyuki/utils/liteyuki_api.py
Normal file
70
liteyuki/utils/liteyuki_api.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user