Update guild listener to use new database. Add default config function to utils.

This commit is contained in:
alwayscompiling
2022-11-30 21:45:46 -05:00
parent 18df783d86
commit 9531dca892
2 changed files with 37 additions and 11 deletions
+29
View File
@@ -2,6 +2,7 @@
Contains various utlity functions for highscores bot
"""
import json
import time
import nextcord
@@ -168,6 +169,7 @@ def format_highscore_message(group: CategoryGroup) -> str:
category_ids.append(cat.CategoryId)
# get all scores in category group, load into data frame.
# FIXME there is some slice warning here from pandas.
d_f = pd.read_sql_query(sql=session.query(Score).where(Score.CategoryId.in_(category_ids)).statement, con=engine)
# this list is what will be printed in the discord message
@@ -306,3 +308,30 @@ async def submit_score(
assert channel is not None, await interaction.send(error_response, ephemeral=True)
await send_highscore_message(channel, group)
def add_preset_configuration(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
"""
with open(f"example_config/{config_str}.json", encoding="utf-8", mode="r") as file:
config = json.load(file)
for group_name, categorys in config["tables"].items():
group_obj = CategoryGroup(GroupName=group_name, GuildId=guild_id)
session.add(group_obj)
for category_name in categorys:
cat_obj = Category(
CategoryName=category_name,
Size=config["table_size"],
IsTimeRecord=config["categories"][category_name]["is_time_record"],
IsAscending=config["categories"][category_name]["ascending"],
)
session.add(cat_obj)
session.commit()