11from copy import deepcopy
22
3- from nonebot .matcher import Matcher
43from nonebot .adapters import Bot , Event
54from nonebot .plugin import PluginMetadata
65from nonebot import on , require , get_driver
7- from nonebot .exception import IgnoredException
8- from nonebot .message import run_preprocessor , event_preprocessor
6+ from nonebot .message import event_preprocessor
97
108require ("nonebot_plugin_localstore" )
119require ("nonebot_plugin_orm" )
1210
13- from .config import Config
14- from .onebotimpl import OneBotImplementation
11+ from .onebotimpl import Config , OneBotImplementation
1512
1613__plugin_meta__ = PluginMetadata (
1714 name = "OneBot 实现" ,
1815 description = "让 NoneBot2 成为 OneBot 实现!" ,
19- usage = """obimpl_connections = [{"type":"websocket_rev","url":"ws://127.0.0.1:8080/onebot/v12/"}] # 其它连接方式的配置同理
20- middlewares = ["OneBot V11"] # 自定义加载的 Middleware,默认加载全部
21- block_event = False # 是否中止已转发 Event 的处理流程,默认中止
22- blocked_plugins = ["echo"] # 在 block_event=False 时生效,可自定义处理流程中要中止的插件""" ,
16+ usage = """
17+ obimpl_connections = [{"type":"websocket_rev","url":"ws://127.0.0.1:8080/onebot/v12/"}]
18+ # 其它连接方式的配置同理
19+ middlewares = ["OneBot V11"]
20+ # 自定义加载的 Middleware,默认加载全部
21+ """ ,
2322 type = "application" ,
2423 homepage = "https://github.com/nonepkg/nonebot-plugin-all4one" ,
2524 config = Config ,
26- supported_adapters = {"~onebot.v11" , "~telegram" },
25+ supported_adapters = {"~onebot.v11" , "~telegram" , "~discord" },
2726)
2827
2928driver = get_driver ()
30- a4o_config = Config (** driver .config .model_dump ())
3129obimpl = OneBotImplementation (driver )
3230
3331on (priority = 1 , block = False )
@@ -42,18 +40,3 @@ async def _(bot: Bot, event: Event):
4240 await queue .get ()
4341 event = deepcopy (event )
4442 await queue .put (deepcopy (event ))
45- if a4o_config .block_event :
46- raise IgnoredException ("All4One has transfer it to OneBot V12" )
47-
48-
49- if not a4o_config .block_event and a4o_config .blocked_plugins :
50-
51- @run_preprocessor
52- async def _ (bot : Bot , matcher : Matcher ):
53- if (
54- bot .type in obimpl ._middlewares
55- and matcher .plugin_name
56- and a4o_config .blocked_plugins
57- and matcher .plugin_name in a4o_config .blocked_plugins
58- ):
59- raise IgnoredException ("All4One has blocked it" )
0 commit comments