From b5eaf0283065673389ecf997541d217cf7fc7541 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sun, 6 Sep 2020 16:26:49 +0800 Subject: [Update] --- ATRI/modules/error/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ATRI/modules/error/__init__.py (limited to 'ATRI/modules/error/__init__.py') diff --git a/ATRI/modules/error/__init__.py b/ATRI/modules/error/__init__.py new file mode 100644 index 0000000..0f69608 --- /dev/null +++ b/ATRI/modules/error/__init__.py @@ -0,0 +1,36 @@ +import json +import string +from pathlib import Path +from random import sample +from traceback import format_exc +from datetime import datetime +from typing import Optional + + +def errorBack(Lmsg: Optional[str] = None): + try: + with open(Path('.') / 'ATRI' / 'data' / 'errorData' / 'errorData.json', 'r') as f: + data = json.load(f) + except: + data = {} + + ran_str = ''.join(sample(string.ascii_letters + string.digits, 8)) + msg0 = f"{datetime.now()}\n" + msg0 += f"{format_exc()}" + data[f"{ran_str}"] = f"{msg0}" + + with open(Path('.') / 'ATRI' / 'data' / 'errorData' / 'errorData.json', 'w') as f: + f.write(json.dumps(data)) + f.close() + + if Lmsg: + pass + else: + Lmsg = 'unknown' + + msg0 = f'ERROR! Reason: [{Lmsg}]\n' + msg0 += f'trackID: {ran_str}\n' + msg0 += "请使用[来杯红茶]功能以联系维护者\n" + msg0 += "并附上 trackID" + + return msg0 \ No newline at end of file -- cgit v1.2.3