精确描述每个渠道的能力层次
核心修改: - GitHub: 零配置=公开仓库可读可搜,配置 gh/token 后=Fork、Issue、PR、Review 全部可用 - Reddit: 三层能力——Exa 搜索(免费)→代理读帖子→OAuth Bot 高级操作(发帖等) - 小红书: 必须配 Cookie,没有降级方案,明确说明 - B站: 本地可用/服务器需代理,区分清楚 - Twitter: 零配置可读推文,birdx+Cookie 解锁搜索发推 每个渠道的 check() 方法都改为自定义逻辑,精确反映当前环境的实际能力。
This commit is contained in:
@@ -27,10 +27,12 @@ class GitHubChannel(Channel):
|
||||
return h
|
||||
|
||||
def check(self, config=None):
|
||||
import shutil
|
||||
token = config.get("github_token") if config else None
|
||||
if token:
|
||||
return "ok", "已认证,可访问私有仓库"
|
||||
return "ok", "公开仓库可用。配置 github_token 可访问私有仓库"
|
||||
has_gh = shutil.which("gh")
|
||||
if token or has_gh:
|
||||
return "ok", "完整可用(读取、搜索、Fork、Issue、PR 等)"
|
||||
return "ok", "公开仓库可读可搜。配置 gh CLI 或 github_token 可解锁 Fork、Issue、PR 等操作"
|
||||
|
||||
def can_handle(self, url: str) -> bool:
|
||||
domain = urlparse(url).netloc.lower()
|
||||
|
||||
@@ -5,6 +5,7 @@ Backend: Reddit public JSON API (append .json to any URL)
|
||||
Swap to: any Reddit access method
|
||||
"""
|
||||
|
||||
import os
|
||||
import requests
|
||||
from urllib.parse import urlparse
|
||||
from .base import Channel, ReadResult
|
||||
@@ -14,7 +15,6 @@ class RedditChannel(Channel):
|
||||
name = "reddit"
|
||||
description = "Reddit 帖子和评论"
|
||||
backends = ["Reddit JSON API"]
|
||||
requires_config = ["reddit_proxy"]
|
||||
tier = 2
|
||||
|
||||
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"
|
||||
@@ -23,6 +23,18 @@ class RedditChannel(Channel):
|
||||
domain = urlparse(url).netloc.lower()
|
||||
return "reddit.com" in domain or "redd.it" in domain
|
||||
|
||||
def check(self, config=None):
|
||||
proxy = config.get("reddit_proxy") if config else None
|
||||
has_bot = bool(os.environ.get("REDDIT_CLIENT_ID"))
|
||||
if proxy and has_bot:
|
||||
return "ok", "完整可用(代理 + OAuth Bot)"
|
||||
elif proxy:
|
||||
return "ok", "代理已配置,可读取帖子。配置 REDDIT_CLIENT_ID/SECRET 可解锁高级搜索和发帖"
|
||||
elif has_bot:
|
||||
return "warn", "OAuth Bot 已配置,但服务器直连可能被封。配个代理更稳定:agent-eyes configure proxy URL"
|
||||
else:
|
||||
return "off", "搜索用 Exa 免费可用。读帖子需配个代理:agent-eyes configure proxy URL"
|
||||
|
||||
async def read(self, url: str, config=None) -> ReadResult:
|
||||
proxy = config.get("reddit_proxy") if config else None
|
||||
proxies = {"http": proxy, "https": proxy} if proxy else None
|
||||
|
||||
@@ -16,13 +16,18 @@ class XiaoHongShuChannel(Channel):
|
||||
name = "xiaohongshu"
|
||||
description = "小红书笔记"
|
||||
backends = ["XHS Web API"]
|
||||
requires_config = ["xhs_cookie"]
|
||||
tier = 2
|
||||
|
||||
def can_handle(self, url: str) -> bool:
|
||||
domain = urlparse(url).netloc.lower()
|
||||
return "xiaohongshu.com" in domain or "xhslink.com" in domain
|
||||
|
||||
def check(self, config=None):
|
||||
cookie = config.get("xhs_cookie") if config else None
|
||||
if cookie:
|
||||
return "ok", "Cookie 已配置,完整可用"
|
||||
return "off", "需要配置 Cookie 才能访问。导入浏览器 Cookie 即可:agent-eyes configure --from-browser chrome"
|
||||
|
||||
async def read(self, url: str, config=None) -> ReadResult:
|
||||
cookie = config.get("xhs_cookie") if config else None
|
||||
|
||||
|
||||
@@ -64,14 +64,10 @@ def format_report(results: Dict[str, dict]) -> str:
|
||||
for key, r in tier2.items():
|
||||
if r["status"] == "ok":
|
||||
lines.append(f" ✅ {r['name']} — {r['message']}")
|
||||
elif r["status"] == "warn":
|
||||
lines.append(f" ⚠️ {r['name']} — {r['message']}")
|
||||
else:
|
||||
# Friendly message about what to configure
|
||||
if "proxy" in str(r.get("message", "")):
|
||||
lines.append(f" ⬜ {r['name']} — 配个代理就能用:agent-eyes configure proxy URL")
|
||||
elif "cookie" in str(r.get("message", "")):
|
||||
lines.append(f" ⬜ {r['name']} — 导入浏览器 Cookie 就能用:agent-eyes configure --from-browser chrome")
|
||||
else:
|
||||
lines.append(f" ⬜ {r['name']} — {r['message']}")
|
||||
lines.append(f" ⬜ {r['name']} — {r['message']}")
|
||||
|
||||
lines.append("")
|
||||
lines.append(f"状态:{ok_count}/{total} 个渠道可用")
|
||||
|
||||
Reference in New Issue
Block a user