From 635e548a0a25e81dd804ac6d8f73aefc1ac14035 Mon Sep 17 00:00:00 2001 From: wling <90316914+wling-art@users.noreply.github.com> Date: Thu, 11 Jan 2024 05:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=E6=8F=92=E4=BB=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BB=A5=E5=8F=8A=E8=AF=8D=E4=BA=91=E6=8E=92=E9=99=A4?= =?UTF-8?q?qq=E7=AE=A1=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨Add wordcloud_exclude_user_ids to .env file * 🚀 更新githubcard --- .env | 2 +- .github/workflows/main.yml | 18 ------- .../nonebot_plugin_githubcard/__init__.py | 28 +++++++---- .../nonebot_plugin_githubcard/config.py | 1 + .../nonebot_plugin_githubcard/data_source.py | 48 +++++++++++-------- 5 files changed, 49 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.env b/.env index bd538df..08d3b08 100644 --- a/.env +++ b/.env @@ -32,9 +32,9 @@ ncm_admin_level=2 wordcloud_colormap=viridis wordcloud_background_color=black wordcloud_stopwords_path="./停用词.txt" +wordcloud_exclude_user_ids=["2854196310"] #45 wordcloud_userdict_path wordcloud_timezone - # chatrecorder 迁移所需的配置(QQ号) # https://github.com/noneplugin/nonebot-plugin-chatrecorder#chatrecorder_record_migration_bot_id CHATRECORDER_RECORD_MIGRATION_BOT_ID diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 09107cd..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Report Test Coverage - -on: [pull_request, push] - -jobs: - report_coverage: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Report test coverage to DeepSource - uses: deepsourcelabs/test-coverage-action@master - with: - key: python - coverage-file: coverage.xml - dsn: ${{ secrets.DEEPSOURCE_DSN }} - fail-ci-on-error: true # Optional: Set to true if you want the CI build to fail on error diff --git a/src/plugins/nonebot_plugin_githubcard/__init__.py b/src/plugins/nonebot_plugin_githubcard/__init__.py index 877db33..0d2f06a 100644 --- a/src/plugins/nonebot_plugin_githubcard/__init__.py +++ b/src/plugins/nonebot_plugin_githubcard/__init__.py @@ -1,22 +1,31 @@ from nonebot.rule import T_State from nonebot import get_driver +from nonebot.log import logger from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, MessageSegment from .config import Config from .data_source import get_github_reposity_information -from nonebot.plugin import on_regex -from nonebot.plugin import PluginMetadata +from nonebot.plugin import on_regex, PluginMetadata import re __plugin_meta__ = PluginMetadata( - name="github card", - description="展示github仓库卡片", - usage="github仓库卡片\n发出 github.com/用户名/仓库名 的格式即可自动检测") + name="githubcard", + description="检测GitHub仓库链接并自动发送卡片信息(适用于Onebot V11)", + usage='通过正则表达式检测Github链接', + type='application', + homepage='https://github.com/ElainaFanBoy/nonebot_plugin_githubcard', + supported_adapters={"~onebot.v11"}, + extra={ + "unique_name": "githubcard", + "author": "Nanako ", + "version": "0.2.1", + }, +) + global_config = get_driver().config config = Config(**global_config.dict()) -github = on_regex(r"https?://github\.com/([^/]+/[^/]+)", - priority=10, - block=False) +github = on_regex( + r"https?://github\.com/([^/]+/[^/]+)", priority=10, block=False) def match_link_parts(link): @@ -28,6 +37,5 @@ def match_link_parts(link): async def github_handle(bot: Bot, event: GroupMessageEvent, state: T_State): url = match_link_parts(event.get_plaintext()) imageUrl = await get_github_reposity_information(url) - if imageUrl == "获取信息失败": - raise AssertionError + assert (imageUrl != "获取信息失败") await github.send(MessageSegment.image(imageUrl)) diff --git a/src/plugins/nonebot_plugin_githubcard/config.py b/src/plugins/nonebot_plugin_githubcard/config.py index d2e4336..6b9effa 100644 --- a/src/plugins/nonebot_plugin_githubcard/config.py +++ b/src/plugins/nonebot_plugin_githubcard/config.py @@ -5,6 +5,7 @@ class Config(BaseModel, extra=Extra.ignore): github_token: Optional[str] = None + github_type: Optional[int] = 0 global_config = nonebot.get_driver().config diff --git a/src/plugins/nonebot_plugin_githubcard/data_source.py b/src/plugins/nonebot_plugin_githubcard/data_source.py index 1890add..ddb8013 100644 --- a/src/plugins/nonebot_plugin_githubcard/data_source.py +++ b/src/plugins/nonebot_plugin_githubcard/data_source.py @@ -1,32 +1,42 @@ +''' +Author: Night-stars-1 nujj1042633805@gmail.com +Date: 2023-10-01 21:25:18 +LastEditors: Night-stars-1 nujj1042633805@gmail.com +LastEditTime: 2023-10-01 21:33:20 +Description: + +Copyright (c) 2023 by Night-stars-1, All Rights Reserved. +''' + import aiohttp from .config import githubcard_config + token = githubcard_config.github_token +github_type = githubcard_config.github_type Headers1 = { - "user-agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36" -} -Headers2 = { - "Authorization": - f"Bearer {token}", - "Accept": - "application/vnd.github+json", - "user-agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36" -} + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"} +Headers2 = {"Authorization": f"Bearer {token}", "Accept": "application/vnd.github+json", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"} -headers = Headers1 if token is None else Headers2 +if token is None: + headers = Headers1 +else: + headers = Headers2 async def get_github_reposity_information(url: str) -> str: try: UserName, RepoName = url.replace("https://github.com/", "").split("/") - except Exception: + except: UserName, RepoName = url.replace("github.com/", "").split("/") - async with aiohttp.ClientSession() as session, session.get(f"https://api.github.com/users/{UserName}", - headers=headers, - timeout=5) as response: - RawData = await response.json() - AvatarUrl = RawData["avatar_url"] - return f"https://image.thum.io/get/width/1280/crop/640/viewportWidth/1280/png/noanimate/https://socialify.git.ci/{UserName}/{RepoName}/image?description=1&font=Source%20Code%20Pro&forks=1&issues=1&language=1&name=1&owner=1&pattern=Charlie%20Brown&pulls=1&stargazers=1&theme=Dark&logo={AvatarUrl}" + async with aiohttp.ClientSession() as session: + async with session.get(f"https://api.github.com/users/{UserName}", headers=headers, timeout=5) as response: + RawData = await response.json() + AvatarUrl = RawData["avatar_url"] + if github_type == 0: + ImageUrl = f"https://image.thum.io/get/width/1280/crop/640/viewportWidth/1280/png/noanimate/https://socialify.git.ci/{UserName}/{RepoName}/image?description=1&font=Rokkitt&forks=1&issues=1&language=1&name=1&owner=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Light&logo={AvatarUrl}" + else: + ImageUrl = f"https://opengraph.githubassets.com/githubcard/{UserName}/{RepoName}" + return ImageUrl