Skip to main content

GitHub adapter for nonebot2

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot-adapter-github-0.2.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_adapter_github-0.2.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file nonebot-adapter-github-0.2.1.tar.gz.

File metadata

  • Download URL: nonebot-adapter-github-0.2.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.7 Linux/5.15.0-1020-azure

File hashes

Hashes for nonebot-adapter-github-0.2.1.tar.gz
Algorithm Hash digest
SHA256 794dd066aebab8e51889aa101730b3cfa54cf2f13a820787d35b6bfa4050f86d
MD5 93d8cb095c2afada446415e3f10fcf1c
BLAKE2b-256 e0401179183f740fb8a7edac27a6c0d4b7872620ac67b7b6885bc1dfb52feeb1

See more details on using hashes here.

File details

Details for the file nonebot_adapter_github-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_adapter_github-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d25ffa1751076956d6fc5c904fac36e44d8ea8881a5bf4b5a9b93b6cfc25999d
MD5 1a854af1bff9f78aeabd196b3a71be95
BLAKE2b-256 9c479d27e8b1190b332c1d7d836b99deb0ff0758b5f6afc426d45f4e603355e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page