Skip to content

Commit

Permalink
Revert "🚀 插件更新以及词云排除qq管家"
Browse files Browse the repository at this point in the history
This reverts commit 635e548.
  • Loading branch information
wling-art authored Jan 10, 2024
1 parent 048d2d5 commit 17699b5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 10 additions & 18 deletions src/plugins/nonebot_plugin_githubcard/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"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):
Expand All @@ -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))
1 change: 0 additions & 1 deletion src/plugins/nonebot_plugin_githubcard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 19 additions & 29 deletions src/plugins/nonebot_plugin_githubcard/data_source.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
'''
Author: Night-stars-1 [email protected]
Date: 2023-10-01 21:25:18
LastEditors: Night-stars-1 [email protected]
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}"

0 comments on commit 17699b5

Please sign in to comment.