From e1cc6ca1a89ad6d9ef5c91d444d4bc2bc2d7e057 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 30 Dec 2023 04:10:25 -0500 Subject: [PATCH] fix(aurora): fixed JSON serializing error in `/edit` command --- aurora/aurora.py | 4 ++-- aurora/utilities/database.py | 8 ++------ aurora/utilities/utils.py | 9 +++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 4bef46a..ae1da8d 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -25,7 +25,7 @@ from .utilities.config import config, register_config from .utilities.database import connect, create_guild_table, fetch_case, mysql_log from .utilities.embed_factory import embed_factory from .utilities.logger import logger -from .utilities.utils import check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat +from .utilities.utils import convert_timedelta_to_str, check_moddable, check_permissions, fetch_channel_dict, fetch_user_dict, generate_dict, log, send_evidenceformat class Aurora(commands.Cog): @@ -898,7 +898,7 @@ class Aurora(commands.Cog): 'timestamp': int(time.time()), 'reason': reason, 'user_id': interaction.user.id, - 'duration': parsed_time, + 'duration': convert_timedelta_to_str(parsed_time), 'end_timestamp': end_timestamp } ) diff --git a/aurora/utilities/database.py b/aurora/utilities/database.py index c501c2f..18b4de2 100644 --- a/aurora/utilities/database.py +++ b/aurora/utilities/database.py @@ -9,7 +9,7 @@ from discord import Guild from redbot.core import data_manager from .logger import logger -from .utils import generate_dict, get_next_case_number +from .utils import generate_dict, get_next_case_number, convert_timedelta_to_str def connect() -> sqlite3.Connection: @@ -128,11 +128,7 @@ async def mysql_log( end_timedelta = datetime.fromtimestamp(timestamp) + duration end_timestamp = int(end_timedelta.timestamp()) - total_seconds = int(duration.total_seconds()) - hours = total_seconds // 3600 - minutes = (total_seconds % 3600) // 60 - seconds = total_seconds % 60 - duration = f"{hours}:{minutes}:{seconds}" + duration = convert_timedelta_to_str(duration) else: end_timestamp = 0 diff --git a/aurora/utilities/utils.py b/aurora/utilities/utils.py index 3a52f91..87173c8 100644 --- a/aurora/utilities/utils.py +++ b/aurora/utilities/utils.py @@ -1,6 +1,7 @@ # pylint: disable=cyclic-import import json +from datetime import timedelta as td from typing import Union from discord import Guild, Interaction, Member, User @@ -221,3 +222,11 @@ async def send_evidenceformat(interaction: Interaction, case_dict: dict): "evidenceformat", await interaction.client.get_embed_color(None), interaction=interaction, case_dict=case_dict ) await interaction.followup.send(content=content, ephemeral=True) + +def convert_timedelta_to_str(timedelta: td): + """This function converts a timedelta object to a string.""" + total_seconds = int(timedelta.total_seconds()) + hours = total_seconds // 3600 + minutes = (total_seconds % 3600) // 60 + seconds = total_seconds % 60 + return f"{hours}:{minutes}:{seconds}"