Created rest of guild functions.
This commit is contained in:
+62
-1
@@ -16,23 +16,54 @@ class Guild:
|
||||
self._username_length: int = 12
|
||||
self._verification_channel_id: int = 0
|
||||
|
||||
# TODO create setters then classmethod from dict. Also need todict and string. Then test creation from json and then editting objects.
|
||||
def __str__(self) -> str:
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, guild_id: int, data: dict):
|
||||
"""Fills out Guild object based off of passed data."""
|
||||
guild = cls(guild_id)
|
||||
guild.highscore_channel = data["highscore_channel_id"]
|
||||
guild.submission_channel = data["submission_channel_id"]
|
||||
guild.username_length = data["username_length"]
|
||||
guild.verification_channel = data["verification_channel_id"]
|
||||
|
||||
for table_name, table_data in data["tables"].items():
|
||||
table = Table.from_dict(table_name, table_data)
|
||||
guild.add_table(table)
|
||||
|
||||
return guild
|
||||
|
||||
@property
|
||||
def guild_id(self) -> int:
|
||||
"""Getter for Guild id."""
|
||||
return self._guild_id
|
||||
|
||||
@guild_id.setter
|
||||
def guild_id(self, guild_id: int) -> None:
|
||||
"""Setter for Guild id."""
|
||||
self._guild_id = guild_id
|
||||
|
||||
@property
|
||||
def highscore_channel(self) -> int:
|
||||
"""Getter for highscore channel id."""
|
||||
return self._highscore_channel_id
|
||||
|
||||
@highscore_channel.setter
|
||||
def highscore_channel(self, channel: int) -> None:
|
||||
"""Setter for highscore channel id."""
|
||||
self._highscore_channel_id = channel
|
||||
|
||||
@property
|
||||
def submission_channel(self) -> int:
|
||||
"""Getter for submission channel id."""
|
||||
return self._submission_channel_id
|
||||
|
||||
@submission_channel.setter
|
||||
def submission_channel(self, channel: id) -> None:
|
||||
"""Setter for submission channel id."""
|
||||
self._submission_channel_id = channel
|
||||
|
||||
@property
|
||||
def tables(self) -> "list[dict]":
|
||||
"""Getter for list of tables in Guild."""
|
||||
@@ -43,7 +74,37 @@ class Guild:
|
||||
"""Getter for username length."""
|
||||
return self._username_length
|
||||
|
||||
@username_length.setter
|
||||
def username_length(self, length: int) -> None:
|
||||
"""Setter for username length."""
|
||||
self._username_length = length
|
||||
|
||||
@property
|
||||
def verification_channel(self) -> int:
|
||||
"""Getter for verification channel id."""
|
||||
return self._verification_channel_id
|
||||
|
||||
@verification_channel.setter
|
||||
def verification_channel(self, channel: int) -> None:
|
||||
"""Setter for verification channel id."""
|
||||
self._verification_channel_id = channel
|
||||
|
||||
def add_table(self, table: Table) -> None:
|
||||
"""Adds a table to table_map if it is not there."""
|
||||
if table.name not in self._table_map:
|
||||
self._table_map[table.name] = table
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Creates python dictionary object from class data."""
|
||||
data: dict = {}
|
||||
|
||||
data["highscore_channel_id"] = self.highscore_channel
|
||||
data["submission_channel_id"] = self.submission_channel
|
||||
data["tables"] = {}
|
||||
data["username_length"] = self.username_length
|
||||
data["verification_channel_id"] = self.verification_channel
|
||||
|
||||
for table in self.tables:
|
||||
data["tables"][table.name] = table.to_dict()
|
||||
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user