fix some bug

This commit is contained in:
yanyongyu
2020-08-23 10:45:26 +08:00
parent 87a848d8c3
commit a895089a8b
8 changed files with 39 additions and 18 deletions

View File

@ -148,19 +148,17 @@ class Driver(BaseDriver):
access_token: Optional[str] = Depends(get_auth_bearer)):
secret = self.config.secret
if secret is not None and secret != access_token:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
detail="Not authenticated",
headers={"WWW-Authenticate": "Bearer"})
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
websocket = WebSocket(websocket)
if not x_self_id:
logger.error(f"Error Connection Unkown: self_id {x_self_id}")
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
if x_self_id in self._clients:
logger.error(f"Error Connection Conflict: self_id {x_self_id}")
raise HTTPException(status_code=status.HTTP_409_CONFLICT)
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
# Create Bot Object
if adapter in self._adapters:

View File

@ -147,9 +147,7 @@ class Matcher:
else:
state[state["_current_key"]] = str(event.message)
if cls.handlers:
# 已有前置handlers则接受一条新的消息否则视为接收初始消息
cls.handlers.append(_key_getter)
cls.handlers.append(_key_getter)
cls.handlers.append(_key_parser)
def _decorator(func: Handler) -> Handler:

View File

@ -65,7 +65,8 @@ async def handle_event(bot: Bot, event: Event):
return
# Trie Match
_, _ = TrieRule.get_value(bot, event, state)
if event.type == "message":
_, _ = TrieRule.get_value(bot, event, state)
break_flag = False
for priority in sorted(matchers.keys()):

View File

@ -142,10 +142,12 @@ def on_endswith(msg: str,
startswith(msg), permission, **kwargs)
def on_command(cmd: Tuple[str],
def on_command(cmd: Union[str, Tuple[str]],
rule: Optional[Union[Rule, RuleChecker]] = None,
permission: Permission = Permission(),
**kwargs) -> Type[Matcher]:
if isinstance(cmd, str):
cmd = (cmd,)
return on_message(command(cmd) &
rule, permission, **kwargs) if rule else on_message(
command(cmd), permission, **kwargs)

View File

@ -125,3 +125,11 @@ def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
return bool(pattern.search(str(event.message)))
return Rule(_regex)
def to_me() -> Rule:
async def _to_me(bot: Bot, event: Event, state: dict) -> bool:
return bool(event.to_me)
return Rule(_to_me)