misc(aurora): use redbot chat_formatting for errors and warnings
Some checks failed
Pylint / Pylint (3.11) (push) Failing after 41s

This commit is contained in:
SeaswimmerTheFsh 2024-01-05 09:21:05 +00:00
parent 1f4254e9ca
commit 8129fee36a
Signed by: cswimr
GPG key ID: D74DDDDF420E13DF
4 changed files with 48 additions and 47 deletions

View file

@ -18,7 +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 redbot.core.utils.chat_formatting import box, error, warning
from .importers.galacticbot import ImportGalacticBotView
from .importers.aurora import ImportAuroraView
@ -233,7 +233,7 @@ class Aurora(commands.Cog):
blacklist_roles = await config.guild(interaction.guild).blacklist_roles()
if not blacklist_roles:
await interaction.response.send_message(content="There are no blacklist types set for this server!", ephemeral=True)
await interaction.response.send_message(content=error("There are no blacklist types set for this server!"), ephemeral=True)
return
matching_role = None
@ -244,14 +244,14 @@ class Aurora(commands.Cog):
break
if not matching_role:
await interaction.response.send_message(content="Please provide a valid blacklist type!", ephemeral=True)
await interaction.response.send_message(content=error("Please provide a valid blacklist type!"), ephemeral=True)
return
if not await check_moddable(target, interaction, ['moderate_members', 'manage_roles']):
return
if role in [role.id for role in target.roles]:
await interaction.response.send_message(content=f"{target.mention} already has the blacklist role!", ephemeral=True)
await interaction.response.send_message(content=error(f"{target.mention} already has the blacklist role!"), ephemeral=True)
return
if silent is None:
@ -292,17 +292,17 @@ class Aurora(commands.Cog):
return
if target.is_timed_out() is True:
await interaction.response.send_message(f"{target.mention} is already muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
await interaction.response.send_message(error(f"{target.mention} is already muted!"), allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
return
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
await interaction.response.send_message("Please provide a valid duration!", ephemeral=True)
await interaction.response.send_message(error("Please provide a valid duration!"), ephemeral=True)
return
if parsed_time.total_seconds() / 1000 > 2419200000:
await interaction.response.send_message("Please provide a duration that is less than 28 days.")
await interaction.response.send_message(error("Please provide a duration that is less than 28 days."))
return
await target.timeout(parsed_time, reason=f"Muted by {interaction.user.id} for: {reason}")
@ -341,7 +341,7 @@ class Aurora(commands.Cog):
return
if target.is_timed_out() is False:
await interaction.response.send_message(f"{target.mention} is not muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
await interaction.response.send_message(error(f"{target.mention} is not muted!"), allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
return
if reason:
@ -437,7 +437,7 @@ class Aurora(commands.Cog):
try:
await interaction.guild.fetch_ban(target)
await interaction.response.send_message(content=f"{target.mention} is already banned!", ephemeral=True)
await interaction.response.send_message(content=error(f"{target.mention} is already banned!"), ephemeral=True)
return
except discord.errors.NotFound:
pass
@ -446,7 +446,7 @@ class Aurora(commands.Cog):
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
await interaction.response.send_message("Please provide a valid duration!", ephemeral=True)
await interaction.response.send_message(error("Please provide a valid duration!"), ephemeral=True)
return
await interaction.response.send_message(content=f"{target.mention} has been banned for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`")
@ -504,7 +504,7 @@ class Aurora(commands.Cog):
try:
await interaction.guild.fetch_ban(target)
except discord.errors.NotFound:
await interaction.response.send_message(content=f"{target.mention} is not banned!", ephemeral=True)
await interaction.response.send_message(content=error(f"{target.mention} is not banned!"), ephemeral=True)
return
if reason:
@ -576,7 +576,7 @@ class Aurora(commands.Cog):
permissions = check_permissions(interaction.client.user, ['embed_links'], interaction)
if permissions:
await interaction.followup.send(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
await interaction.followup.send(error(f"I do not have the `{permissions}` permission, required for this action."), ephemeral=True)
return
database = connect()
@ -602,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" + box(e, 'py'), ephemeral=ephemeral)
await interaction.followup.send(content=error(f"An error occured while exporting the moderation history.\nError:\n") + box(e, 'py'), ephemeral=ephemeral)
cursor.close()
database.close()
return
@ -699,7 +699,7 @@ class Aurora(commands.Cog):
Reason for resolving case"""
permissions = check_permissions(interaction.client.user, ['embed_links', 'moderate_members', 'ban_members'], interaction)
if permissions:
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
await interaction.response.send_message(error(f"I do not have the `{permissions}` permission, required for this action."), ephemeral=True)
return
database = connect()
@ -709,14 +709,14 @@ class Aurora(commands.Cog):
cursor.execute(query_1, (case,))
result_1 = cursor.fetchone()
if result_1 is None or case == 0:
await interaction.response.send_message(content=f"There is no moderation with a case number of {case}.", ephemeral=True)
await interaction.response.send_message(content=error(f"There is no moderation with a case number of {case}."), ephemeral=True)
return
query_2 = f"SELECT * FROM moderation_{interaction.guild.id} WHERE moderation_id = ? AND resolved = 0;"
cursor.execute(query_2, (case,))
result_2 = cursor.fetchone()
if result_2 is None:
await interaction.response.send_message(content=f"This moderation has already been resolved!\nUse `/case {case}` for more information.", ephemeral=True)
await interaction.response.send_message(content=error(f"This moderation has already been resolved!\nUse `/case {case}` for more information."), ephemeral=True)
return
case_dict = generate_dict(result_2)
@ -725,7 +725,7 @@ class Aurora(commands.Cog):
changes: list = case_dict['changes']
if len(changes) > 25:
await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True)
await interaction.response.send_message(content=error("Due to limitations with Discord's embed system, you cannot edit a case more than 25 times."), ephemeral=True)
return
if not changes:
changes.append(
@ -746,7 +746,7 @@ class Aurora(commands.Cog):
)
if case_dict['moderation_type'] in ['UNMUTE', 'UNBAN']:
await interaction.response.send_message(content="You cannot resolve this type of moderation!", ephemeral=True)
await interaction.response.send_message(content=error("You cannot resolve this type of moderation!"), ephemeral=True)
if case_dict['moderation_type'] in ['MUTE', 'TEMPBAN', 'BAN']:
if case_dict['moderation_type'] == 'MUTE':
@ -799,7 +799,7 @@ class Aurora(commands.Cog):
Export the case to a JSON file or codeblock"""
permissions = check_permissions(interaction.client.user, ['embed_links'], interaction)
if permissions:
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
await interaction.response.send_message(error(f"I do not have the `{permissions}` permission, required for this action."), ephemeral=True)
return
if ephemeral is None:
@ -818,7 +818,7 @@ class Aurora(commands.Cog):
json.dump(case_dict, f, indent=2)
if export.value == 'codeblock':
content = f"Case #{case:,} exported.\n*Case was too large to export as codeblock, so it has been uploaded as a `.json` file.*"
content = f"Case #{case:,} exported.\n" + warning("Case was too large to export as codeblock, so it has been uploaded as a `.json` file.")
else:
content = f"Case #{case:,} exported."
@ -854,7 +854,7 @@ class Aurora(commands.Cog):
What is the new duration? Does not reapply the moderation if it has already expired."""
permissions = check_permissions(interaction.client.user, ['embed_links'], interaction)
if permissions:
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
await interaction.response.send_message(error(f"I do not have the `{permissions}` permission, required for this action."), ephemeral=True)
return
if case != 0:
@ -865,14 +865,14 @@ class Aurora(commands.Cog):
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
await interaction.response.send_message("Please provide a valid duration!", ephemeral=True)
await interaction.response.send_message(error("Please provide a valid duration!"), ephemeral=True)
return
end_timestamp = case_dict['timestamp'] + parsed_time.total_seconds()
if case_dict['moderation_type'] == 'MUTE':
if (time.time() - case_dict['timestamp']) + parsed_time.total_seconds() > 2419200:
await interaction.response.send_message("Please provide a duration that is less than 28 days from the initial moderation.")
await interaction.response.send_message(error("Please provide a duration that is less than 28 days from the initial moderation."))
return
try:
@ -884,7 +884,7 @@ class Aurora(commands.Cog):
changes: list = case_dict['changes']
if len(changes) > 25:
await interaction.response.send_message(content="Due to limitations with Discord's embed system, you cannot edit a case more than 25 times.", ephemeral=True)
await interaction.response.send_message(content=error("Due to limitations with Discord's embed system, you cannot edit a case more than 25 times."), ephemeral=True)
return
if not changes:
changes.append(
@ -940,7 +940,7 @@ class Aurora(commands.Cog):
cursor.close()
database.close()
return
await interaction.response.send_message(content=f"No case with case number `{case}` found.", ephemeral=True)
await interaction.response.send_message(content=error(f"No case with case number `{case}` found."), ephemeral=True)
@tasks.loop(minutes=1)
async def handle_expiry(self):
@ -1101,10 +1101,10 @@ class Aurora(commands.Cog):
async def auroraset_user_history_inline_pagesize(self, ctx: commands.Context, pagesize: int):
"""Set the amount of cases to display per page."""
if pagesize > 20:
await ctx.send("Pagesize cannot be greater than 20!")
await ctx.send(error("Pagesize cannot be greater than 20!"))
return
if pagesize < 1:
await ctx.send("Pagesize cannot be less than 1!")
await ctx.send(error("Pagesize cannot be less than 1!"))
return
await config.user(ctx.author).history_inline_pagesize.set(pagesize)
await ctx.send(f"Inline pagesize set to {await config.user(ctx.author).history_inline_pagesize()}")
@ -1181,7 +1181,7 @@ class Aurora(commands.Cog):
"""Add a role to the immune roles list."""
immune_roles: list = await config.guild(ctx.guild).immune_roles()
if role.id in immune_roles:
await ctx.send("Role is already immune!")
await ctx.send(error("Role is already immune!"))
return
immune_roles.append(role.id)
await config.guild(ctx.guild).immune_roles.set(immune_roles)
@ -1193,7 +1193,7 @@ class Aurora(commands.Cog):
"""Remove a role from the immune roles list."""
immune_roles: list = await config.guild(ctx.guild).immune_roles()
if role.id not in immune_roles:
await ctx.send("Role is not immune!")
await ctx.send(error("Role is not immune!"))
return
immune_roles.remove(role.id)
await config.guild(ctx.guild).immune_roles.set(immune_roles)
@ -1228,13 +1228,13 @@ class Aurora(commands.Cog):
blacklist_roles: list = await config.guild(ctx.guild).blacklist_roles()
for blacklist_role in blacklist_roles:
if role.id == blacklist_role['role']:
await ctx.send("Role already has an associated blacklist type!")
await ctx.send(error("Role already has an associated blacklist type!"))
return
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
await ctx.send("Please provide a valid duration!")
await ctx.send(error("Please provide a valid duration!"))
return
blacklist_roles.append(
@ -1257,7 +1257,7 @@ class Aurora(commands.Cog):
await config.guild(ctx.guild).blacklist_roles.set(blacklist_roles)
await ctx.send(f"Role {role.mention} removed from blacklist types.", allowed_mentions=discord.AllowedMentions.none())
return
await ctx.send("Role does not have an associated blacklist type!")
await ctx.send(error("Role does not have an associated blacklist type!"))
@auroraset_blacklist.command(name='list')
@checks.admin()
@ -1308,7 +1308,7 @@ class Aurora(commands.Cog):
await ctx.send(f"Logging channel set to {channel.mention}.")
else:
await config.guild(ctx.guild).log_channel.set(" ")
await ctx.send("Logging channel disabled.")
await ctx.send(warning("Logging channel disabled."))
@auroraset.command(name="showmoderator")
@checks.admin()
@ -1327,20 +1327,20 @@ class Aurora(commands.Cog):
async def auroraset_import_aurora(self, ctx: commands.Context):
"""Import moderations from another bot using Aurora."""
if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8':
message = await ctx.send("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")
message = await ctx.send(warning("Are you sure you want to import moderations from another bot?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*"))
await message.edit(view=ImportAuroraView(60, ctx, message))
else:
await ctx.send("Please provide a valid Aurora export file.")
await ctx.send(error("Please provide a valid Aurora export file."))
@auroraset_import.command(name="galacticbot")
@checks.admin()
async def auroraset_import_galacticbot(self, ctx: commands.Context):
"""Import moderations from GalacticBot."""
if ctx.message.attachments and ctx.message.attachments[0].content_type == 'application/json; charset=utf-8':
message = await ctx.send("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*")
message = await ctx.send(warning("Are you sure you want to import GalacticBot moderations?\n**This will overwrite any moderations that already exist in this guild's moderation table.**\n*The import process will block the rest of your bot until it is complete.*"))
await message.edit(view=ImportGalacticBotView(60, ctx, message))
else:
await ctx.send("Please provide a valid GalacticBot moderation export file.")
await ctx.send(error("Please provide a valid GalacticBot moderation export file."))
@commands.command(aliases=["tdc"])
async def timedeltaconvert(self, ctx: commands.Context, *, duration: str):
@ -1354,4 +1354,4 @@ class Aurora(commands.Cog):
parsed_time = parse(duration, as_timedelta=True, raise_exception=True)
await ctx.send(f"`{str(parsed_time)}`")
except ValueError:
await ctx.send("Please provide a convertible value!")
await ctx.send(error("Please provide a convertible value!"))