🐛 fix cqhttp secret checking #289

This commit is contained in:
yanyongyu
2021-03-20 14:49:58 +08:00
parent 22033e1cfb
commit 2166595e50
11 changed files with 61 additions and 54 deletions

View File

@ -72,7 +72,7 @@ class Bot(abc.ABC):
@classmethod
@abc.abstractmethod
async def check_permission(cls, driver: "Driver", connection_type: str,
headers: dict, body: Optional[dict]) -> str:
headers: dict, body: Optional[bytes]) -> str:
"""
:说明:
@ -83,7 +83,7 @@ class Bot(abc.ABC):
* ``driver: Driver``: Driver 对象
* ``connection_type: str``: 连接类型
* ``headers: dict``: 请求头
* ``body: Optional[dict]``: 请求数据WebSocket 连接该部分为
* ``body: Optional[bytes]``: 请求数据WebSocket 连接该部分为 None
:返回:

View File

@ -16,7 +16,7 @@ from typing import List, Optional, Callable
import uvicorn
from pydantic import BaseSettings
from fastapi.responses import Response
from fastapi import Body, status, Request, FastAPI, HTTPException
from fastapi import status, Request, FastAPI, HTTPException
from starlette.websockets import WebSocketDisconnect, WebSocket as FastAPIWebSocket
from nonebot.log import logger
@ -177,11 +177,11 @@ class Driver(BaseDriver):
**kwargs)
@overrides(BaseDriver)
async def _handle_http(self,
adapter: str,
request: Request,
data: dict = Body(...)):
if not isinstance(data, dict):
async def _handle_http(self, adapter: str, request: Request):
data = await request.body()
data_dict = json.loads(data.decode())
if not isinstance(data_dict, dict):
logger.warning("Data received is invalid")
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
@ -208,7 +208,7 @@ class Driver(BaseDriver):
bot = BotClass("http", x_self_id)
asyncio.create_task(bot.handle_message(data))
asyncio.create_task(bot.handle_message(data_dict))
return Response("", 204)
@overrides(BaseDriver)