mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 17:58:26 +08:00
Add type hints for config items
This commit is contained in:
parent
e59a81858d
commit
bc0d7aaa64
@ -247,7 +247,8 @@ class CommandSession(BaseSession):
|
||||
@property
|
||||
def is_valid(self) -> bool:
|
||||
"""Check if the session is expired or not."""
|
||||
if self._last_interaction and \
|
||||
if self.bot.config.SESSION_EXPIRE_TIMEOUT and \
|
||||
self._last_interaction and \
|
||||
datetime.now() - self._last_interaction > \
|
||||
self.bot.config.SESSION_EXPIRE_TIMEOUT:
|
||||
return False
|
||||
|
@ -15,21 +15,25 @@ For example:
|
||||
"""
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Container, Union, Iterable, Pattern, Optional
|
||||
|
||||
API_ROOT = ''
|
||||
SECRET = ''
|
||||
ACCESS_TOKEN = ''
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 8080
|
||||
DEBUG = True
|
||||
from .expression import Expression_T
|
||||
|
||||
SUPERUSERS = set()
|
||||
NICKNAME = ''
|
||||
COMMAND_START = {'/', '!', '/', '!'}
|
||||
COMMAND_SEP = {'/', '.'}
|
||||
SESSION_EXPIRE_TIMEOUT = timedelta(minutes=5)
|
||||
SESSION_RUNNING_EXPRESSION = '您有命令正在执行,请稍后再试'
|
||||
SHORT_MESSAGE_MAX_LENGTH = 50
|
||||
API_ROOT: str = ''
|
||||
SECRET: str = ''
|
||||
ACCESS_TOKEN: str = ''
|
||||
HOST: str = '127.0.0.1'
|
||||
PORT: int = 8080
|
||||
DEBUG: bool = True
|
||||
|
||||
SUPERUSERS: Container[int] = set()
|
||||
NICKNAME: Union[str, Iterable[str]] = ''
|
||||
COMMAND_START: Iterable[Union[str, Pattern]] = {'/', '!', '/', '!'}
|
||||
COMMAND_SEP: Iterable[Union[str, Pattern]] = {'/', '.'}
|
||||
SESSION_EXPIRE_TIMEOUT: Optional[timedelta] = timedelta(minutes=5)
|
||||
SESSION_RUN_TIMEOUT: Optional[timedelta] = None
|
||||
SESSION_RUNNING_EXPRESSION: Expression_T = '您有命令正在执行,请稍后再试'
|
||||
SHORT_MESSAGE_MAX_LENGTH: int = 50
|
||||
|
||||
APSCHEDULER_CONFIG = {
|
||||
'apscheduler.timezone': 'Asia/Shanghai'
|
||||
|
@ -3,8 +3,10 @@ from typing import Union, Sequence, Callable
|
||||
|
||||
from aiocqhttp import message
|
||||
|
||||
Expression_T = Union[str, Sequence[str], Callable]
|
||||
|
||||
def render(expr: Union[str, Sequence[str], Callable], *, escape_args=True,
|
||||
|
||||
def render(expr: Expression_T, *, escape_args=True,
|
||||
**kwargs) -> str:
|
||||
"""
|
||||
Render an expression to message string.
|
||||
|
@ -86,11 +86,10 @@ async def handle_natural_language(bot: NoneBot, ctx: Dict[str, Any]) -> bool:
|
||||
msg = str(ctx['message'])
|
||||
if bot.config.NICKNAME:
|
||||
# check if the user is calling me with my nickname
|
||||
if not isinstance(bot.config.NICKNAME, Iterable):
|
||||
# noinspection PyUnusedLocal
|
||||
if isinstance(bot.config.NICKNAME, str) or \
|
||||
not isinstance(bot.config.NICKNAME, Iterable):
|
||||
nicknames = (bot.config.NICKNAME,)
|
||||
else:
|
||||
# noinspection PyUnusedLocal
|
||||
nicknames = filter(lambda n: n, bot.config.NICKNAME)
|
||||
m = re.search(rf'^({"|".join(nicknames)})[\s,,]+', msg, re.IGNORECASE)
|
||||
if m:
|
||||
|
Loading…
Reference in New Issue
Block a user