Added temporary config handling.
This commit is contained in:
@@ -18,6 +18,8 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
async def on_guild_join(self, guild: nextcord.Guild):
|
||||
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
|
||||
highscores_data.add_guild(guild.id)
|
||||
# This add config will be removed eventually. Config adding will have to be controlled by commands.
|
||||
highscores_data.add_configuration(guild.id, "runescape")
|
||||
highscores_data.save_guild_data(highscores_data.get_guild(guild.id))
|
||||
|
||||
welcome_message: str = "Hello, I keep track of Highscores for you!"
|
||||
|
||||
+26
-1
@@ -4,6 +4,8 @@ import os
|
||||
import json
|
||||
|
||||
from data.guild import Guild # pylint: disable=import-error
|
||||
from data.table import Table # pylint: disable=import-error
|
||||
from data.category import Category # pylint: disable=import-error
|
||||
|
||||
|
||||
HIGHSCORES_BACKUP_DIR = "deleted_backups"
|
||||
@@ -48,6 +50,29 @@ class HighscoresData:
|
||||
"""
|
||||
return self._guild_map.values()
|
||||
|
||||
def add_configuration(self, guild_id: int, config_str: str) -> None:
|
||||
"""
|
||||
Adds an example configuration to a Guild. Uses guild id to know which guild and
|
||||
config name to open a file in example_config.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild id to add config to
|
||||
config_str (str): Config name to add
|
||||
"""
|
||||
config = self._open_highscores_config(config_str)
|
||||
guild = self.get_guild(guild_id)
|
||||
|
||||
for table_name, categorys in config["tables"].items():
|
||||
table_obj = Table(table_name)
|
||||
table_obj.size = config["table_size"]
|
||||
for category_name in categorys:
|
||||
category = Category(category_name)
|
||||
category.ascending = config["categories"][category]["ascending"]
|
||||
category.time_record = config["categories"][category]["is_time_record"]
|
||||
table_obj.add_category(category)
|
||||
|
||||
guild.add_table(table_obj)
|
||||
|
||||
def add_guild(self, guild_id: int) -> None:
|
||||
"""
|
||||
Creates a new Guild and adds to Guild map.
|
||||
@@ -83,7 +108,7 @@ class HighscoresData:
|
||||
f"{HIGHSCORES_DATA_DIR}/{guild_id}.json", f"{HIGHSCORES_BACKUP_DIR}/{guild_id}.json"
|
||||
)
|
||||
|
||||
def open_highscores_config(self, config: str) -> dict:
|
||||
def _open_highscores_config(self, config: str) -> dict:
|
||||
"""
|
||||
Opens the highscores config file and returns in dictionary format.
|
||||
Will be replaced when config class is created.
|
||||
|
||||
Reference in New Issue
Block a user