Update main.py

This commit is contained in:
谢幕 2025-07-18 21:18:13 +08:00 committed by GitHub
parent f995f86419
commit 6dc75cd4ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

19
main.py
View File

@ -15,6 +15,7 @@ SUBSCRIPTION_FILE = "data/astrbot_plugin_github_sub_subscriptions.json"
# 默认仓库数据存储路径
DEFAULT_REPO_FILE = "data/astrbot_plugin_github_sub_default_repos.json"
GITHUB_URL_PATTERN = r"https://github\.com/[\w\-]+/[\w\-]+(?:/(pull|issues)/\d+)?"
GITHUB_API_URL = "https://api.github.com/repos/{repo}"
GITHUB_ISSUES_API_URL = "https://api.github.com/repos/{repo}/issues"
@ -92,6 +93,24 @@ class MyPlugin(Star):
headers["Authorization"] = f"token {self.github_token}"
return headers
@filter.regex(GITHUB_URL_PATTERN)
async def github_repo(self, event: AstrMessageEvent):
"""解析 Github 仓库信息"""
msg = event.message_str
match = re.search(GITHUB_URL_PATTERN, msg)
repo_url = match.group(0)
repo_url = repo_url.replace("https://github.com/", "")
hash_value = uuid.uuid4().hex
opengraph_url = GITHUB_REPO_OPENGRAPH.format(hash=hash_value, appendix=repo_url)
logger.info(f"生成的 OpenGraph URL: {opengraph_url}")
try:
yield event.image_result(opengraph_url)
except Exception as e:
logger.error(f"下载图片失败: {e}")
yield event.plain_result("下载 GitHub 图片失败: " + str(e))
return
@filter.command("ghsub")
async def subscribe_repo(self, event: AstrMessageEvent, repo: str):
"""订阅GitHub仓库的Issue和PR。例如: /ghsub Soulter/AstrBot"""