Skip to content

Latest commit

 

History

History
81 lines (57 loc) · 2.18 KB

README.en-US.md

File metadata and controls

81 lines (57 loc) · 2.18 KB
logo

Wait a Minute

✨ A nonebot plugin for running some func before closing the bot ✨

Python PyPI - Version pdm-managed Ruff


简体中文 | English

🤔 What is this

This plugin implements graceful shutdown for NoneBot2 (see nonebot/nonebot2#2479)
It waits for events to finish processing before shutdown
It also allows you to run some functions before shutdown, similar to on_shutdown
But with higher priority, ensuring execution before bot disconnects

💿 Installation

🚀 Using uv

uv add nonebot-plugin-wait-a-minute

🚀 Using PDM

pdm add nonebot-plugin-wait-a-minute

🚀 Using poetry

poetry add nonebot-plugin-wait-a-minute

♿️ How to use

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