redo guild docstrings.

This commit is contained in:
alwayscompiling
2022-08-01 22:38:32 -04:00
parent 3ce9f8090f
commit 2515b90497
2 changed files with 105 additions and 20 deletions
+104 -19
View File
@@ -9,6 +9,13 @@ class Guild:
"""Stores a guild's information.""" """Stores a guild's information."""
def __init__(self, guild_id: int) -> None: def __init__(self, guild_id: int) -> None:
"""
Default constructor for Guild class. Initializes channel ids as 0 as they won't be
registered yet. Sets default username length of 12.
Args:
guild_id (int): Discord Guild id of new Guild
"""
self._guild_id: int = guild_id self._guild_id: int = guild_id
self._highscore_channel_id: int = 0 self._highscore_channel_id: int = 0
self._submission_channel_id: int = 0 self._submission_channel_id: int = 0
@@ -17,11 +24,26 @@ class Guild:
self._verification_channel_id: int = 0 self._verification_channel_id: int = 0
def __str__(self) -> str: def __str__(self) -> str:
"""
Returns Guild class as a string for printing.
Returns:
str: Guild class as a string
"""
return json.dumps(self.to_dict(), indent=4) return json.dumps(self.to_dict(), indent=4)
@classmethod @classmethod
def from_dict(cls, guild_id: int, data: dict): def from_dict(cls, guild_id: int, data: dict):
"""Fills out Guild object based off of passed data.""" """
Creates a Guild class from the passed data.
Args:
guild_id (int): Guild's id
data (dict): Rest of Guild data in dictionary format
Returns:
Guild: Populated Guild object
"""
guild = cls(guild_id) guild = cls(guild_id)
guild.highscore_channel = data["highscore_channel_id"] guild.highscore_channel = data["highscore_channel_id"]
guild.submission_channel = data["submission_channel_id"] guild.submission_channel = data["submission_channel_id"]
@@ -36,72 +58,135 @@ class Guild:
@property @property
def guild_id(self) -> int: def guild_id(self) -> int:
"""Getter for Guild id.""" """
return self._guild_id Getter for Guild id
@guild_id.setter Returns:
def guild_id(self, guild_id: int) -> None: int: Guild id
"""Setter for Guild id.""" """
self._guild_id = guild_id return self._guild_id
@property @property
def highscore_channel(self) -> int: def highscore_channel(self) -> int:
"""Getter for highscore channel id.""" """
Getter for highscore channel id.
Returns:
int: highscore channel id
"""
return self._highscore_channel_id return self._highscore_channel_id
@highscore_channel.setter @highscore_channel.setter
def highscore_channel(self, channel: int) -> None: def highscore_channel(self, channel: int) -> None:
"""Setter for highscore channel id.""" """
Setter for highscore channel id.
Args:
channel (int): highscore channel id
"""
self._highscore_channel_id = channel self._highscore_channel_id = channel
@property @property
def submission_channel(self) -> int: def submission_channel(self) -> int:
"""Getter for submission channel id.""" """
Getter for submission channel id.
Returns:
int: submission channel id
"""
return self._submission_channel_id return self._submission_channel_id
@submission_channel.setter @submission_channel.setter
def submission_channel(self, channel: id) -> None: def submission_channel(self, channel: id) -> None:
"""Setter for submission channel id.""" """
Setter fro submission channel id.
Args:
channel (id): submission channel id
"""
self._submission_channel_id = channel self._submission_channel_id = channel
@property @property
def tables(self) -> "list[Table]": def tables(self) -> "list[Table]":
"""Getter for list of tables in Guild.""" """
Getter for Tables list.
Returns:
list[Table]: List of Tables in this Guild
"""
return self._table_map.values() return self._table_map.values()
@property @property
def username_length(self) -> int: def username_length(self) -> int:
"""Getter for username length.""" """
Getter for username length.
Returns:
int: username length
"""
return self._username_length return self._username_length
@username_length.setter @username_length.setter
def username_length(self, length: int) -> None: def username_length(self, length: int) -> None:
"""Setter for username length.""" """
Setter for username length.
Args:
length (int): username length
"""
self._username_length = length self._username_length = length
@property @property
def verification_channel(self) -> int: def verification_channel(self) -> int:
"""Getter for verification channel id.""" """
Getter for verification channel id.
Returns:
int: verification channel id
"""
return self._verification_channel_id return self._verification_channel_id
@verification_channel.setter @verification_channel.setter
def verification_channel(self, channel: int) -> None: def verification_channel(self, channel: int) -> None:
"""Setter for verification channel id.""" """
Setter for verification channel id
Args:
channel (int): verification channel id
"""
self._verification_channel_id = channel self._verification_channel_id = channel
def add_table(self, table: Table) -> None: def add_table(self, table: Table) -> None:
"""Adds a table to table_map if it is not there.""" """
Adds a Table to table map. Shouldn't exist already.
Args:
table (Table): new Table to add
"""
if table.name not in self._table_map: if table.name not in self._table_map:
self._table_map[table.name] = table self._table_map[table.name] = table
def get_table(self, table_name: str) -> Table: def get_table(self, table_name: str) -> Table:
"""Getter for specific table.""" """
return self._table_map[table_name] Getter for specific Table. Returns None if Table is not found.
Args:
table_name (str): Name of Table to find
Returns:
Table: Table corresponding to Name. None if not found.
"""
if table_name in self._table_map:
return self._table_map[table_name]
return None
def to_dict(self) -> dict: def to_dict(self) -> dict:
""" """
Creates python dictionary object from class data. Creates python dictionary object from class data.
Does not include guild_id in dict, it should be the key of above data structure. Does not include guild_id in dict, it should be the key of above data structure.
Returns:
dict: Guild class in dictionary format
""" """
data: dict = {} data: dict = {}
+1 -1
View File
@@ -95,7 +95,7 @@ class Table:
Adds a Category to categories map. Shouldn't exist already. Adds a Category to categories map. Shouldn't exist already.
Args: Args:
category (Category): Category to add category (Category): New Category to add
""" """
if category.name not in self._categories_map: if category.name not in self._categories_map:
self._categories_map[category.name] = category self._categories_map[category.name] = category