mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-12-01 01:25:07 +08:00
fix import
This commit is contained in:
parent
e9fb50eb1b
commit
4794a4bacb
@ -131,11 +131,11 @@ def on_websocket_connect(func: Callable[[aiocqhttp.Event], Awaitable[None]]) \
|
|||||||
|
|
||||||
|
|
||||||
from .exceptions import *
|
from .exceptions import *
|
||||||
from .message import message_preprocessor, Message, MessageSegment
|
from .command import CommandSession, CommandGroup
|
||||||
from .plugin import (on_command, on_natural_language, on_notice, on_request,
|
from .plugin import (on_command, on_natural_language, on_notice, on_request,
|
||||||
load_plugin, load_plugins, load_builtin_plugins,
|
load_plugin, load_plugins, load_builtin_plugins,
|
||||||
get_loaded_plugins)
|
get_loaded_plugins)
|
||||||
from .command import CommandSession, CommandGroup
|
from .message import message_preprocessor, Message, MessageSegment
|
||||||
from .natural_language import NLPSession, NLPResult, IntentCommand
|
from .natural_language import NLPSession, NLPResult, IntentCommand
|
||||||
from .notice_request import NoticeSession, RequestSession
|
from .notice_request import NoticeSession, RequestSession
|
||||||
from .helpers import context_id
|
from .helpers import context_id
|
||||||
|
@ -8,12 +8,12 @@ from typing import (Tuple, Union, Callable, Iterable, Any, Optional, List, Dict,
|
|||||||
Awaitable)
|
Awaitable)
|
||||||
|
|
||||||
from aiocqhttp import Event as CQEvent
|
from aiocqhttp import Event as CQEvent
|
||||||
|
from aiocqhttp.message import Message
|
||||||
|
|
||||||
from nonebot import NoneBot, permission as perm
|
from nonebot import NoneBot, permission as perm
|
||||||
from nonebot.command.argfilter import ValidateError
|
from nonebot.command.argfilter import ValidateError
|
||||||
from nonebot.helpers import context_id, send, render_expression
|
from nonebot.helpers import context_id, send, render_expression
|
||||||
from nonebot.log import logger
|
from nonebot.log import logger
|
||||||
from nonebot.message import Message
|
|
||||||
from nonebot.session import BaseSession
|
from nonebot.session import BaseSession
|
||||||
from nonebot.typing import (CommandName_T, CommandArgs_T, CommandHandler_T,
|
from nonebot.typing import (CommandName_T, CommandArgs_T, CommandHandler_T,
|
||||||
Message_T, State_T, Filter_T)
|
Message_T, State_T, Filter_T)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import re
|
import re
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from nonebot.message import Message
|
from aiocqhttp.message import Message
|
||||||
|
|
||||||
from nonebot.typing import Message_T
|
from nonebot.typing import Message_T
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import re
|
import re
|
||||||
from typing import Callable, Any
|
from typing import Callable, Any
|
||||||
|
|
||||||
from nonebot.command.argfilter import ValidateError
|
|
||||||
from nonebot.typing import Filter_T
|
from nonebot.typing import Filter_T
|
||||||
|
from nonebot.command.argfilter import ValidateError
|
||||||
|
|
||||||
|
|
||||||
class BaseValidator:
|
class BaseValidator:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from typing import Union, Callable
|
from typing import Union, Callable
|
||||||
|
|
||||||
from nonebot.command import on_command
|
from nonebot.plugin import on_command
|
||||||
from nonebot.typing import CommandName_T
|
from nonebot.typing import CommandName_T
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@ import hashlib
|
|||||||
import random
|
import random
|
||||||
from typing import Sequence, Callable, Any
|
from typing import Sequence, Callable, Any
|
||||||
|
|
||||||
|
from aiocqhttp.message import escape
|
||||||
from aiocqhttp import Event as CQEvent
|
from aiocqhttp import Event as CQEvent
|
||||||
|
|
||||||
from . import NoneBot
|
from . import NoneBot
|
||||||
from .exceptions import CQHttpError
|
from .exceptions import CQHttpError
|
||||||
from .message import escape
|
|
||||||
from .typing import Message_T, Expression_T
|
from .typing import Message_T, Expression_T
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@ from functools import update_wrapper
|
|||||||
from typing import Set, Iterable, Optional, Callable, Union, NamedTuple
|
from typing import Set, Iterable, Optional, Callable, Union, NamedTuple
|
||||||
|
|
||||||
from aiocqhttp import Event as CQEvent
|
from aiocqhttp import Event as CQEvent
|
||||||
|
from aiocqhttp.message import Message
|
||||||
|
|
||||||
|
from .log import logger
|
||||||
from . import NoneBot, permission as perm
|
from . import NoneBot, permission as perm
|
||||||
from .command import call_command
|
from .command import call_command
|
||||||
from .log import logger
|
|
||||||
from .message import Message
|
|
||||||
from .session import BaseSession
|
from .session import BaseSession
|
||||||
from .typing import CommandName_T, CommandArgs_T
|
from .typing import CommandName_T, CommandArgs_T
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ from aiocqhttp import Event as CQEvent
|
|||||||
from aiocqhttp.bus import EventBus
|
from aiocqhttp.bus import EventBus
|
||||||
|
|
||||||
from . import NoneBot
|
from . import NoneBot
|
||||||
from .exceptions import CQHttpError
|
|
||||||
from .log import logger
|
from .log import logger
|
||||||
|
from .exceptions import CQHttpError
|
||||||
from .session import BaseSession
|
from .session import BaseSession
|
||||||
|
|
||||||
_bus = EventBus()
|
_bus = EventBus()
|
||||||
|
@ -9,8 +9,8 @@ from typing import Any, Set, Dict, Union, Optional, Iterable, Callable
|
|||||||
from .log import logger
|
from .log import logger
|
||||||
from nonebot import permission as perm
|
from nonebot import permission as perm
|
||||||
from .command import Command, CommandManager
|
from .command import Command, CommandManager
|
||||||
from .natural_language import NLProcessor, NLPManager
|
|
||||||
from .notice_request import _bus, EventHandler
|
from .notice_request import _bus, EventHandler
|
||||||
|
from .natural_language import NLProcessor, NLPManager
|
||||||
from .typing import CommandName_T, CommandHandler_T
|
from .typing import CommandName_T, CommandHandler_T
|
||||||
|
|
||||||
_tmp_command: Set[Command] = set()
|
_tmp_command: Set[Command] = set()
|
||||||
@ -49,7 +49,7 @@ class PluginManager:
|
|||||||
"""Register a plugin
|
"""Register a plugin
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): module path
|
module_path (str): module path
|
||||||
plugin (Plugin): Plugin object
|
plugin (Plugin): Plugin object
|
||||||
"""
|
"""
|
||||||
if module_path in cls._plugins:
|
if module_path in cls._plugins:
|
||||||
@ -59,10 +59,10 @@ class PluginManager:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_plugin(cls, module_path: str) -> Optional[Plugin]:
|
def get_plugin(cls, module_path: str) -> Optional[Plugin]:
|
||||||
"""Get plugin object by plugin path
|
"""Get plugin object by plugin module path
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): plugin path
|
module_path (str): Plugin module path
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Optional[Plugin]: Plugin object
|
Optional[Plugin]: Plugin object
|
||||||
@ -71,6 +71,17 @@ class PluginManager:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def remove_plugin(cls, module_path: str) -> bool:
|
def remove_plugin(cls, module_path: str) -> bool:
|
||||||
|
"""Remove a plugin by plugin module path
|
||||||
|
|
||||||
|
** Warning: This function not remove plugin actually! **
|
||||||
|
** Just remove command, nlprocessor and event handlers **
|
||||||
|
|
||||||
|
Args:
|
||||||
|
module_path (str): Plugin module path
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: Success or not
|
||||||
|
"""
|
||||||
plugin = cls.get_plugin(module_path)
|
plugin = cls.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {module_path} not exists")
|
warnings.warn(f"Plugin {module_path} not exists")
|
||||||
@ -86,17 +97,18 @@ class PluginManager:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def switch_plugin_global(cls, name: str,
|
def switch_plugin_global(cls,
|
||||||
|
module_path: str,
|
||||||
state: Optional[bool] = None) -> None:
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin state globally or simply switch it if `state` is None
|
"""Change plugin state globally or simply switch it if `state` is None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = cls.get_plugin(name)
|
plugin = cls.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for command in plugin.commands:
|
for command in plugin.commands:
|
||||||
CommandManager.switch_command_global(command.name, state)
|
CommandManager.switch_command_global(command.name, state)
|
||||||
@ -111,49 +123,52 @@ class PluginManager:
|
|||||||
_bus.subscribe(event, event_handler.func)
|
_bus.subscribe(event, event_handler.func)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def switch_command_global(cls, name: str,
|
def switch_command_global(cls,
|
||||||
|
module_path: str,
|
||||||
state: Optional[bool] = None) -> None:
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin command state globally or simply switch it if `state` is None
|
"""Change plugin command state globally or simply switch it if `state` is None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = cls.get_plugin(name)
|
plugin = cls.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for command in plugin.commands:
|
for command in plugin.commands:
|
||||||
CommandManager.switch_command_global(command.name, state)
|
CommandManager.switch_command_global(command.name, state)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def switch_nlprocessor_global(cls, name: str,
|
def switch_nlprocessor_global(cls,
|
||||||
|
module_path: str,
|
||||||
state: Optional[bool] = None) -> None:
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin nlprocessor state globally or simply switch it if `state` is None
|
"""Change plugin nlprocessor state globally or simply switch it if `state` is None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = cls.get_plugin(name)
|
plugin = cls.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for processor in plugin.nl_processors:
|
for processor in plugin.nl_processors:
|
||||||
NLPManager.switch_nlprocessor_global(processor, state)
|
NLPManager.switch_nlprocessor_global(processor, state)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def switch_eventhandler_global(cls, name: str,
|
def switch_eventhandler_global(cls,
|
||||||
|
module_path: str,
|
||||||
state: Optional[bool] = None) -> None:
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin event handler state globally or simply switch it if `state` is None
|
"""Change plugin event handler state globally or simply switch it if `state` is None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = cls.get_plugin(name)
|
plugin = cls.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for event_handler in plugin.event_handlers:
|
for event_handler in plugin.event_handlers:
|
||||||
for event in event_handler.events:
|
for event in event_handler.events:
|
||||||
@ -163,52 +178,54 @@ class PluginManager:
|
|||||||
event] and state != False:
|
event] and state != False:
|
||||||
_bus.subscribe(event, event_handler.func)
|
_bus.subscribe(event, event_handler.func)
|
||||||
|
|
||||||
def switch_plugin(self, name: str, state: Optional[bool] = None) -> None:
|
def switch_plugin(self, module_path: str,
|
||||||
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin state or simply switch it if `state` is None
|
"""Change plugin state or simply switch it if `state` is None
|
||||||
|
|
||||||
Tips:
|
Tips:
|
||||||
This method will only change the state of the plugin's
|
This method will only change the state of the plugin's
|
||||||
commands and natural language processors since change
|
commands and natural language processors since change
|
||||||
state of the event handler partially is meaningless.
|
state of the event handler for message is meaningless.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = self.get_plugin(name)
|
plugin = self.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for command in plugin.commands:
|
for command in plugin.commands:
|
||||||
self.cmd_manager.switch_command(command.name, state)
|
self.cmd_manager.switch_command(command.name, state)
|
||||||
for nl_processor in plugin.nl_processors:
|
for nl_processor in plugin.nl_processors:
|
||||||
self.nlp_manager.switch_nlprocessor(nl_processor, state)
|
self.nlp_manager.switch_nlprocessor(nl_processor, state)
|
||||||
|
|
||||||
def switch_command(self, name: str, state: Optional[bool] = None) -> None:
|
def switch_command(self, module_path: str,
|
||||||
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin command state or simply switch it if `state` is None
|
"""Change plugin command state or simply switch it if `state` is None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = self.get_plugin(name)
|
plugin = self.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for command in plugin.commands:
|
for command in plugin.commands:
|
||||||
self.cmd_manager.switch_command(command.name, state)
|
self.cmd_manager.switch_command(command.name, state)
|
||||||
|
|
||||||
def switch_nlprocessor(self, name: str,
|
def switch_nlprocessor(self, module_path: str,
|
||||||
state: Optional[bool] = None) -> None:
|
state: Optional[bool] = None) -> None:
|
||||||
"""Change plugin nlprocessor state or simply switch it if `state` is None
|
"""Change plugin nlprocessor state or simply switch it if `state` is None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Plugin name
|
module_path (str): Plugin module path
|
||||||
state (Optional[bool]): State to change to. Defaults to None.
|
state (Optional[bool]): State to change to. Defaults to None.
|
||||||
"""
|
"""
|
||||||
plugin = self.get_plugin(name)
|
plugin = self.get_plugin(module_path)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
warnings.warn(f"Plugin {name} not found")
|
warnings.warn(f"Plugin {module_path} not found")
|
||||||
return
|
return
|
||||||
for processor in plugin.nl_processors:
|
for processor in plugin.nl_processors:
|
||||||
self.nlp_manager.switch_nlprocessor(processor, state)
|
self.nlp_manager.switch_nlprocessor(processor, state)
|
||||||
|
Loading…
Reference in New Issue
Block a user