-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨Add wordcloud_exclude_user_ids to .env file * 🚀 更新githubcard
- Loading branch information
Showing
5 changed files
with
49 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>", | ||
"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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
''' | ||
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"} | ||
|
||
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 |