GitHub adapter for nonebot2
Project description
NoneBot-Adapter-GitHub
✨ GitHub 协议适配 ✨
安装
poetry add nonebot-adapter-github
# 或者
pip install nonebot-adapter-github
加载适配器
import nonebot
from nonebot.adapters.github import Adapter
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter(Adapter)
配置
配置 APP
GITHUB_APPS='
[
{
"app_id": "123456", # GitHub App ID 必填
"private_key": [
"-----BEGIN RSA PRIVATE KEY-----",
"...", # 将私钥按行输入
"...",
"...",
"-----END RSA PRIVATE KEY-----"
], # GitHub App 私钥必填
"client_id": "123456", # OAuth App Client ID 必填,GitHub App 可选
"client_secret": "xxxxxx", # OAuth App Client Secret 必填,GitHub App 可选
"webhook_secret": "xxxxxx" # 可选
}
]'
其他配置
GITHUB_BASE_URL=https://api.github.com
GITHUB_ACCEPT_FORMAT=full+json
GITHUB_PREVIEWS=["starfox"]
使用
WebHook
URL: /github/webhooks/<app_id>
(GitHub APP) / /github/webhooks/<client_id>
(OAuth APP)
事件格式:
class Event(BaseModel):
id: str # 事件 ID
name: str # 事件名称
payload: Dict[str, Any] # 事件内容
to_me: bool = False # 是否 @ 了机器人或机器人昵称
具体事件类型及内容请参考 GitHub Developer
调用 API
可以直接通过 bot 调用 API,但是请注意 只能使用异步接口,参数必须是 keyword args。具体使用方法参考 githubkit。
async with bot.as_installation(installation_id=1):
resp = await bot.rest.issues.async_get(owner="owner", repo="repo", issue_number=1)
issue = resp.parsed_data
resp = await bot.async_graphql(query=query)
async for issue in bot.github.paginate(bot.rest.issues.async_list_for_repo, owner="owner", repo="repo"):
print(issue)
也可以直接使用 githubkit
,但是将绕过 NoneBot 的 call api hook
。
github = bot.github
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for nonebot_adapter_github-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5f72316fc93d91f654b053f272f74e9a0332345b9428c599c5883cf3f1baf6 |
|
MD5 | c7363a824b295870b2d4e3a2c5977d84 |
|
BLAKE2b-256 | 8fc32082343a3528cb1f9017c175fa4f70c0e0f6da2f40fa995f99103980a529 |
Close
Hashes for nonebot_adapter_github-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 538e4c1277e47ce1813a7e132e0c20ddcf4e3c17339f611d8022411888bbacea |
|
MD5 | 76899dfbc591b2610afcd45deb7b7061 |
|
BLAKE2b-256 | a589afeb51f5d0f131fba206bf324fc754f8eed5aaf63849c9d4696dd2e81f85 |