Skip to main content

nonebot

NoneBot-Adapter-GitHub

✨ GitHub 协议适配 ✨

license pypi python
QQ Chat Group QQ Channel Telegram Channel Discord Server

安装

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_ACCEPR_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

Metadata

Release files for nonebot-adapter-github 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-adapter-github 0.2.5
File Size Uploaded Provenance Actions
nonebot_adapter_github-0.2.5.tar.gz 17.3 kB Without provenance Details for nonebot_adapter_github-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-adapter-github 0.2.5
File Interpreter ABI Platform Actions
nonebot_adapter_github-0.2.5-py3-none-any.whl Python 3 none any Details for nonebot_adapter_github-0.2.5-py3-none-any.whl

Total release size: 34.4 kB

Release files / nonebot_adapter_github-0.2.5.tar.gz

Download URL nonebot_adapter_github-0.2.5.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7f16f78d22da3d2bc01afa8c50d410bcb4f3bafe2956d004b04dad074e339e0a
BLAKE2b-256 checksum
How to use checksums
e911253e1b0937bf4ebe35b8fd5bf73f4c973018fb43c4908bd8817906b6281d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1023-azure

Release files / nonebot_adapter_github-0.2.5-py3-none-any.whl

Download URL nonebot_adapter_github-0.2.5-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29b10396fb2c3ad0424e5c6d263d98b88276e9199fb432e03e54fed008a0cd2a
BLAKE2b-256 checksum
How to use checksums
997d16798aec1ffca47c627db414de19e8a713b3446b9af8a8c4d93044e02dba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1023-azure

Security for nonebot-adapter-github 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page