fc33b3eb68
* docs: transfer AstrBotDevs/AstrBot-docs to AstrBotDevs/AstrBot * refactor: reorder imports and improve type hints in sync_docs_to_wiki.py and upload_doc_images_to_r2.py * feat: add GitHub Actions workflow to sync wiki with documentation Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> Co-authored-by: anka-afk <110004162+anka-afk@users.noreply.github.com> Co-authored-by: zouyonghe <62183434+zouyonghe@users.noreply.github.com> Co-authored-by: shuiping233 <49360196+shuiping233@users.noreply.github.com> Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com> Co-authored-by: Sjshi763 <179909421+Sjshi763@users.noreply.github.com> Co-authored-by: xiewoc <70128845+xiewoc@users.noreply.github.com> Co-authored-by: QingFeng-awa <151742581+QingFeng-awa@users.noreply.github.com> Co-authored-by: PaloMiku <96452465+PaloMiku@users.noreply.github.com> Co-authored-by: shangxueink <138397030+shangxueink@users.noreply.github.com> Co-authored-by: IGCrystal-A <244300990+IGCrystal-A@users.noreply.github.com> Co-authored-by: RC-CHN <67079377+RC-CHN@users.noreply.github.com> Co-authored-by: MC090610 <113341105+MC090610@users.noreply.github.com> Co-authored-by: Waterwzy <196913419+Waterwzy@users.noreply.github.com> Co-authored-by: Lanhuace-Wan <186303160+Lanhuace-Wan@users.noreply.github.com> Co-authored-by: LiAlH4qwq <61769640+LiAlH4qwq@users.noreply.github.com> Co-authored-by: HSOS6 <209910899+HSOS6@users.noreply.github.com> Co-authored-by: th-dd <162813557+th-dd@users.noreply.github.com> Co-authored-by: miaoxutao123 <81676466+miaoxutao123@users.noreply.github.com> Co-authored-by: nuomicici <143102889+nuomicici@users.noreply.github.com> Co-authored-by: nasyt233 <210103278+nasyt233@users.noreply.github.com> Co-authored-by: jlugjb <7426462+jlugjb@users.noreply.github.com> Co-authored-by: Raven95676 <176760093+Raven95676@users.noreply.github.com> Co-authored-by: Futureppo <180109455+Futureppo@users.noreply.github.com> Co-authored-by: MliKiowa <61873808+MliKiowa@users.noreply.github.com> Co-authored-by: Fridemn <150212937+Fridemn@users.noreply.github.com> Co-authored-by: BakaCookie520 <138355736+BakaCookie520@users.noreply.github.com> Co-authored-by: YumeYuka <125112916+YumeYuka@users.noreply.github.com> Co-authored-by: xming521 <32786500+xming521@users.noreply.github.com> Co-authored-by: ywh555hhh <121592812+ywh555hhh@users.noreply.github.com> Co-authored-by: stevessr <89645372+stevessr@users.noreply.github.com> Co-authored-by: roeseth <41995115+roeseth@users.noreply.github.com> Co-authored-by: ikun-1145141 <265925499+ikun-1145141@users.noreply.github.com> Co-authored-by: evpeople <54983536+evpeople@users.noreply.github.com> Co-authored-by: Yue-bin <60509781+Yue-bin@users.noreply.github.com> Co-authored-by: W1ndys <109416673+W1ndys@users.noreply.github.com> Co-authored-by: TheFurina <218887821+TheFurina@users.noreply.github.com> Co-authored-by: Seayon <12275933+Seayon@users.noreply.github.com> Co-authored-by: OnlyblackTea <38585636+OnlyblackTea@users.noreply.github.com> Co-authored-by: ocetars <74854972+ocetars@users.noreply.github.com> Co-authored-by: railgun19457 <117180744+railgun19457@users.noreply.github.com> Co-authored-by: JunieXD <107397009+JunieXD@users.noreply.github.com> Co-authored-by: advent259141 <197440256+advent259141@users.noreply.github.com> Co-authored-by: Doge2077 <91442300+Doge2077@users.noreply.github.com> Co-authored-by: Bocity <23430545+Bocity@users.noreply.github.com> Co-authored-by: Aurora-xk <192227833+Aurora-xk@users.noreply.github.com>
129 lines
5.1 KiB
Markdown
129 lines
5.1 KiB
Markdown
---
|
|
outline: deep
|
|
---
|
|
|
|
# AstrBot Plugin Development Guide 🌠
|
|
|
|
Welcome to the AstrBot Plugin Development Guide! This section will guide you through developing AstrBot plugins. Before we begin, we hope you have the following foundational knowledge:
|
|
|
|
1. Some experience with Python programming.
|
|
2. Some experience with Git and GitHub.
|
|
|
|
## Environment Setup
|
|
|
|
### Obtain the Plugin Template
|
|
|
|
1. Open the AstrBot plugin template: [helloworld](https://github.com/Soulter/helloworld)
|
|
2. Click `Use this template` in the upper right corner
|
|
3. Then click `Create new repository`.
|
|
4. Fill in your plugin name in the `Repository name` field. Plugin naming conventions:
|
|
- Recommended to start with `astrbot_plugin_`;
|
|
- Must not contain spaces;
|
|
- Keep all letters lowercase;
|
|
- Keep it concise.
|
|
5. Click `Create repository` in the lower right corner.
|
|
|
|
### Clone the Project Locally
|
|
|
|
Clone both the AstrBot main project and the plugin repository you just created to your local machine.
|
|
|
|
```bash
|
|
git clone https://github.com/AstrBotDevs/AstrBot
|
|
mkdir -p AstrBot/data/plugins
|
|
cd AstrBot/data/plugins
|
|
git clone <your-plugin-repository-url>
|
|
```
|
|
|
|
Then, use `VSCode` to open the `AstrBot` project. Navigate to the `data/plugins/<your-plugin-name>` directory.
|
|
|
|
Update the `metadata.yaml` file with your plugin's metadata information.
|
|
|
|
> [!WARNING]
|
|
> Please make sure to modify this file, as AstrBot relies on the `metadata.yaml` file to recognize plugin metadata.
|
|
|
|
### Set Plugin Logo (Optional)
|
|
|
|
You can add a `logo.png` file in the plugin directory as the plugin's logo. Please maintain an aspect ratio of 1:1, with a recommended size of 256x256.
|
|
|
|

|
|
|
|
### Plugin Display Name (Optional)
|
|
|
|
You can modify (or add) the `display_name` field in the `metadata.yaml` file to serve as the plugin's display name in scenarios like the plugin marketplace, making it easier for users to read.
|
|
|
|
### Declare Supported Platforms (Optional)
|
|
|
|
You can add a `support_platforms` field (`list[str]`) to `metadata.yaml` to declare which platform adapters your plugin supports. The WebUI plugin page will display this field.
|
|
|
|
```yaml
|
|
support_platforms:
|
|
- telegram
|
|
- discord
|
|
```
|
|
|
|
The values in `support_platforms` must be keys from `ADAPTER_NAME_2_TYPE`. Currently supported:
|
|
|
|
- `aiocqhttp`
|
|
- `qq_official`
|
|
- `telegram`
|
|
- `wecom`
|
|
- `lark`
|
|
- `dingtalk`
|
|
- `discord`
|
|
- `slack`
|
|
- `kook`
|
|
- `vocechat`
|
|
- `weixin_official_account`
|
|
- `satori`
|
|
- `misskey`
|
|
- `line`
|
|
|
|
### Declare AstrBot Version Range (Optional)
|
|
|
|
You can add an `astrbot_version` field in `metadata.yaml` to declare the required AstrBot version range for your plugin. The format follows dependency specifiers in `pyproject.toml` (PEP 440), and must not include a `v` prefix.
|
|
|
|
```yaml
|
|
astrbot_version: ">=4.16,<5"
|
|
```
|
|
|
|
Examples:
|
|
|
|
- `>=4.17.0`
|
|
- `>=4.16,<5`
|
|
- `~=4.17`
|
|
|
|
If you only want to declare a minimum version, use:
|
|
|
|
- `>=4.17.0`
|
|
|
|
If the current AstrBot version does not satisfy this range, the plugin will be blocked from loading with a compatibility error.
|
|
In the WebUI installation flow, you can choose to "Ignore Warning and Install" to bypass this check.
|
|
|
|
### Debugging Plugins
|
|
|
|
AstrBot uses a runtime plugin injection mechanism. Therefore, when debugging plugins, you need to start the AstrBot main application.
|
|
|
|
You can use AstrBot's hot reload feature to streamline the development process.
|
|
|
|
After modifying the plugin code, you can find your plugin in the AstrBot WebUI's plugin management section, click the `...` button in the upper right corner, and select `Reload Plugin`.
|
|
|
|
If the plugin fails to load due to code errors or other reasons, you can also click **"Try one-click reload fix"** in the error prompt on the admin panel to reload it.
|
|
|
|
### Plugin Dependency Management
|
|
|
|
Currently, AstrBot manages plugin dependencies using pip's built-in `requirements.txt` file. If your plugin requires third-party libraries, please be sure to create a `requirements.txt` file in the plugin directory and list the dependencies used, to prevent Module Not Found errors when users install your plugin.
|
|
|
|
> For the complete format of `requirements.txt`, please refer to the [pip official documentation](https://pip.pypa.io/en/stable/reference/requirements-file-format/).
|
|
|
|
## Development Principles
|
|
|
|
Thank you for contributing to the AstrBot ecosystem. Please follow these principles when developing plugins, which are also good programming practices:
|
|
|
|
- Features must be tested.
|
|
- Include comprehensive comments.
|
|
- Store persistent data in the `data` directory, not in the plugin's own directory, to prevent data loss when updating/reinstalling the plugin.
|
|
- Implement robust error handling mechanisms; don't let a single error crash the plugin.
|
|
- Before committing, please use the [ruff](https://docs.astral.sh/ruff/) tool to format your code.
|
|
- Do not use the `requests` library for network requests; use asynchronous network request libraries such as `aiohttp` or `httpx`.
|
|
- If you're extending functionality for an existing plugin, please prioritize submitting a PR to that plugin rather than creating a separate one (unless the original plugin author has stopped maintaining it).
|