Update app.py
Browse files
app.py
CHANGED
@@ -524,38 +524,46 @@ async def unbanUser(chatId, userId):
|
|
524 |
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
525 |
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
def webdav_upload(filename, data):
|
528 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
529 |
-
headers = {'Content-Type': 'application/json'}
|
530 |
|
531 |
try:
|
532 |
#尝试创建目录
|
533 |
dir_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}")
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
print(f"WebDAV 目录已存在: {WEBDAV_DIR}")
|
539 |
-
|
540 |
-
|
|
|
541 |
|
542 |
-
|
543 |
-
|
544 |
-
|
|
|
545 |
print(f"WebDAV 上传成功: {filename}")
|
546 |
-
|
547 |
-
|
548 |
-
print(f"WebDAV 上传失败: {filename}, {e}")
|
549 |
|
550 |
def webdav_download(filename):
|
551 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
552 |
try:
|
553 |
-
|
554 |
-
response.raise_for_status()
|
555 |
print(f"WebDAV 下载成功: {filename}")
|
556 |
-
|
557 |
-
|
558 |
-
|
|
|
|
|
|
|
559 |
return None
|
560 |
|
561 |
def sync_data_to_webdav():
|
@@ -570,7 +578,7 @@ def sync_data_to_webdav():
|
|
570 |
webdav_upload('BANNED_USERS.json', BANNED_USERS)
|
571 |
except Exception as e:
|
572 |
print(f"WebDAV 同步失败: {e}")
|
573 |
-
time.sleep(
|
574 |
|
575 |
def load_data_from_webdav():
|
576 |
global chatHistories, GROUP_SETTINGS, USER_SETTINGS, USER_LAST_ACTIVE, GROUP_ACTIVE_USERS, GROUP_INFO, BANNED_USERS
|
|
|
524 |
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
525 |
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
526 |
|
527 |
+
async def unbanUser(chatId, userId):
|
528 |
+
if userId in BANNED_USERS:
|
529 |
+
del BANNED_USERS[userId]
|
530 |
+
await sendTelegramMessage(chatId, f"用户 {userId} 已被解禁。")
|
531 |
+
print(f"用户 {userId} 在群组 {chatId} 中被解禁。")
|
532 |
+
|
533 |
def webdav_upload(filename, data):
|
534 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
|
|
535 |
|
536 |
try:
|
537 |
#尝试创建目录
|
538 |
dir_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}")
|
539 |
+
subprocess.run(['curl', '-X', 'MKCOL', '-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}', dir_url], check=True, capture_output=True)
|
540 |
+
print(f"WebDAV 目录创建成功: {WEBDAV_DIR}")
|
541 |
+
except subprocess.CalledProcessError as e:
|
542 |
+
if b'405' in e.stderr:
|
543 |
print(f"WebDAV 目录已存在: {WEBDAV_DIR}")
|
544 |
+
else:
|
545 |
+
print(f"WebDAV 目录创建失败: {WEBDAV_DIR}, {e.stderr.decode()}")
|
546 |
+
return
|
547 |
|
548 |
+
try:
|
549 |
+
# 上传文件
|
550 |
+
json_data = json.dumps(data, default=str)
|
551 |
+
process = subprocess.run(['curl', '-X', 'PUT', '-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}', '-H', 'Content-Type: application/json', '--data', json_data, url], check=True, capture_output=True)
|
552 |
print(f"WebDAV 上传成功: {filename}")
|
553 |
+
except subprocess.CalledProcessError as e:
|
554 |
+
print(f"WebDAV 上传失败: {filename}, {e.stderr.decode()}")
|
|
|
555 |
|
556 |
def webdav_download(filename):
|
557 |
url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}")
|
558 |
try:
|
559 |
+
process = subprocess.run(['curl', '-u', f'{WEBDAV_USERNAME}:{WEBDAV_PASSWORD}', '-H', 'Accept: application/json', url], capture_output=True, check=True)
|
|
|
560 |
print(f"WebDAV 下载成功: {filename}")
|
561 |
+
if process.stdout:
|
562 |
+
return json.loads(process.stdout.decode())
|
563 |
+
else:
|
564 |
+
return None
|
565 |
+
except subprocess.CalledProcessError as e:
|
566 |
+
print(f"WebDAV 下载失败: {filename}, {e.stderr.decode()}")
|
567 |
return None
|
568 |
|
569 |
def sync_data_to_webdav():
|
|
|
578 |
webdav_upload('BANNED_USERS.json', BANNED_USERS)
|
579 |
except Exception as e:
|
580 |
print(f"WebDAV 同步失败: {e}")
|
581 |
+
time.sleep(60)
|
582 |
|
583 |
def load_data_from_webdav():
|
584 |
global chatHistories, GROUP_SETTINGS, USER_SETTINGS, USER_LAST_ACTIVE, GROUP_ACTIVE_USERS, GROUP_INFO, BANNED_USERS
|