diff --git a/.env b/.env index 08d3b08..bd538df 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 new file mode 100644 index 0000000..09107cd --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,18 @@ +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 0d2f06a..877db33 100644 --- a/src/plugins/nonebot_plugin_githubcard/__init__.py +++ b/src/plugins/nonebot_plugin_githubcard/__init__.py @@ -1,31 +1,22 @@ 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, PluginMetadata +from nonebot.plugin import on_regex +from nonebot.plugin import PluginMetadata import re __plugin_meta__ = PluginMetadata( - 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", - }, -) - + name="github card", + description="展示github仓库卡片", + usage="github仓库卡片\n发出 github.com/用户名/仓库名 的格式即可自动检测") 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): @@ -37,5 +28,6 @@ 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) - assert (imageUrl != "获取信息失败") + if imageUrl == "获取信息失败": + raise AssertionError 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 6b9effa..d2e4336 100644 --- a/src/plugins/nonebot_plugin_githubcard/config.py +++ b/src/plugins/nonebot_plugin_githubcard/config.py @@ -5,7 +5,6 @@ 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 ddb8013..1890add 100644 --- a/src/plugins/nonebot_plugin_githubcard/data_source.py +++ b/src/plugins/nonebot_plugin_githubcard/data_source.py @@ -1,42 +1,32 @@ -''' -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" +} -if token is None: - headers = Headers1 -else: - headers = Headers2 +headers = Headers1 if token is None else Headers2 async def get_github_reposity_information(url: str) -> str: try: UserName, RepoName = url.replace("https://github.com/", "").split("/") - except: + except Exception: UserName, RepoName = url.replace("github.com/", "").split("/") - 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 + 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}"