https://github.com/shoucandanghehe/nonebot-plugin-wait-a-minute
为 NoneBot2 实现了优雅关机(Graceful Shutdown)
https://github.com/shoucandanghehe/nonebot-plugin-wait-a-minute
graceful-shutdown hook nonebot2 python3
Last synced: 5 months ago
JSON representation
为 NoneBot2 实现了优雅关机(Graceful Shutdown)
- Host: GitHub
- URL: https://github.com/shoucandanghehe/nonebot-plugin-wait-a-minute
- Owner: shoucandanghehe
- License: mit
- Created: 2024-08-17T23:06:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-12-22T18:31:07.000Z (6 months ago)
- Last Synced: 2025-12-24T06:44:24.254Z (6 months ago)
- Topics: graceful-shutdown, hook, nonebot2, python3
- Language: Python
- Homepage:
- Size: 282 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.en-US.md
- License: LICENSE
Awesome Lists containing this project
README
# Wait a Minute
✨ A nonebot plugin for running some func before closing the bot ✨


[](https://pdm-project.org)
[](https://github.com/astral-sh/ruff)
---
[简体中文](./README.md) | English
## 🤔 What is this
This plugin implements graceful shutdown for NoneBot2 (see [nonebot/nonebot2#2479](https://github.com/nonebot/nonebot2/issues/2479))
It waits for events to **finish processing** before shutdown
It also allows you to run some functions before shutdown, similar to [`on_shutdown`](https://nonebot.dev/docs/advanced/runtime-hook#%E7%BB%88%E6%AD%A2%E5%A4%84%E7%90%86)
But with higher priority, ensuring execution before `bot` disconnects
## 💿 Installation
### 🚀 Using uv
```bash
uv add nonebot-plugin-wait-a-minute
```
### 🚀 Using PDM
```bash
pdm add nonebot-plugin-wait-a-minute
```
### 🚀 Using poetry
```bash
poetry add nonebot-plugin-wait-a-minute
```
## ♿️ How to use
```python
from nonebot import require, on_command
from nonebot.matcher import Matcher
require('nonebot_plugin_wait_a_minute') # require plugin
from nonebot_plugin_wait_a_minute import graceful, on_shutdown_before
# Graceful shutdown
@on_command('foo').handle()
@graceful() # 👈 Add graceful decorator below the handle decorator
# Or, you can use @graceful(block=True) to prevent new handles from running during shutdown wait
async def _(matcher: Matcher):
matcher.send('foo')
# Pre-shutdown hook
@on_shutdown_before
def _():
# Do something()
...
# Or use async
@on_shutdown_before
async def _():
# await Do something()
...
```
## 📄 LICENSE
This project is open-sourced under the [MIT](./LICENSE) license