2021-01-29 17:37:44 +08:00
|
|
|
from pprint import pprint
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from nonebot.adapters import Bot as BaseBot
|
2021-01-29 21:19:13 +08:00
|
|
|
from nonebot.adapters import Event as BaseEvent
|
2021-01-29 17:37:44 +08:00
|
|
|
from nonebot.drivers import Driver, WebSocket
|
2021-01-29 21:19:13 +08:00
|
|
|
from nonebot.message import handle_event
|
2021-01-29 17:37:44 +08:00
|
|
|
from nonebot.typing import overrides
|
|
|
|
|
2021-01-29 21:19:13 +08:00
|
|
|
from .event import Event
|
|
|
|
|
2021-01-29 17:37:44 +08:00
|
|
|
|
|
|
|
class MiraiBot(BaseBot):
|
|
|
|
|
|
|
|
def __init__(self,
|
|
|
|
connection_type: str,
|
|
|
|
self_id: str,
|
|
|
|
*,
|
|
|
|
websocket: Optional["WebSocket"] = None):
|
|
|
|
super().__init__(connection_type, self_id, websocket=websocket)
|
|
|
|
|
|
|
|
@property
|
|
|
|
@overrides(BaseBot)
|
|
|
|
def type(self) -> str:
|
|
|
|
return "mirai"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@overrides(BaseBot)
|
|
|
|
async def check_permission(cls, driver: "Driver", connection_type: str,
|
|
|
|
headers: dict, body: Optional[dict]) -> str:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
@overrides(BaseBot)
|
|
|
|
async def handle_message(self, message: dict):
|
2021-01-29 21:19:13 +08:00
|
|
|
event = Event.new(message)
|
|
|
|
await handle_event(self, event)
|
2021-01-29 17:37:44 +08:00
|
|
|
|
|
|
|
@overrides(BaseBot)
|
|
|
|
async def call_api(self, api: str, **data):
|
|
|
|
return super().call_api(api, **data)
|
|
|
|
|
|
|
|
@overrides(BaseBot)
|
2021-01-29 21:19:13 +08:00
|
|
|
async def send(self, event: "BaseEvent", message: str, **kwargs):
|
2021-01-29 17:37:44 +08:00
|
|
|
return super().send(event, message, **kwargs)
|