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
|
@property
|
||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
"""Check if the session is expired or not."""
|
"""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 > \
|
datetime.now() - self._last_interaction > \
|
||||||
self.bot.config.SESSION_EXPIRE_TIMEOUT:
|
self.bot.config.SESSION_EXPIRE_TIMEOUT:
|
||||||
return False
|
return False
|
||||||
|
@ -15,21 +15,25 @@ For example:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from typing import Container, Union, Iterable, Pattern, Optional
|
||||||
|
|
||||||
API_ROOT = ''
|
from .expression import Expression_T
|
||||||
SECRET = ''
|
|
||||||
ACCESS_TOKEN = ''
|
|
||||||
HOST = '127.0.0.1'
|
|
||||||
PORT = 8080
|
|
||||||
DEBUG = True
|
|
||||||
|
|
||||||
SUPERUSERS = set()
|
API_ROOT: str = ''
|
||||||
NICKNAME = ''
|
SECRET: str = ''
|
||||||
COMMAND_START = {'/', '!', '/', '!'}
|
ACCESS_TOKEN: str = ''
|
||||||
COMMAND_SEP = {'/', '.'}
|
HOST: str = '127.0.0.1'
|
||||||
SESSION_EXPIRE_TIMEOUT = timedelta(minutes=5)
|
PORT: int = 8080
|
||||||
SESSION_RUNNING_EXPRESSION = '您有命令正在执行,请稍后再试'
|
DEBUG: bool = True
|
||||||
SHORT_MESSAGE_MAX_LENGTH = 50
|
|
||||||
|
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_CONFIG = {
|
||||||
'apscheduler.timezone': 'Asia/Shanghai'
|
'apscheduler.timezone': 'Asia/Shanghai'
|
||||||
|
@ -3,8 +3,10 @@ from typing import Union, Sequence, Callable
|
|||||||
|
|
||||||
from aiocqhttp import message
|
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:
|
**kwargs) -> str:
|
||||||
"""
|
"""
|
||||||
Render an expression to message string.
|
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'])
|
msg = str(ctx['message'])
|
||||||
if bot.config.NICKNAME:
|
if bot.config.NICKNAME:
|
||||||
# check if the user is calling me with my nickname
|
# check if the user is calling me with my nickname
|
||||||
if not isinstance(bot.config.NICKNAME, Iterable):
|
if isinstance(bot.config.NICKNAME, str) or \
|
||||||
# noinspection PyUnusedLocal
|
not isinstance(bot.config.NICKNAME, Iterable):
|
||||||
nicknames = (bot.config.NICKNAME,)
|
nicknames = (bot.config.NICKNAME,)
|
||||||
else:
|
else:
|
||||||
# noinspection PyUnusedLocal
|
|
||||||
nicknames = filter(lambda n: n, bot.config.NICKNAME)
|
nicknames = filter(lambda n: n, bot.config.NICKNAME)
|
||||||
m = re.search(rf'^({"|".join(nicknames)})[\s,,]+', msg, re.IGNORECASE)
|
m = re.search(rf'^({"|".join(nicknames)})[\s,,]+', msg, re.IGNORECASE)
|
||||||
if m:
|
if m:
|
||||||
|
Loading…
Reference in New Issue
Block a user