Skip to content

Commit c54a35c

Browse files
committed
refactor: reorganize the library arch.
This is a decision that the core development team met on. The goal of this refactor is to provide a better and more organized library architecture that is easier to navigate around for us and collaborators wanting to get involved.
1 parent 4e43974 commit c54a35c

File tree

22 files changed

+121
-136
lines changed

22 files changed

+121
-136
lines changed

interactions/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
from .api.models.team import * # noqa: F401 F403
2424
from .api.models.user import * # noqa: F401 F403
2525
from .base import * # noqa: F401 F403
26-
from .client import * # noqa: F401 F403
27-
from .context import * # noqa: F401 F403
28-
from .decor import * # noqa: F401 F403
29-
from .enums import * # noqa: F401 F403
30-
from .models.command import * # noqa: F401 F403
31-
from .models.component import * # noqa: F401 F403
32-
from .models.misc import * # noqa: F401 F403
26+
from .client.bot import * # noqa: F401 F403
27+
from .client.context import * # noqa: F401 F403
28+
from .client.decor import * # noqa: F401 F403
29+
from .client.enums import * # noqa: F401 F403
30+
from .client.models.command import * # noqa: F401 F403
31+
from .client.models.component import * # noqa: F401 F403
32+
from .client.models.misc import * # noqa: F401 F403

interactions/api/enums.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Normal libraries
21
from enum import IntEnum
32

43
# TODO: post-v4: Implement this into the new error system at a later point.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
interactions.api.gateway
3+
4+
This section of the library maintains and
5+
handles all of the Gateway work.
6+
"""
7+
from .client import * # noqa: F401 F403
8+
from .heartbeat import * # noqa: F401 F403

interactions/api/gateway.py renamed to interactions/api/gateway/client.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from json import dumps, loads
55

66
from asyncio import (
7-
AbstractEventLoop,
87
Event,
98
Task,
109
ensure_future,
@@ -20,38 +19,20 @@
2019
from aiohttp import WSMessage, WSMsgType
2120
from aiohttp.http import WS_CLOSED_MESSAGE, WS_CLOSING_MESSAGE
2221

23-
from ..base import get_logger
24-
from ..enums import InteractionType, OptionType
25-
from ..models.command import Option
26-
from .dispatch import Listener
27-
from .enums import OpCodeType
28-
from .error import GatewayException
29-
from .http.client import HTTPClient
30-
from .models.flags import Intents
31-
from .models.misc import MISSING
32-
from .models.presence import ClientPresence
22+
from ...base import get_logger
23+
from ...client.models import Option
24+
from ..dispatch import Listener
25+
from ..enums import InteractionType, OpCodeType, OptionType
26+
from ..error import GatewayException
27+
from ..http.client import HTTPClient
28+
from ..models.flags import Intents
29+
from ..models.misc import MISSING
30+
from ..models.presence import ClientPresence
31+
from .heartbeat import _Heartbeat
3332

3433
log = get_logger("gateway")
3534

36-
__all__ = ("_Heartbeat", "WebSocketClient")
37-
38-
39-
class _Heartbeat:
40-
"""An internal class representing the heartbeat in a WebSocket connection."""
41-
42-
event: Event
43-
delay: float
44-
45-
def __init__(self, loop: AbstractEventLoop) -> None:
46-
"""
47-
:param loop: The event loop to base the asynchronous manager.
48-
:type loop: AbstractEventLoop
49-
"""
50-
try:
51-
self.event = Event(loop=loop) if version_info < (3, 10) else Event()
52-
except TypeError:
53-
pass
54-
self.delay = 0.0
35+
__all__ = "WebSocketClient"
5536

5637

5738
class WebSocketClient:

interactions/api/gateway.pyi renamed to interactions/api/gateway/client.pyi

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ from typing import Any, Dict, List, Optional, Tuple, Union, Iterable
88

99
from aiohttp import ClientWebSocketResponse
1010

11-
from ..models import Option
12-
from ..api.models.misc import MISSING
13-
from ..api.models.presence import ClientPresence
14-
from .dispatch import Listener
15-
from .http.client import HTTPClient
16-
from .models.flags import Intents
11+
from .heartbeat import _Heartbeat
12+
from ...client.models import Option
13+
from ...api.models.misc import MISSING
14+
from ...api.models.presence import ClientPresence
15+
from ..dispatch import Listener
16+
from ..http.client import HTTPClient
17+
from ..models.flags import Intents
1718

1819
log: Logger
1920
__all__: Iterable[str]
2021

21-
class _Heartbeat:
22-
event: Event
23-
delay: float
24-
def __init__(self, loop: AbstractEventLoop) -> None: ...
25-
2622
class WebSocketClient:
2723
_loop: AbstractEventLoop
2824
_dispatch: Listener
@@ -42,7 +38,6 @@ class WebSocketClient:
4238
_last_ack: float
4339
latency: float
4440
ready: Event
45-
4641
def __init__(
4742
self,
4843
token: str,
@@ -53,7 +48,9 @@ class WebSocketClient:
5348
async def _manage_heartbeat(self) -> None: ...
5449
async def __restart(self): ...
5550
async def _establish_connection(
56-
self, shard: Optional[List[Tuple[int]]] = MISSING, presence: Optional[ClientPresence] = MISSING
51+
self,
52+
shard: Optional[List[Tuple[int]]] = MISSING,
53+
presence: Optional[ClientPresence] = MISSING,
5754
) -> None: ...
5855
async def _handle_connection(
5956
self,
@@ -64,7 +61,9 @@ class WebSocketClient:
6461
async def wait_until_ready(self) -> None: ...
6562
def _dispatch_event(self, event: str, data: dict) -> None: ...
6663
def __contextualize(self, data: dict) -> object: ...
67-
def __sub_command_context(self, data: Union[dict, Option], _context: Optional[object] = MISSING) -> Union[Tuple[str], dict]: ...
64+
def __sub_command_context(
65+
self, data: Union[dict, Option], _context: Optional[object] = MISSING
66+
) -> Union[Tuple[str], dict]: ...
6867
def __option_type_context(self, context: object, type: int) -> dict: ...
6968
@property
7069
async def __receive_packet_stream(self) -> Optional[Dict[str, Any]]: ...
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from asyncio import AbstractEventLoop, Event
2+
from sys import version_info
3+
4+
5+
class _Heartbeat:
6+
"""An internal class representing the heartbeat in a WebSocket connection."""
7+
8+
event: Event
9+
delay: float
10+
11+
def __init__(self, loop: AbstractEventLoop) -> None:
12+
"""
13+
:param loop: The event loop to base the asynchronous manager.
14+
:type loop: AbstractEventLoop
15+
"""
16+
try:
17+
self.event = Event(loop=loop) if version_info < (3, 10) else Event()
18+
except TypeError:
19+
pass
20+
self.delay = 0.0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from asyncio import AbstractEventLoop, Event
2+
3+
class _Heartbeat:
4+
event: Event
5+
delay: float
6+
def __init__(self, loop: AbstractEventLoop) -> None: ...

interactions/client/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
interactions.client
3+
4+
This section of the library maintains and
5+
handles all of the client work.
6+
"""
7+
from .bot import * # noqa: F401 F403
8+
from .context import * # noqa: F401 F403
9+
from .decor import * # noqa: F401 F403
10+
from .enums import * # noqa: F401 F403
11+
from .models import * # noqa: F401 F403

interactions/client.py renamed to interactions/client/bot.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
from types import ModuleType
1010
from typing import Any, Callable, Coroutine, Dict, List, Optional, Union
1111

12-
from .api.cache import Cache
13-
from .api.cache import Item as Build
14-
from .api.error import InteractionException, JSONException
15-
from .api.gateway import WebSocketClient
16-
from .api.http.client import HTTPClient
17-
from .api.models.flags import Intents
18-
from .api.models.guild import Guild
19-
from .api.models.misc import MISSING, Snowflake
20-
from .api.models.presence import ClientPresence
21-
from .api.models.team import Application
22-
from .base import get_logger
12+
from ..api.cache import Cache
13+
from ..api.cache import Item as Build
14+
from ..api.error import InteractionException, JSONException
15+
from ..api.gateway import WebSocketClient
16+
from ..api.http.client import HTTPClient
17+
from ..api.models.flags import Intents
18+
from ..api.models.guild import Guild
19+
from ..api.models.misc import MISSING, Snowflake
20+
from ..api.models.presence import ClientPresence
21+
from ..api.models.team import Application
22+
from ..base import get_logger
2323
from .decor import command
2424
from .decor import component as _component
2525
from .enums import ApplicationCommandType, OptionType

interactions/client.pyi renamed to interactions/client/bot.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from asyncio import AbstractEventLoop
22
from types import ModuleType
3-
from typing import Any, Callable, Coroutine, Dict, List, NoReturn, Optional, Tuple, Union
3+
from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple, Union
44

5-
from .api.cache import Cache
6-
from .api.gateway import WebSocketClient
7-
from .api.http.client import HTTPClient
8-
from .api.models.flags import Intents
9-
from .api.models.guild import Guild
10-
from .api.models.misc import MISSING, Snowflake
11-
from .api.models.presence import ClientPresence
12-
from .api.models.team import Application
5+
from ..api.cache import Cache
6+
from ..api.gateway import WebSocketClient
7+
from ..api.http.client import HTTPClient
8+
from ..api.models.flags import Intents
9+
from ..api.models.guild import Guild
10+
from ..api.models.misc import MISSING, Snowflake
11+
from ..api.models.presence import ClientPresence
12+
from ..api.models.team import Application
1313
from .enums import ApplicationCommandType
1414
from .models.command import ApplicationCommand, Option
1515
from .models.component import Button, Modal, SelectMenu

0 commit comments

Comments
 (0)