misc(repository): black reformat

This commit is contained in:
SeaswimmerTheFsh 2024-02-02 11:22:08 -05:00
parent 519e3056ab
commit fa3b353704
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063
5 changed files with 186 additions and 86 deletions

View file

@ -2,26 +2,27 @@ from redbot.core import Config
config: Config = Config.get_conf(None, identifier=481923957134912, cog_name="Aurora")
def register_config(config_obj: Config):
config_obj.register_guild(
show_moderator = True,
use_discord_permissions = True,
ignore_modlog = True,
ignore_other_bots = True,
dm_users = True,
log_channel = " ",
immune_roles = [],
history_ephemeral = False,
history_inline = False,
history_pagesize = 5,
history_inline_pagesize = 6,
auto_evidenceformat = False,
addrole_whitelist = []
show_moderator=True,
use_discord_permissions=True,
ignore_modlog=True,
ignore_other_bots=True,
dm_users=True,
log_channel=" ",
immune_roles=[],
history_ephemeral=False,
history_inline=False,
history_pagesize=5,
history_inline_pagesize=6,
auto_evidenceformat=False,
addrole_whitelist=[],
)
config_obj.register_user(
history_ephemeral = None,
history_inline = None,
history_pagesize = None,
history_inline_pagesize = None,
auto_evidenceformat = None
history_ephemeral=None,
history_inline=None,
history_pagesize=None,
history_inline_pagesize=None,
auto_evidenceformat=None,
)

View file

@ -1,21 +1,23 @@
# pylint: disable=cyclic-import
import json
import time
import sqlite3
import time
from datetime import datetime, timedelta
from discord import Guild
from redbot.core import data_manager
from .logger import logger
from .utils import generate_dict, get_next_case_number, convert_timedelta_to_str
from .utils import convert_timedelta_to_str, generate_dict, get_next_case_number
def connect() -> sqlite3.Connection:
"""Connects to the SQLite database, and returns a connection object."""
try:
connection = sqlite3.connect(database=data_manager.cog_data_path(raw_name='Aurora') / 'aurora.db')
connection = sqlite3.connect(
database=data_manager.cog_data_path(raw_name="Aurora") / "aurora.db"
)
return connection
except sqlite3.OperationalError as e:
@ -85,8 +87,8 @@ async def create_guild_table(guild: Guild):
"NULL",
"NULL",
0,
json.dumps([]), # pylint: disable=dangerous-default-value
json.dumps({}), # pylint: disable=dangerous-default-value
json.dumps([]), # pylint: disable=dangerous-default-value
json.dumps({}), # pylint: disable=dangerous-default-value
)
cursor.execute(insert_query, insert_values)

View file

@ -4,7 +4,7 @@ import json
from datetime import timedelta as td
from typing import Union
from discord import Guild, Interaction, Member, User, SelectOption
from discord import Guild, Interaction, Member, SelectOption, User
from discord.errors import Forbidden, NotFound
from redbot.core import commands
from redbot.core.utils.chat_formatting import error
@ -46,7 +46,9 @@ async def check_moddable(
"""Checks if a moderator can moderate a target."""
if check_permissions(interaction.client.user, permissions, guild=interaction.guild):
await interaction.response.send_message(
error(f"I do not have the `{permissions}` permission, required for this action."),
error(
f"I do not have the `{permissions}` permission, required for this action."
),
ephemeral=True,
)
return False
@ -54,7 +56,9 @@ async def check_moddable(
if await config.guild(interaction.guild).use_discord_permissions() is True:
if check_permissions(interaction.user, permissions, guild=interaction.guild):
await interaction.response.send_message(
error(f"You do not have the `{permissions}` permission, required for this action."),
error(
f"You do not have the `{permissions}` permission, required for this action."
),
ephemeral=True,
)
return False
@ -74,7 +78,9 @@ async def check_moddable(
if isinstance(target, Member):
if interaction.user.top_role <= target.top_role:
await interaction.response.send_message(
content=error("You cannot moderate members with a higher role than you!"),
content=error(
"You cannot moderate members with a higher role than you!"
),
ephemeral=True,
)
return False
@ -84,7 +90,9 @@ async def check_moddable(
<= target.top_role
):
await interaction.response.send_message(
content=error("You cannot moderate members with a role higher than the bot!"),
content=error(
"You cannot moderate members with a role higher than the bot!"
),
ephemeral=True,
)
return False
@ -102,7 +110,7 @@ async def check_moddable(
return True
async def get_next_case_number(guild_id: str, cursor = None) -> int:
async def get_next_case_number(guild_id: str, cursor=None) -> int:
"""This function returns the next case number from the MySQL table for a specific guild."""
from .database import connect
@ -133,7 +141,7 @@ def generate_dict(result):
"resolve_reason": result[12],
"expired": result[13],
"changes": json.loads(result[14]),
"metadata": json.loads(result[15])
"metadata": json.loads(result[15]),
}
return case
@ -172,7 +180,11 @@ async def fetch_channel_dict(interaction: Interaction, channel_id: str):
if not channel:
channel = await interaction.guild.fetch_channel(channel_id)
channel_dict = {"id": channel.id, "name": channel.name, "mention": channel.mention}
channel_dict = {
"id": channel.id,
"name": channel.name,
"mention": channel.mention,
}
except NotFound:
channel_dict = {"id": channel_id, "name": "Deleted Channel", "mention": None}
@ -202,25 +214,31 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal
case = await fetch_case(moderation_id, interaction.guild.id)
if case:
embed = await log_factory(interaction=interaction, case_dict=case, resolved=resolved)
embed = await log_factory(
interaction=interaction, case_dict=case, resolved=resolved
)
try:
await logging_channel.send(embed=embed)
except Forbidden:
return
async def send_evidenceformat(interaction: Interaction, case_dict: dict):
"""This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel."""
from .factory import evidenceformat_factory
send_evidence_bool = (await config.user(interaction.user).auto_evidenceformat()
send_evidence_bool = (
await config.user(interaction.user).auto_evidenceformat()
or await config.guild(interaction.guild).auto_evidenceformat()
or False)
or False
)
if send_evidence_bool is False:
return
content = await evidenceformat_factory(interaction=interaction, case_dict=case_dict)
await interaction.followup.send(content=content, ephemeral=True)
def convert_timedelta_to_str(timedelta: td) -> str:
"""This function converts a timedelta object to a string."""
total_seconds = int(timedelta.total_seconds())
@ -229,6 +247,7 @@ def convert_timedelta_to_str(timedelta: td) -> str:
seconds = total_seconds % 60
return f"{hours}:{minutes}:{seconds}"
def get_bool_emoji(value: bool) -> str:
"""Returns a unicode emoji based on a boolean value."""
if value is True:
@ -237,12 +256,14 @@ def get_bool_emoji(value: bool) -> str:
return "\N{NO ENTRY SIGN}"
return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}"
def get_pagesize_str(value: Union[int, None]) -> str:
"""Returns a string based on a pagesize value."""
if value is None:
return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}"
return str(value) + " cases per page"
def create_pagesize_options() -> list[SelectOption]:
"""Returns a list of SelectOptions for pagesize configuration."""
options = []