Skip to content

Commit dda2679

Browse files
committed
add docstrings everywhere
1 parent cc4e238 commit dda2679

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

nightwatch/bot/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ class AuthorizationFailed(Exception):
1717

1818
# Handle state
1919
class ClientState:
20+
"""The current client state. Includes data such as the user list, chat logs, and websocket connection."""
2021
def __init__(self) -> None:
2122
self.user_list: list[User]
2223
self.chat_logs: list[Message]
2324
self.rics_info: dict[str, str]
2425
self.socket : ClientConnection
2526

2627
class Context:
28+
"""An object to store data about the current event context."""
2729
def __init__(
2830
self,
2931
state: ClientState,
@@ -54,21 +56,26 @@ def __repr__(self) -> str:
5456

5557
# Main client class
5658
class Client:
59+
"""The main client class, override events on this class and call :run: to start the client."""
5760
def __init__(self) -> None:
5861
self.__state = ClientState()
5962
self.__session = requests.Session()
6063

6164
# Events (for overwriting)
6265
async def on_connect(self, ctx: Context) -> None:
66+
"""Listen to the :connect: event."""
6367
pass
6468

6569
async def on_message(self, ctx: Context) -> None:
70+
"""Listen to the :message: event."""
6671
pass
6772

6873
async def on_join(self, ctx: Context) -> None:
74+
"""Listen to the :join: event."""
6975
pass
7076

7177
async def on_leave(self, ctx: Context) -> None:
78+
"""Listen to the :leave: event."""
7279
pass
7380

7481
# Handle running

nightwatch/bot/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,38 @@ def from_dict(cls: typing.Type[T], data: dict) -> T:
2828
@dataclass
2929
class User:
3030
name: str
31+
"""The name of this user."""
3132
hex: str
33+
"""The hex color code of this user, without a leading hashtag."""
3234
admin: bool
35+
"""Status of whether or not this user is an admin."""
3336
bot: bool
37+
"""Status of whether or not this user is a bot."""
3438

3539
def __repr__(self) -> str:
3640
return f"<User name='{self.name}' hex='{self.hex}' admin={self.admin} bot={self.bot}>"
3741

3842
@dataclass
3943
class Message:
4044
user: User
45+
"""The :User: object who sent this message."""
4146
message: str
47+
"""The raw text content of this message."""
4248
time: int
49+
"""The time this message was sent in seconds since the epoch."""
4350

4451
def __repr__(self) -> str:
4552
return f"<Message user='{self.user}' message='{self.message}' time={self.time}>"
4653

4754
@dataclass
4855
class RicsInfo:
4956
name: str
57+
"""The name of the RICS server we are connected to."""
5058
users: list[User]
59+
"""List of :User: objects that are connected to this server."""
5160
chat_logs: list[Message]
61+
"""List of :Message: objects consisting of chat logs.
62+
This will be the last 25 messages sent if you just joined, otherwise it will build over time."""
5263

5364
def __repr__(self) -> str:
5465
return f"<RicsInfo name='{self.name}' users=[...] chat_logs=[...]>"

0 commit comments

Comments
 (0)