mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
chore: move checks before command is procesed
This commit is contained in:
@@ -71,6 +71,29 @@ def download_command():
|
|||||||
await context.send(embed=embed, ephemeral=True)
|
await context.send(embed=embed, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check if bot has send messages permission before starting download
|
||||||
|
try:
|
||||||
|
test_embed = discord.Embed(title="Testing permissions...", color=0x7289DA)
|
||||||
|
test_embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
await context.channel.send(embed=test_embed, delete_after=0.1)
|
||||||
|
except discord.Forbidden:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Permission Error",
|
||||||
|
description="The bot needs the `send messages` permission to execute this command.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
parsed_url = urlparse(url)
|
parsed_url = urlparse(url)
|
||||||
if not parsed_url.scheme or not parsed_url.netloc:
|
if not parsed_url.scheme or not parsed_url.netloc:
|
||||||
@@ -208,36 +231,16 @@ def download_command():
|
|||||||
embed.set_footer(text=f"Requested by {context.author.name}", icon_url=context.author.display_avatar.url)
|
embed.set_footer(text=f"Requested by {context.author.name}", icon_url=context.author.display_avatar.url)
|
||||||
|
|
||||||
if interaction is not None:
|
if interaction is not None:
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(link)
|
||||||
try:
|
try:
|
||||||
await context.channel.send(embed=embed)
|
await interaction.delete_original_response()
|
||||||
await context.channel.send(link)
|
except:
|
||||||
try:
|
pass
|
||||||
await interaction.delete_original_response()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await interaction.followup.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
try:
|
await processing_msg.delete()
|
||||||
await processing_msg.delete()
|
await context.channel.send(embed=embed)
|
||||||
await context.channel.send(embed=embed)
|
await context.channel.send(link)
|
||||||
await context.channel.send(link)
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await context.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
return
|
return
|
||||||
except Exception as upload_error:
|
except Exception as upload_error:
|
||||||
logger.exception(f"Catbox upload exception: {upload_error}")
|
logger.exception(f"Catbox upload exception: {upload_error}")
|
||||||
@@ -285,36 +288,16 @@ def download_command():
|
|||||||
file = discord.File(f, filename=files[0])
|
file = discord.File(f, filename=files[0])
|
||||||
|
|
||||||
if interaction is not None:
|
if interaction is not None:
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(file=file)
|
||||||
try:
|
try:
|
||||||
await context.channel.send(embed=embed)
|
await interaction.delete_original_response()
|
||||||
await context.channel.send(file=file)
|
except:
|
||||||
try:
|
pass
|
||||||
await interaction.delete_original_response()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await interaction.followup.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
try:
|
await processing_msg.delete()
|
||||||
await processing_msg.delete()
|
await context.channel.send(embed=embed)
|
||||||
await context.channel.send(embed=embed)
|
await context.channel.send(file=file)
|
||||||
await context.channel.send(file=file)
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await context.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
except discord.HTTPException as e:
|
except discord.HTTPException as e:
|
||||||
if e.status == 413:
|
if e.status == 413:
|
||||||
logger.info("Discord rejected file (413), falling back to Catbox upload")
|
logger.info("Discord rejected file (413), falling back to Catbox upload")
|
||||||
@@ -353,36 +336,16 @@ def download_command():
|
|||||||
embed.set_footer(text=f"Requested by {context.author.name}", icon_url=context.author.display_avatar.url)
|
embed.set_footer(text=f"Requested by {context.author.name}", icon_url=context.author.display_avatar.url)
|
||||||
|
|
||||||
if interaction is not None:
|
if interaction is not None:
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(link)
|
||||||
try:
|
try:
|
||||||
await context.channel.send(embed=embed)
|
await interaction.delete_original_response()
|
||||||
await context.channel.send(link)
|
except:
|
||||||
try:
|
pass
|
||||||
await interaction.delete_original_response()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await interaction.followup.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
try:
|
await processing_msg.delete()
|
||||||
await processing_msg.delete()
|
await context.channel.send(embed=embed)
|
||||||
await context.channel.send(embed=embed)
|
await context.channel.send(link)
|
||||||
await context.channel.send(link)
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await context.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
except Exception as upload_error:
|
except Exception as upload_error:
|
||||||
logger.exception(f"Catbox upload exception: {upload_error}")
|
logger.exception(f"Catbox upload exception: {upload_error}")
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
|
|||||||
@@ -85,6 +85,29 @@ def mcquote_command():
|
|||||||
await context.send(embed=embed, ephemeral=True)
|
await context.send(embed=embed, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check if bot has send messages permission before starting quote generation
|
||||||
|
try:
|
||||||
|
test_embed = discord.Embed(title="Testing permissions...", color=0x7289DA)
|
||||||
|
test_embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
await context.channel.send(embed=test_embed, delete_after=0.1)
|
||||||
|
except discord.Forbidden:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Permission Error",
|
||||||
|
description="The bot needs the `send messages` permission to execute this command.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
processing_embed = discord.Embed(
|
processing_embed = discord.Embed(
|
||||||
title="Minecraft Quote (Processing)",
|
title="Minecraft Quote (Processing)",
|
||||||
description="<a:mariospin:1423677027013103709> Generating quote... This may take a moment.",
|
description="<a:mariospin:1423677027013103709> Generating quote... This may take a moment.",
|
||||||
@@ -127,36 +150,16 @@ def mcquote_command():
|
|||||||
|
|
||||||
interaction = getattr(context, "interaction", None)
|
interaction = getattr(context, "interaction", None)
|
||||||
if interaction is not None:
|
if interaction is not None:
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(file=file)
|
||||||
try:
|
try:
|
||||||
await context.channel.send(embed=embed)
|
await interaction.delete_original_response()
|
||||||
await context.channel.send(file=file)
|
except:
|
||||||
try:
|
pass
|
||||||
await interaction.delete_original_response()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await interaction.followup.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
try:
|
await processing_msg.delete()
|
||||||
await processing_msg.delete()
|
await context.channel.send(embed=embed)
|
||||||
await context.channel.send(embed=embed)
|
await context.channel.send(file=file)
|
||||||
await context.channel.send(file=file)
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await context.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
os.remove(temp_file_path)
|
os.remove(temp_file_path)
|
||||||
except aiohttp.ClientError:
|
except aiohttp.ClientError:
|
||||||
|
|||||||
@@ -128,6 +128,29 @@ def tts_command():
|
|||||||
await send_embed(context, embed, ephemeral=True)
|
await send_embed(context, embed, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check if bot has send messages permission before starting TTS generation
|
||||||
|
try:
|
||||||
|
test_embed = discord.Embed(title="Testing permissions...", color=0x7289DA)
|
||||||
|
test_embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
await context.channel.send(embed=test_embed, delete_after=0.1)
|
||||||
|
except discord.Forbidden:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Permission Error",
|
||||||
|
description="The bot needs the `send messages` permission to execute this command.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
processing_embed = (
|
processing_embed = (
|
||||||
discord.Embed(
|
discord.Embed(
|
||||||
title="TTS (Processing)",
|
title="TTS (Processing)",
|
||||||
@@ -198,35 +221,15 @@ def tts_command():
|
|||||||
)
|
)
|
||||||
|
|
||||||
if interaction is not None:
|
if interaction is not None:
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(file=audio_file)
|
||||||
try:
|
try:
|
||||||
await context.channel.send(embed=embed)
|
await interaction.delete_original_response()
|
||||||
await context.channel.send(file=audio_file)
|
except:
|
||||||
try:
|
pass
|
||||||
await interaction.delete_original_response()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await interaction.followup.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
try:
|
await processing_message.delete()
|
||||||
await processing_message.delete()
|
await context.channel.send(embed=embed)
|
||||||
await context.channel.send(embed=embed)
|
await context.channel.send(file=audio_file)
|
||||||
await context.channel.send(file=audio_file)
|
|
||||||
except discord.Forbidden:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title="Permission Error",
|
|
||||||
description="The bot needs the `send messages` permission to execute this command.",
|
|
||||||
color=0xE02B2B,
|
|
||||||
)
|
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
|
||||||
await context.send(embed=embed, ephemeral=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
return tts
|
return tts
|
||||||
@@ -174,13 +174,40 @@ def codepreview_command():
|
|||||||
url="GitHub URL to preview code from"
|
url="GitHub URL to preview code from"
|
||||||
)
|
)
|
||||||
async def codepreview(self, context, url: str = None):
|
async def codepreview(self, context, url: str = None):
|
||||||
if not context.guild:
|
if isinstance(context.channel, discord.DMChannel):
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Error",
|
title="Error",
|
||||||
description="Due to reasons ~~gatekeep~~, this command can only be used in servers. Please add this bot to your sever to use it, or use it in a server which has this bot added.",
|
description="This command can only be used in servers.",
|
||||||
color=0xE02B2B,
|
color=0xE02B2B,
|
||||||
).set_author(name="Utility", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
)
|
||||||
await send_embed(context, embed, ephemeral=True)
|
embed.set_author(name="Utility", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if isinstance(context.channel, discord.PartialMessageable):
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Error",
|
||||||
|
description="The bot needs the `send messages` permission in this channel.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Utility", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not url or not url.strip():
|
if not url or not url.strip():
|
||||||
@@ -225,6 +252,29 @@ def codepreview_command():
|
|||||||
await send_embed(context, embed, ephemeral=True)
|
await send_embed(context, embed, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check if bot has send messages permission before starting processing
|
||||||
|
try:
|
||||||
|
test_embed = discord.Embed(title="Testing permissions...", color=0x7289DA)
|
||||||
|
test_embed.set_author(name="Utility", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
await context.channel.send(embed=test_embed, delete_after=0.1)
|
||||||
|
except discord.Forbidden:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Permission Error",
|
||||||
|
description="The bot needs the `send messages` permission to execute this command.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Utility", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
parsed = parse_github_url(url)
|
parsed = parse_github_url(url)
|
||||||
|
|
||||||
if not parsed:
|
if not parsed:
|
||||||
|
|||||||
Reference in New Issue
Block a user