mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 04:26:24 +08:00
💬 💡 rename MiraiBot to Bot, fix a comment style
This commit is contained in:
parent
6c0b20e5b7
commit
5a63827f22
@ -18,7 +18,7 @@ Mirai-API-HTTP 协议适配
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .bot import MiraiBot
|
from .bot import Bot
|
||||||
from .bot_ws import MiraiWebsocketBot
|
from .bot_ws import WebsocketBot
|
||||||
from .event import *
|
from .event import *
|
||||||
from .message import MessageChain, MessageSegment
|
from .message import MessageChain, MessageSegment
|
||||||
|
@ -142,7 +142,7 @@ class SessionManager:
|
|||||||
return cls(key, client)
|
return cls(key, client)
|
||||||
|
|
||||||
|
|
||||||
class MiraiBot(BaseBot):
|
class Bot(BaseBot):
|
||||||
"""
|
"""
|
||||||
mirai-api-http 协议 Bot 适配。
|
mirai-api-http 协议 Bot 适配。
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from nonebot.exception import RequestDenied
|
|||||||
from nonebot.log import logger
|
from nonebot.log import logger
|
||||||
from nonebot.typing import overrides
|
from nonebot.typing import overrides
|
||||||
|
|
||||||
from .bot import MiraiBot, SessionManager
|
from .bot import SessionManager, Bot
|
||||||
|
|
||||||
WebsocketHandlerFunction = Callable[[Dict[str, Any]], Coroutine[Any, Any, None]]
|
WebsocketHandlerFunction = Callable[[Dict[str, Any]], Coroutine[Any, Any, None]]
|
||||||
WebsocketHandler_T = TypeVar('WebsocketHandler_T',
|
WebsocketHandler_T = TypeVar('WebsocketHandler_T',
|
||||||
@ -71,8 +71,9 @@ class WebSocket(BaseWebSocket):
|
|||||||
logger.exception(f'Websocket client listened {self.websocket} '
|
logger.exception(f'Websocket client listened {self.websocket} '
|
||||||
f'failed to decode data: {e}')
|
f'failed to decode data: {e}')
|
||||||
continue
|
continue
|
||||||
asyncio.gather(*map(lambda f: f(data), self.event_handlers),
|
asyncio.gather(
|
||||||
return_exceptions=True)
|
*map(lambda f: f(data), self.event_handlers), #type: ignore
|
||||||
|
return_exceptions=True)
|
||||||
|
|
||||||
@overrides(BaseWebSocket)
|
@overrides(BaseWebSocket)
|
||||||
async def accept(self):
|
async def accept(self):
|
||||||
@ -87,18 +88,18 @@ class WebSocket(BaseWebSocket):
|
|||||||
return callable
|
return callable
|
||||||
|
|
||||||
|
|
||||||
class MiraiWebsocketBot(MiraiBot):
|
class WebsocketBot(Bot):
|
||||||
"""
|
"""
|
||||||
mirai-api-http 正向 Websocket 协议 Bot 适配。
|
mirai-api-http 正向 Websocket 协议 Bot 适配。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@overrides(MiraiBot)
|
@overrides(Bot)
|
||||||
def __init__(self, connection_type: str, self_id: str, *,
|
def __init__(self, connection_type: str, self_id: str, *,
|
||||||
websocket: WebSocket):
|
websocket: WebSocket):
|
||||||
super().__init__(connection_type, self_id, websocket=websocket)
|
super().__init__(connection_type, self_id, websocket=websocket)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@overrides(MiraiBot)
|
@overrides(Bot)
|
||||||
def type(self) -> str:
|
def type(self) -> str:
|
||||||
return "mirai-ws"
|
return "mirai-ws"
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ class MiraiWebsocketBot(MiraiBot):
|
|||||||
return api
|
return api
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@overrides(MiraiBot)
|
@overrides(Bot)
|
||||||
async def check_permission(cls, driver: "Driver", connection_type: str,
|
async def check_permission(cls, driver: "Driver", connection_type: str,
|
||||||
headers: dict, body: Optional[dict]) -> NoReturn:
|
headers: dict, body: Optional[dict]) -> NoReturn:
|
||||||
raise RequestDenied(
|
raise RequestDenied(
|
||||||
@ -121,7 +122,7 @@ class MiraiWebsocketBot(MiraiBot):
|
|||||||
reason=f'Connection {connection_type} not implented')
|
reason=f'Connection {connection_type} not implented')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@overrides(MiraiBot)
|
@overrides(Bot)
|
||||||
def register(cls, driver: "Driver", config: "Config", qq: int):
|
def register(cls, driver: "Driver", config: "Config", qq: int):
|
||||||
"""
|
"""
|
||||||
:说明:
|
:说明:
|
||||||
|
@ -10,3 +10,20 @@ from .base import (Event, GroupChatInfo, GroupInfo, PrivateChatInfo,
|
|||||||
from .message import *
|
from .message import *
|
||||||
from .notice import *
|
from .notice import *
|
||||||
from .request import *
|
from .request import *
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'Event', 'GroupChatInfo', 'GroupInfo', 'PrivateChatInfo', 'UserPermission',
|
||||||
|
'MessageChain', 'MessageEvent', 'GroupMessage', 'FriendMessage',
|
||||||
|
'TempMessage', 'NoticeEvent', 'MuteEvent', 'BotMuteEvent', 'BotUnmuteEvent',
|
||||||
|
'MemberMuteEvent', 'MemberUnmuteEvent', 'BotJoinGroupEvent',
|
||||||
|
'BotLeaveEventActive', 'BotLeaveEventKick', 'MemberJoinEvent',
|
||||||
|
'MemberLeaveEventKick', 'MemberLeaveEventQuit', 'FriendRecallEvent',
|
||||||
|
'GroupRecallEvent', 'GroupStateChangeEvent', 'GroupNameChangeEvent',
|
||||||
|
'GroupEntranceAnnouncementChangeEvent', 'GroupMuteAllEvent',
|
||||||
|
'GroupAllowAnonymousChatEvent', 'GroupAllowConfessTalkEvent',
|
||||||
|
'GroupAllowMemberInviteEvent', 'MemberStateChangeEvent',
|
||||||
|
'MemberCardChangeEvent', 'MemberSpecialTitleChangeEvent',
|
||||||
|
'BotGroupPermissionChangeEvent', 'MemberPermissionChangeEvent',
|
||||||
|
'RequestEvent', 'NewFriendRequestEvent', 'MemberJoinRequestEvent',
|
||||||
|
'BotInvitedJoinGroupRequestEvent'
|
||||||
|
]
|
||||||
|
@ -6,7 +6,7 @@ from typing_extensions import Literal
|
|||||||
from .base import Event
|
from .base import Event
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..bot import MiraiBot as Bot
|
from ..bot import Bot
|
||||||
|
|
||||||
|
|
||||||
class RequestEvent(Event):
|
class RequestEvent(Event):
|
||||||
|
@ -257,12 +257,14 @@ class MessageSegment(BaseMessageSegment):
|
|||||||
:参数:
|
:参数:
|
||||||
|
|
||||||
* ``name: str``: 戳一戳的类型
|
* ``name: str``: 戳一戳的类型
|
||||||
- "Poke": 戳一戳
|
|
||||||
- "ShowLove": 比心
|
* ``Poke``: 戳一戳
|
||||||
- "Like": 点赞
|
* ``ShowLove``: 比心
|
||||||
- "Heartbroken": 心碎
|
* ``Like``: 点赞
|
||||||
- "SixSixSix": 666
|
* ``Heartbroken``: 心碎
|
||||||
- "FangDaZhao": 放大招
|
* ``SixSixSix``: 666
|
||||||
|
* ``FangDaZhao``: 放大招
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return cls(type=MessageType.POKE, name=name)
|
return cls(type=MessageType.POKE, name=name)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user