|
30 | 30 | import logging
|
31 | 31 | import typing
|
32 | 32 |
|
33 |
| -import aiohttp |
34 | 33 | from multidict import CIMultiDict
|
35 | 34 |
|
36 | 35 | from . import __version__, utils
|
37 |
| -from .adapter import HTTPWebSocket, HTTPAdapter, AIOHTTPAdapter |
| 36 | +from .adapter import WebSocketConnectionFailure, HTTPWebSocket, HTTPAdapter, AIOHTTPAdapter |
38 | 37 | from .core import ULIDOr, resolve_id
|
39 | 38 | from .enums import ShardFormat
|
40 | 39 | from .errors import PyvoltException, ShardClosedError, AuthenticationError, ConnectError
|
|
44 | 43 |
|
45 | 44 | from . import raw
|
46 | 45 | from .channel import TextableChannel
|
| 46 | + from .message import BaseMessage |
47 | 47 | from .server import BaseServer
|
48 | 48 | from .state import State
|
49 | 49 |
|
@@ -251,6 +251,36 @@ async def subscribe_to(self, server: ULIDOr[BaseServer], /) -> None:
|
251 | 251 | """
|
252 | 252 | ...
|
253 | 253 |
|
| 254 | + @abstractmethod |
| 255 | + async def begin_editing(self, channel: ULIDOr[TextableChannel], message: ULIDOr[BaseMessage]) -> None: |
| 256 | + """|coro| |
| 257 | +
|
| 258 | + Begins editing a message. |
| 259 | +
|
| 260 | + Parameters |
| 261 | + ---------- |
| 262 | + channel: ULIDOr[:class:`.TextableChannel`] |
| 263 | + The channel the message was sent in. |
| 264 | + message: ULIDOr[:class:`.BaseMessage`] |
| 265 | + The message to begin editing. |
| 266 | + """ |
| 267 | + ... |
| 268 | + |
| 269 | + @abstractmethod |
| 270 | + async def stop_editing(self, channel: ULIDOr[TextableChannel], message: ULIDOr[BaseMessage]) -> None: |
| 271 | + """|coro| |
| 272 | +
|
| 273 | + Stops editing a message. |
| 274 | +
|
| 275 | + Parameters |
| 276 | + ---------- |
| 277 | + channel: ULIDOr[:class:`.TextableChannel`] |
| 278 | + The channel the message was sent in. |
| 279 | + message: ULIDOr[:class:`.BaseMessage`] |
| 280 | + The message to stop editing. |
| 281 | + """ |
| 282 | + ... |
| 283 | + |
254 | 284 | @abstractmethod
|
255 | 285 | async def connect(self) -> None:
|
256 | 286 | """Starts the WebSocket lifecycle."""
|
@@ -479,12 +509,28 @@ async def subscribe_to(self, server: ULIDOr[BaseServer], /) -> None:
|
479 | 509 | payload: raw.ServerSubscribeEvent = {'type': 'Subscribe', 'server_id': resolve_id(server)}
|
480 | 510 | await self.send(payload)
|
481 | 511 |
|
| 512 | + async def begin_editing(self, channel: ULIDOr[TextableChannel], message: ULIDOr[BaseMessage]) -> None: |
| 513 | + payload: raw.ServerBeginEditingEvent = { |
| 514 | + 'type': 'BeginEditing', |
| 515 | + 'channel': resolve_id(channel), |
| 516 | + 'message': resolve_id(message), |
| 517 | + } |
| 518 | + await self.send(payload) |
| 519 | + |
| 520 | + async def stop_editing(self, channel: ULIDOr[TextableChannel], message: ULIDOr[BaseMessage]) -> None: |
| 521 | + payload: raw.ServerStopEditingEvent = { |
| 522 | + 'type': 'StopEditing', |
| 523 | + 'channel': resolve_id(channel), |
| 524 | + 'message': resolve_id(message), |
| 525 | + } |
| 526 | + await self.send(payload) |
| 527 | + |
482 | 528 | async def _send_json(self, d: raw.ServerEvent, /) -> None:
|
483 |
| - _L.debug('sending %s', d) |
| 529 | + _L.debug('Sending %s', d) |
484 | 530 | await self.socket.send_str(utils.to_json(d))
|
485 | 531 |
|
486 | 532 | async def _send_msgpack(self, d: raw.ServerEvent, /) -> None:
|
487 |
| - _L.debug('sending %s', d) |
| 533 | + _L.debug('Sending %s', d) |
488 | 534 |
|
489 | 535 | # Will never none according to stubs: https://github.com/sbdchd/msgpack-types/blob/a9ab1c861933fa11aff706b21c303ee52a2ee359/msgpack-stubs/__init__.pyi#L40-L49
|
490 | 536 | payload: bytes = msgpack.packb(d) # type: ignore
|
@@ -595,9 +641,9 @@ async def _socket_connect(self) -> HTTPWebSocket[typing.Any]:
|
595 | 641 | if exc.errno == 11001:
|
596 | 642 | await asyncio.sleep(1)
|
597 | 643 | i += 1
|
598 |
| - except aiohttp.WSServerHandshakeError as exc: |
599 |
| - _L.debug('Server replied with %i', exc.code) |
600 |
| - if exc.code in (502, 525): |
| 644 | + except WebSocketConnectionFailure as exc: |
| 645 | + _L.debug('Server replied with %i', exc.status) |
| 646 | + if exc.status in (502, 525): |
601 | 647 | await asyncio.sleep(1.5)
|
602 | 648 | continue
|
603 | 649 | raise exc from None
|
|
0 commit comments