From ac8cefd779de5c109a1ddf85f174cbd849585f56 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 6 May 2024 16:47:21 -0400 Subject: [PATCH] fix(aurora): pylint fixes --- aurora/aurora.py | 18 ++++++++++++------ aurora/importers/galacticbot.py | 4 ++-- aurora/models.py | 16 ++++++---------- aurora/utilities/factory.py | 11 ++++------- aurora/utilities/json.py | 1 - aurora/utilities/utils.py | 6 +++--- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index cacee63..6e2e2fc 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -20,7 +20,8 @@ from redbot.core import app_commands, commands, data_manager from redbot.core.app_commands import Choice from redbot.core.bot import Red from redbot.core.commands.converter import parse_relativedelta, parse_timedelta -from redbot.core.utils.chat_formatting import box, error, humanize_list, humanize_timedelta, warning +from redbot.core.utils.chat_formatting import (box, error, humanize_list, + humanize_timedelta, warning) from aurora.importers.aurora import ImportAuroraView from aurora.importers.galacticbot import ImportGalacticBotView @@ -31,10 +32,17 @@ from aurora.menus.overrides import Overrides from aurora.models import Change, Moderation from aurora.utilities.config import config, register_config from aurora.utilities.database import connect, create_guild_table -from aurora.utilities.factory import addrole_embed, case_factory, changes_factory, evidenceformat_factory, guild_embed, immune_embed, message_factory, overrides_embed +from aurora.utilities.factory import (addrole_embed, case_factory, + changes_factory, evidenceformat_factory, + guild_embed, immune_embed, + message_factory, overrides_embed) + from aurora.utilities.json import dump from aurora.utilities.logger import logger -from aurora.utilities.utils import check_moddable, check_permissions, get_footer_image, log, send_evidenceformat, timedelta_from_relativedelta +from aurora.utilities.utils import (check_moddable, check_permissions, + get_footer_image, log, send_evidenceformat, + timedelta_from_relativedelta) + class Aurora(commands.Cog): """Aurora is a fully-featured moderation system. @@ -1327,9 +1335,7 @@ class Aurora(commands.Cog): embed=embed, ephemeral=ephemeral ) elif evidenceformat: - content = await evidenceformat_factory( - interaction=interaction, moderation=mod - ) + content = await evidenceformat_factory(moderation=mod) await interaction.response.send_message( content=content, ephemeral=ephemeral ) diff --git a/aurora/importers/galacticbot.py b/aurora/importers/galacticbot.py index 574d5ad..4cdc42e 100644 --- a/aurora/importers/galacticbot.py +++ b/aurora/importers/galacticbot.py @@ -100,13 +100,13 @@ class ImportGalacticBotView(ui.View): if resolved_timestamp is None: resolved_timestamp = timestamp changes = [ - Change.from_dict({ + Change.from_dict(interaction.client, { "type": "ORIGINAL", "reason": case["reason"], "user_id": case["executor"], "timestamp": timestamp, }), - Change.from_dict({ + Change.from_dict(interaction.client, { "type": "RESOLVE", "reason": resolved_reason, "user_id": resolved_by, diff --git a/aurora/models.py b/aurora/models.py index f5f758b..ab63be1 100644 --- a/aurora/models.py +++ b/aurora/models.py @@ -19,7 +19,7 @@ class AuroraBaseModel(BaseModel): bot: Red def to_json(self, indent: int = None, file: Any = None, **kwargs): - from aurora.utilities.json import dump, dumps + from aurora.utilities.json import dump, dumps # pylint: disable=cyclic-import return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs) class AuroraGuildModel(AuroraBaseModel): @@ -27,7 +27,7 @@ class AuroraGuildModel(AuroraBaseModel): guild_id: int def to_json(self, indent: int = None, file: Any = None, **kwargs): - from aurora.utilities.json import dump, dumps + from aurora.utilities.json import dump, dumps # pylint: disable=cyclic-import return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs) class Moderation(AuroraGuildModel): @@ -66,8 +66,7 @@ class Moderation(AuroraGuildModel): async def get_target(self) -> Union["PartialUser", "PartialChannel"]: if self.target_type == "USER": return await PartialUser.from_id(self.bot, self.target_id) - else: - return await PartialChannel.from_id(self.bot, self.target_id) + return await PartialChannel.from_id(self.bot, self.target_id) async def get_resolved_by(self) -> Optional["PartialUser"]: if self.resolved_by: @@ -264,10 +263,7 @@ class Moderation(AuroraGuildModel): end_timestamp = None if not expired: - if timestamp > end_timestamp: - expired = True - else: - expired = False + expired = bool(timestamp > end_timestamp) if reason == "NULL": reason = None @@ -422,7 +418,7 @@ class PartialChannel(AuroraGuildModel): @property def mention(self): - if self.name == "Deleted Channel" or self.name == "Forbidden Channel": + if self.name in ["Deleted Channel", "Forbidden Channel"]: return self.name return f"<#{self.id}>" @@ -448,7 +444,7 @@ class PartialRole(AuroraGuildModel): @property def mention(self): - if self.name == "Deleted Role" or self.name == "Forbidden Role": + if self.name in ["Deleted Role", "Forbidden Role"]: return self.name return f"<@&{self.id}>" diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index 5977f26..11d00b9 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -2,16 +2,13 @@ from datetime import datetime, timedelta from typing import Union -from discord import (Color, Embed, Guild, Interaction, InteractionMessage, - Member, Role, User) +from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User from redbot.core import commands -from redbot.core.utils.chat_formatting import (bold, box, error, - humanize_timedelta, warning) +from redbot.core.utils.chat_formatting import bold, box, error, humanize_timedelta, warning from aurora.models import Moderation, PartialUser from aurora.utilities.config import config -from aurora.utilities.utils import (get_bool_emoji, get_next_case_number, - get_pagesize_str) +from aurora.utilities.utils import get_bool_emoji, get_next_case_number, get_pagesize_str async def message_factory( @@ -261,7 +258,7 @@ async def changes_factory(interaction: Interaction, moderation: Moderation) -> E return embed -async def evidenceformat_factory(interaction: Interaction, moderation: Moderation) -> str: +async def evidenceformat_factory(moderation: Moderation) -> str: """This function creates a codeblock in evidence format from set parameters. Args: diff --git a/aurora/utilities/json.py b/aurora/utilities/json.py index cad264e..554679d 100644 --- a/aurora/utilities/json.py +++ b/aurora/utilities/json.py @@ -3,7 +3,6 @@ from datetime import datetime, timedelta from redbot.core.bot import Red - from aurora.models import AuroraBaseModel diff --git a/aurora/utilities/utils.py b/aurora/utilities/utils.py index bf3f23b..ca9cc85 100644 --- a/aurora/utilities/utils.py +++ b/aurora/utilities/utils.py @@ -133,7 +133,7 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal logging_channel = interaction.guild.get_channel(logging_channel_id) try: - moderation = Moderation.from_sql(interaction.client, moderation_id) + moderation = Moderation.from_sql(interaction.client, moderation_id, interaction.guild_id) embed = await log_factory( interaction=interaction, moderation=moderation, resolved=resolved ) @@ -158,8 +158,8 @@ async def send_evidenceformat(interaction: Interaction, moderation_id: int) -> N if send_evidence_bool is False: return - moderation = Moderation.from_sql(interaction.client, moderation_id) - content = await evidenceformat_factory(interaction=interaction, moderation=moderation) + moderation = Moderation.from_sql(interaction.client, moderation_id, interaction.guild.id) + content = await evidenceformat_factory(moderation=moderation) await interaction.followup.send(content=content, ephemeral=True)