fix: 检测存活支持分组节点,分组节点不被自动清理误删
This commit is contained in:
37
bot.py
37
bot.py
@@ -175,14 +175,28 @@ async def cb_menu(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
elif action == 'menu_check':
|
elif action == 'menu_check':
|
||||||
msg = await send_del(q.message, '🔍 检测中...', delay=120)
|
msg = await send_del(q.message, '🔍 检测中...', delay=120)
|
||||||
results = []
|
results = []
|
||||||
for s in data['subs']:
|
# 检测默认分组
|
||||||
ok = await check_node(s['link'], s['type'])
|
if data['subs']:
|
||||||
s['alive'] = ok
|
results.append('📦 *默认分组*')
|
||||||
results.append(f"{'🟢' if ok else '🔴'} [{s['type']}] {s['name']}")
|
for s in data['subs']:
|
||||||
|
ok = await check_node(s['link'], s['type'])
|
||||||
|
s['alive'] = ok
|
||||||
|
results.append(f"{'🟢' if ok else '🔴'} [{s['type']}] {s['name']}")
|
||||||
|
# 检测所有订阅分组
|
||||||
|
for sg in data.get('sub_groups', []):
|
||||||
|
if not sg.get('nodes'): continue
|
||||||
|
results.append(f"\n📁 *{sg['name']}*")
|
||||||
|
for s in sg['nodes']:
|
||||||
|
ok = await check_node(s['link'], s['type'])
|
||||||
|
s['alive'] = ok
|
||||||
|
results.append(f"{'🟢' if ok else '🔴'} [{s['type']}] {s['name']}")
|
||||||
save_data(data)
|
save_data(data)
|
||||||
try: await msg.delete()
|
try: await msg.delete()
|
||||||
except: pass
|
except: pass
|
||||||
await send_del(q.message, '📊 *检测结果*\n\n' + '\n'.join(results), parse_mode='Markdown')
|
if not results:
|
||||||
|
await send_del(q.message, '📭 暂无订阅')
|
||||||
|
else:
|
||||||
|
await send_del(q.message, '📊 *检测结果*\n\n' + '\n'.join(results), parse_mode='Markdown')
|
||||||
|
|
||||||
elif action == 'menu_pick_multi':
|
elif action == 'menu_pick_multi':
|
||||||
alive = [s for s in data['subs'] if s.get('alive', True)]
|
alive = [s for s in data['subs'] if s.get('alive', True)]
|
||||||
@@ -763,11 +777,12 @@ async def cb_subgroups(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
async def auto_cleanup(bot_token):
|
async def auto_cleanup(bot_token):
|
||||||
"""Every 6h: check nodes, auto-delete dead ones, notify group"""
|
"""Every 6h: check nodes, auto-delete dead ones from default subs only, check group nodes but don't delete"""
|
||||||
import httpx
|
import httpx
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
while True:
|
while True:
|
||||||
data = load_data()
|
data = load_data()
|
||||||
|
# 默认分组:检测并删除不可用
|
||||||
if data['subs']:
|
if data['subs']:
|
||||||
dead = []
|
dead = []
|
||||||
for s in list(data['subs']):
|
for s in list(data['subs']):
|
||||||
@@ -786,6 +801,16 @@ async def auto_cleanup(bot_token):
|
|||||||
json={'chat_id': gid, 'text': msg})
|
json={'chat_id': gid, 'text': msg})
|
||||||
except: pass
|
except: pass
|
||||||
log.info(f'Auto cleanup: removed {len(dead)} dead nodes')
|
log.info(f'Auto cleanup: removed {len(dead)} dead nodes')
|
||||||
|
# 订阅分组:只更新存活状态,不删除
|
||||||
|
changed = False
|
||||||
|
for sg in data.get('sub_groups', []):
|
||||||
|
for s in sg.get('nodes', []):
|
||||||
|
ok = await check_node(s['link'], s['type'])
|
||||||
|
if s.get('alive', True) != ok:
|
||||||
|
s['alive'] = ok
|
||||||
|
changed = True
|
||||||
|
if changed:
|
||||||
|
save_data(data)
|
||||||
await asyncio.sleep(21600)
|
await asyncio.sleep(21600)
|
||||||
|
|
||||||
def run_cleanup():
|
def run_cleanup():
|
||||||
|
|||||||
Reference in New Issue
Block a user