diff --git a/README.md b/README.md index bb769c3..dd6fe61 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,15 @@ 让 [NoneBot2](https://github.com/nonebot/nonebot2) 成为 OneBot 实现! [![License](https://img.shields.io/github/license/nonepkg/nonebot-plugin-all4one?style=flat-square)](LICENSE) +[![codecov](https://codecov.io/gh/nonepkg/plugin-all4one/branch/master/graph/badge.svg?token=BOK429DAHO)](https://codecov.io/gh/nonepkg/plugin-all4one) +[![pdm-managed](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org) ![Python Version](https://img.shields.io/badge/python-3.9+-blue.svg?style=flat-square) -[![NoneBot Version](https://img.shields.io/badge/nonebot-2.3.0+-red.svg?style=flat-square)](https://v2.nonebot.dev/) -[![OneBot 4A](https://img.shields.io/badge/OneBot-4A-black?style=flat-square)](https://onebot4all.vercel.app/) +[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev) [![PyPI Version](https://img.shields.io/pypi/v/nonebot-plugin-all4one.svg?style=flat-square)](https://pypi.python.org/pypi/nonebot-plugin-all4one) -[![codecov](https://codecov.io/gh/nonepkg/plugin-all4one/branch/master/graph/badge.svg?token=BOK429DAHO)](https://codecov.io/gh/nonepkg/plugin-all4one) +[![OneBot 4A](https://img.shields.io/badge/OneBot-4A-black?style=flat-square)](https://onebot4all.vercel.app/) +[![NoneBot Version](https://img.shields.io/badge/nonebot-2.3.0+-red.svg?style=flat-square)](https://v2.nonebot.dev/) +[![NoneBot Registry](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin%2Fnonebot-plugin-all4one)](https://registry.nonebot.dev/plugin/nonebot-plugin-all4one:nonebot_plugin_all4one) +[![Supported Adapters](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin-adapters%2Fnonebot-plugin-all4one)](https://registry.nonebot.dev/plugin/nonebot-plugin-all4one:nonebot_plugin_all4one) @@ -33,8 +37,6 @@ pdm add nonebot-plugin-all4one ```dotenv obimpl_connections = [{"type":"websocket_rev","url":"ws://127.0.0.1:8080/onebot/v12/"}] # 其它连接方式的配置同理 middlewares = ["OneBot V11"] # 自定义加载的 Middleware,默认加载全部 -block_event = False # 是否中止已转发 Event 的处理流程,默认中止 -blocked_plugins = ["echo"] # 在 block_event=False 时生效,可自定义处理流程中要中止的插件 ``` ## Feature @@ -49,12 +51,14 @@ blocked_plugins = ["echo"] # 在 block_event=False 时生效,可自定义处 ### Middlewares - [x] [OneBot V11](https://github.com/nonebot/adapter-onebot) -- [x] [Telegram](http://github.com/nonebot/adapter-telegram) +- [x] [Telegram](https://github.com/nonebot/adapter-telegram) +- [x] [Discord](https://github.com/nonebot/adapter-discord) 测试中 - [ ] [QQ](https://github.com/nonebot/adapter-qq) [@he0119](https://github.com/he0119) 寻求新维护者 ## 相关链接 -- [nonebot-adapter-onebot](https://github.com/nonebot/adapter-onebot) 复用代码 +- [nonebot/adapter-onebot](https://github.com/nonebot/adapter-onebot) 复用代码 - [zhamao-robot/go-cqhttp-adapter-plugin](https://github.com/zhamao-robot/go-cqhttp-adapter-plugin) OneBot V11 -> V12 逻辑参考 -- [nonebot-plugin-params](https://github.com/iyume/nonebot-plugin-params) 灵感来源 +- [iyume/nonebot-plugin-params](https://github.com/iyume/nonebot-plugin-params) 灵感来源 - [felinae98/nonebot-plugin-send-anything-anywhere](https://github.com/felinae98/nonebot-plugin-send-anything-anywhere) 友情推荐 +- [nonebot/plugin-alconna](https://github.com/nonebot/plugin-alconna) 同上 diff --git a/docker/.env b/docker/.env index c4c7821..fa445ae 100644 --- a/docker/.env +++ b/docker/.env @@ -4,10 +4,6 @@ DRIVER=~fastapi+~aiohttp OBIMPL_CONNECTIONS=[{"type":"websocket_rev","url":"ws://127.0.0.1:8080/onebot/v12/"}] # 自定义加载的 Middleware,默认加载全部 MIDDLEWARES -# 是否中止已转发 Event 的处理流程,默认中止 -BLOCK_EVENT=True -# 在 block_event=False 时生效,可自定义处理流程中要中止的插件 -BLOCKED_PLUGINS=[] # QQ 频道 # https://github.com/nonebot/adapter-qqguild diff --git a/nonebot_plugin_all4one/__init__.py b/nonebot_plugin_all4one/__init__.py index 8a1de7f..86fcb10 100644 --- a/nonebot_plugin_all4one/__init__.py +++ b/nonebot_plugin_all4one/__init__.py @@ -1,33 +1,31 @@ from copy import deepcopy -from nonebot.matcher import Matcher from nonebot.adapters import Bot, Event from nonebot.plugin import PluginMetadata from nonebot import on, require, get_driver -from nonebot.exception import IgnoredException -from nonebot.message import run_preprocessor, event_preprocessor +from nonebot.message import event_preprocessor require("nonebot_plugin_localstore") require("nonebot_plugin_orm") -from .config import Config -from .onebotimpl import OneBotImplementation +from .onebotimpl import Config, OneBotImplementation __plugin_meta__ = PluginMetadata( name="OneBot 实现", description="让 NoneBot2 成为 OneBot 实现!", - usage="""obimpl_connections = [{"type":"websocket_rev","url":"ws://127.0.0.1:8080/onebot/v12/"}] # 其它连接方式的配置同理 -middlewares = ["OneBot V11"] # 自定义加载的 Middleware,默认加载全部 -block_event = False # 是否中止已转发 Event 的处理流程,默认中止 -blocked_plugins = ["echo"] # 在 block_event=False 时生效,可自定义处理流程中要中止的插件""", + usage=""" + obimpl_connections = [{"type":"websocket_rev","url":"ws://127.0.0.1:8080/onebot/v12/"}] + # 其它连接方式的配置同理 + middlewares = ["OneBot V11"] + # 自定义加载的 Middleware,默认加载全部 + """, type="application", homepage="https://github.com/nonepkg/nonebot-plugin-all4one", config=Config, - supported_adapters={"~onebot.v11", "~telegram"}, + supported_adapters={"~onebot.v11", "~telegram", "~discord"}, ) driver = get_driver() -a4o_config = Config(**driver.config.model_dump()) obimpl = OneBotImplementation(driver) on(priority=1, block=False) @@ -42,18 +40,3 @@ async def _(bot: Bot, event: Event): await queue.get() event = deepcopy(event) await queue.put(deepcopy(event)) - if a4o_config.block_event: - raise IgnoredException("All4One has transfer it to OneBot V12") - - -if not a4o_config.block_event and a4o_config.blocked_plugins: - - @run_preprocessor - async def _(bot: Bot, matcher: Matcher): - if ( - bot.type in obimpl._middlewares - and matcher.plugin_name - and a4o_config.blocked_plugins - and matcher.plugin_name in a4o_config.blocked_plugins - ): - raise IgnoredException("All4One has blocked it") diff --git a/nonebot_plugin_all4one/config.py b/nonebot_plugin_all4one/config.py deleted file mode 100644 index 2a5d8da..0000000 --- a/nonebot_plugin_all4one/config.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Optional - -from pydantic import BaseModel - - -class Config(BaseModel): - block_event: bool = True - blocked_plugins: Optional[set[str]] = None - - class Config: - extra = "ignore"