From 539052eb0048b7f42248b6d42e18dfdbb6c5780c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Fri, 5 Jan 2024 06:00:45 +0000 Subject: [PATCH] misc(aurora): removed ``` from all of the files that had it, replaced with redbot.core.utils.chat_formatting.box() --- .gitignore | 1 + aurora/aurora.py | 5 +++-- aurora/importers/aurora.py | 3 ++- aurora/importers/galacticbot.py | 3 ++- aurora/utilities/embed_factory.py | 18 +++++++++--------- 5 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16d3c4d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.cache diff --git a/aurora/aurora.py b/aurora/aurora.py index e3cd482..3b2c8ed 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -18,6 +18,7 @@ from discord.ext import tasks from pytimeparse2 import disable_dateutil, parse from redbot.core import app_commands, checks, commands, data_manager from redbot.core.app_commands import Choice +from redbot.core.utils.chat_formatting import box from .importers.galacticbot import ImportGalacticBotView from .importers.aurora import ImportAuroraView @@ -601,7 +602,7 @@ class Aurora(commands.Cog): os.remove(filename) except json.JSONDecodeError as e: - await interaction.followup.send(content=f"An error occured while exporting the moderation history.\nError:\n```{e}```", ephemeral=ephemeral) + await interaction.followup.send(content=f"An error occured while exporting the moderation history.\nError:\n" + box(e, 'py'), ephemeral=ephemeral) cursor.close() database.close() return @@ -825,7 +826,7 @@ class Aurora(commands.Cog): os.remove(filename) return - await interaction.response.send_message(content=f"```json\n{json.dumps(case_dict, indent=2)}```", ephemeral=ephemeral) + await interaction.response.send_message(content=box({json.dumps(case_dict, indent=2)}), ephemeral=ephemeral) return if changes: embed = await embed_factory('changes', await self.bot.get_embed_color(None), interaction=interaction, case_dict=case_dict) diff --git a/aurora/importers/aurora.py b/aurora/importers/aurora.py index ac26f83..49ae584 100644 --- a/aurora/importers/aurora.py +++ b/aurora/importers/aurora.py @@ -4,6 +4,7 @@ from typing import Dict from discord import ButtonStyle, Interaction, Message, ui from redbot.core import commands +from redbot.core.utils.chat_formatting import box from ..utilities.database import connect, create_guild_table, mysql_log @@ -100,7 +101,7 @@ class ImportAuroraView(ui.View): await interaction.edit_original_response(content="Import complete.") if failed_cases: await interaction.edit_original_response( - content=f"Import complete.\n*Failed to import the following cases:*\n```{failed_cases}```" + content=f"Import complete.\n*Failed to import the following cases:*\n" + box(failed_cases) ) @ui.button(label="No", style=ButtonStyle.danger) diff --git a/aurora/importers/galacticbot.py b/aurora/importers/galacticbot.py index 1c7ae76..38aa746 100644 --- a/aurora/importers/galacticbot.py +++ b/aurora/importers/galacticbot.py @@ -3,6 +3,7 @@ from datetime import timedelta from discord import ButtonStyle, Interaction, Message, ui from redbot.core import commands +from redbot.core.utils.chat_formatting import box from ..utilities.database import connect, create_guild_table, mysql_log @@ -136,7 +137,7 @@ class ImportGalacticBotView(ui.View): await interaction.edit_original_response(content="Import complete.") if failed_cases: - await interaction.edit_original_response(content=f"Import complete.\n*Failed to import the following cases:*\n```{failed_cases}```") + await interaction.edit_original_response(content=f"Import complete.\n*Failed to import the following cases:*\n" + box(failed_cases)) @ui.button(label="No", style=ButtonStyle.danger) async def import_button_n(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument diff --git a/aurora/utilities/embed_factory.py b/aurora/utilities/embed_factory.py index 7f55f1f..61b0f21 100644 --- a/aurora/utilities/embed_factory.py +++ b/aurora/utilities/embed_factory.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta import humanize from discord import Color, Embed, Guild, Interaction, InteractionMessage, User, Member +from redbot.core.utils.chat_formatting import box from .config import config from .utils import fetch_channel_dict, fetch_user_dict, get_next_case_number @@ -35,7 +36,6 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact Required arguments for 'case', 'changes', and `evidenceformat`: - interaction - case_dict""" - codeblock = '```' if embed_type == 'message': if moderation_type in ["kicked", "banned", "tempbanned", "unbanned"]: @@ -97,12 +97,12 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact if case_dict['metadata']['imported_from']: embed.description += f"\n**Imported From:** {case_dict['metadata']['imported_from']}" - embed.add_field(name='Reason', value=f"{codeblock}{case_dict['reason']}{codeblock}", inline=False) + embed.add_field(name='Reason', value=box(case_dict['reason']), inline=False) if case_dict['resolved'] == 1: resolved_user = await fetch_user_dict(interaction, case_dict['resolved_by']) resolved_name = f"`{resolved_user['name']}`" if resolved_user['discriminator'] == "0" else f"`{resolved_user['name']}#{resolved_user['discriminator']}`" - embed.add_field(name='Resolve Reason', value=f"Resolved by {resolved_name} ({resolved_user['id']}) for:\n{codeblock}{case_dict['resolve_reason']}{codeblock}", inline=False) + embed.add_field(name='Resolve Reason', value=f"Resolved by {resolved_name} ({resolved_user['id']}) for:\n{box}{case_dict['resolve_reason']}", inline=False) return embed @@ -147,16 +147,16 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact moderator_user = await fetch_user_dict(interaction, case_dict['moderator_id']) moderator_name = moderator_user['name'] if moderator_user['discriminator'] == "0" else f"{moderator_user['name']}#{moderator_user['discriminator']}" - content = f"{codeblock}prolog\nCase: {case_dict['moderation_id']:,} ({str.title(case_dict['moderation_type'])})\nTarget: {target_name} ({target_user['id']})\nModerator: {moderator_name} ({moderator_user['id']})" + content = f"Case: {case_dict['moderation_id']:,} ({str.title(case_dict['moderation_type'])})\nTarget: {target_name} ({target_user['id']})\nModerator: {moderator_name} ({moderator_user['id']})" if case_dict['duration'] != 'NULL': hours, minutes, seconds = map(int, case_dict['duration'].split(':')) td = timedelta(hours=hours, minutes=minutes, seconds=seconds) content += f"\nDuration: {humanize.precisedelta(td)}" - content += f"\nReason: {case_dict['reason']}{codeblock}" + content += f"\nReason: {case_dict['reason']}" - return content + return box(content, 'prolog') if embed_type == 'log': if resolved: @@ -182,11 +182,11 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact duration_embed = f"{humanize.precisedelta(td)} | " if case_dict["expired"] == '0' else str(humanize.precisedelta(td)) embed.description = embed.description + f"\n**Duration:** {duration_embed}\n**Expired:** {bool(case_dict['expired'])}" - embed.add_field(name='Reason', value=f"{codeblock}{case_dict['reason']}{codeblock}", inline=False) + embed.add_field(name='Reason', value=box(case_dict['reason']), inline=False) resolved_user = await fetch_user_dict(interaction, case_dict['resolved_by']) resolved_name = resolved_user['name'] if resolved_user['discriminator'] == "0" else f"{resolved_user['name']}#{resolved_user['discriminator']}" - embed.add_field(name='Resolve Reason', value=f"Resolved by {resolved_name} ({resolved_user['id']}) for:\n{codeblock}{case_dict['resolve_reason']}{codeblock}", inline=False) + embed.add_field(name='Resolve Reason', value=f"Resolved by {resolved_name} ({resolved_user['id']}) for:\n" + box(case_dict['resolve_reason']), inline=False) else: if case_dict['target_type'] == 'USER': target_user = await fetch_user_dict(interaction, case_dict['target_id']) @@ -208,7 +208,7 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact td = timedelta(**{unit: int(val) for unit, val in zip(["hours", "minutes", "seconds"], case_dict["duration"].split(":"))}) embed.description = embed.description + f"\n**Duration:** {humanize.precisedelta(td)} | " - embed.add_field(name='Reason', value=f"{codeblock}{case_dict['reason']}{codeblock}", inline=False) + embed.add_field(name='Reason', value=box(case_dict['reason']), inline=False) return embed raise(TypeError("'type' argument is invalid!"))