mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
- 新增 Cooldown、RateLimit、ConcurrencyLimit 三种限流依赖 - MessageUtils 支持动态格式化字符串 (format_args 参数) - 插件CD限制消息显示精确剩余时间 - 重构限流逻辑至 utils/limiters.py,新增时间工具模块 - 整合时间工具函数并优化时区处理 - 新增 limiter_hook 自动释放资源,CooldownError 优化异常处理 - 冷却提示从固定文本改为动态显示剩余时间 - 示例:总结功能冷却中,请等待 1分30秒 后再试~ Co-authored-by: webjoin111 <455457521@qq.com> Co-authored-by: HibiKier <45528451+HibiKier@users.noreply.github.com>
16 lines
517 B
Python
16 lines
517 B
Python
from nonebot.matcher import Matcher
|
|
from nonebot.message import run_postprocessor
|
|
|
|
from zhenxun.utils.limiters import ConcurrencyLimiter
|
|
|
|
|
|
@run_postprocessor
|
|
async def _concurrency_release_hook(matcher: Matcher):
|
|
"""
|
|
后处理器:在事件处理结束后,释放并发限制的信号量。
|
|
"""
|
|
if concurrency_info := matcher.state.get("_concurrency_limiter_info"):
|
|
limiter: ConcurrencyLimiter = concurrency_info["limiter"]
|
|
key = concurrency_info["key"]
|
|
limiter.release(key)
|