chore: add permission checks

This commit is contained in:
neoarz
2025-10-20 12:21:43 -04:00
parent 898e01abf4
commit a5f94df549
6 changed files with 309 additions and 67 deletions

View File

@@ -186,10 +186,19 @@ class ideviceSelect(discord.ui.Select):
await interaction.followup.send(embed=embed, view=view, ephemeral=True) await interaction.followup.send(embed=embed, view=view, ephemeral=True)
except discord.Forbidden: except discord.Forbidden:
self.bot.logger.warning(f"Bot missing permissions in server {interaction.guild.name} (ID: {interaction.guild.id}) - cannot execute errorcodes command") guild_info = f"server {interaction.guild.name} (ID: {interaction.guild.id})" if interaction.guild else "DM or private channel"
self.bot.logger.warning(f"Bot missing permissions in {guild_info} - cannot execute errorcodes command")
if interaction.guild is None:
embed = discord.Embed(
title="Error",
description="This command cannot be executed in DMs.",
color=0xFF0000
)
else:
embed = discord.Embed( embed = discord.Embed(
title="Permission Error", title="Permission Error",
description="The bot doesn't have the required permissions in this server to execute this command. Use the slash command `/errorcodes` instead.", description="The bot needs the `send messages` permission to execute this command.",
color=0xFF0000 color=0xFF0000
) )
embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png")
@@ -220,10 +229,19 @@ class ideviceSelect(discord.ui.Select):
embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png")
await interaction.response.edit_message(embed=embed, view=None) await interaction.response.edit_message(embed=embed, view=None)
except discord.Forbidden: except discord.Forbidden:
self.bot.logger.warning(f"Bot missing permissions in server {interaction.guild.name} (ID: {interaction.guild.id}) - cannot execute {command_name} command") guild_info = f"server {interaction.guild.name} (ID: {interaction.guild.id})" if interaction.guild else "DM or private channel"
self.bot.logger.warning(f"Bot missing permissions in {guild_info} - cannot execute {command_name} command")
if interaction.guild is None:
embed = discord.Embed(
title="Error",
description="This command cannot be executed in DMs.",
color=0xFF0000
)
else:
embed = discord.Embed( embed = discord.Embed(
title="Permission Error", title="Permission Error",
description=f"The bot doesn't have the required permissions in this server to execute this command. Use the slash command `/{command_name}` instead.", description="The bot needs the `send messages` permission to execute this command.",
color=0xFF0000 color=0xFF0000
) )
embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png")
@@ -258,6 +276,34 @@ def idevice_command():
name="idevice", description="idevice troubleshooting and help" name="idevice", description="idevice troubleshooting and help"
) )
async def idevice(self, context): async def idevice(self, context):
if isinstance(context.channel, discord.DMChannel):
embed = discord.Embed(
title="Error",
description="This command can only be used in servers.",
color=0xE02B2B,
)
embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png")
if context.interaction:
await context.interaction.response.send_message(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 send messages permissions in this channel.",
color=0xE02B2B,
)
embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png")
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
await context.send(embed=embed, ephemeral=True)
return
embed = discord.Embed( embed = discord.Embed(
title="idevice Commands", title="idevice Commands",
description="Choose a command from the dropdown below to get help with specific issues:", description="Choose a command from the dropdown below to get help with specific issues:",

View File

@@ -38,7 +38,7 @@ def download_command():
if isinstance(context.channel, discord.PartialMessageable): if isinstance(context.channel, discord.PartialMessageable):
embed = discord.Embed( embed = discord.Embed(
title="Error", title="Error",
description="The bot needs send messages permissions in this channel.", description="The bot needs the `send messages` permission in this channel.",
color=0xE02B2B, color=0xE02B2B,
) )
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp") embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
@@ -208,16 +208,36 @@ 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:
try:
await context.channel.send(embed=embed) await context.channel.send(embed=embed)
await context.channel.send(link) await context.channel.send(link)
try: try:
await interaction.delete_original_response() await interaction.delete_original_response()
except: except:
pass 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}")
@@ -265,16 +285,36 @@ 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:
try:
await context.channel.send(embed=embed) await context.channel.send(embed=embed)
await context.channel.send(file=file) await context.channel.send(file=file)
try: try:
await interaction.delete_original_response() await interaction.delete_original_response()
except: except:
pass 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")
@@ -313,16 +353,36 @@ 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:
try:
await context.channel.send(embed=embed) await context.channel.send(embed=embed)
await context.channel.send(link) await context.channel.send(link)
try: try:
await interaction.delete_original_response() await interaction.delete_original_response()
except: except:
pass 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(

View File

@@ -34,7 +34,7 @@ def mcquote_command():
if isinstance(context.channel, discord.PartialMessageable): if isinstance(context.channel, discord.PartialMessageable):
embed = discord.Embed( embed = discord.Embed(
title="Error", title="Error",
description="The bot needs send messages permissions in this channel.", description="The bot needs the `send messages` permission in this channel.",
color=0xE02B2B, color=0xE02B2B,
) )
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp") embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
@@ -127,16 +127,36 @@ def mcquote_command():
interaction = getattr(context, "interaction", None) interaction = getattr(context, "interaction", None)
if interaction is not None: if interaction is not None:
try:
await context.channel.send(embed=embed) await context.channel.send(embed=embed)
await context.channel.send(file=file) await context.channel.send(file=file)
try: try:
await interaction.delete_original_response() await interaction.delete_original_response()
except: except:
pass 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:

View File

@@ -85,7 +85,7 @@ def tts_command():
if isinstance(context.channel, discord.PartialMessageable): if isinstance(context.channel, discord.PartialMessageable):
embed = discord.Embed( embed = discord.Embed(
title="Error", title="Error",
description="The bot needs send messages permissions in this channel.", description="The bot needs the `send messages` permission in this channel.",
color=0xE02B2B, color=0xE02B2B,
) )
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp") embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
@@ -198,15 +198,35 @@ def tts_command():
) )
if interaction is not None: if interaction is not None:
try:
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)
try: try:
await interaction.delete_original_response() await interaction.delete_original_response()
except: except:
pass 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

View File

@@ -63,11 +63,20 @@ class MelonxSelect(discord.ui.Select):
embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png") embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png")
await interaction.response.edit_message(embed=embed, view=None) await interaction.response.edit_message(embed=embed, view=None)
except discord.Forbidden: except discord.Forbidden:
self.bot.logger.warning(f"Bot missing permissions in server {interaction.guild.name} (ID: {interaction.guild.id}) - cannot execute {command_name} command") guild_info = f"server {interaction.guild.name} (ID: {interaction.guild.id})" if interaction.guild else "DM or private channel"
self.bot.logger.warning(f"Bot missing permissions in {guild_info} - cannot execute {command_name} command")
if interaction.guild is None:
embed = discord.Embed(
title="Error",
description="This command cannot be executed in DMs.",
color=0xFF0000
)
else:
embed = discord.Embed( embed = discord.Embed(
title="Permission Error", title="Permission Error",
description="The bot doesn't have the required permissions in this server to execute this command. Use the slash command `/{command_name}` instead.", description="The bot needs the `send messages` permission to execute this command.",
color=0x963155 color=0xFF0000
) )
embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png") embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png")
await interaction.response.edit_message(embed=embed, view=None) await interaction.response.edit_message(embed=embed, view=None)
@@ -94,3 +103,53 @@ class MelonxView(discord.ui.View):
def __init__(self, bot): def __init__(self, bot):
super().__init__() super().__init__()
self.add_item(MelonxSelect(bot)) self.add_item(MelonxSelect(bot))
def melonx_command():
@commands.hybrid_command(
name="melonx", description="MeloNX troubleshooting and help"
)
async def melonx(self, context):
if isinstance(context.channel, discord.DMChannel):
embed = discord.Embed(
title="Error",
description="This command can only be used in servers.",
color=0xE02B2B,
)
embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png")
if context.interaction:
await context.interaction.response.send_message(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 send messages permissions in this channel.",
color=0xE02B2B,
)
embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png")
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
await context.send(embed=embed, ephemeral=True)
return
embed = discord.Embed(
title="MeloNX Commands",
description="Choose a command from the dropdown below to get help with specific issues:",
color=0x963155
)
embed.set_author(name="MeloNX", icon_url="https://yes.nighty.works/raw/TLGaVa.png")
view = MelonxView(self.bot)
if context.interaction:
await context.interaction.response.send_message(embed=embed, view=view, ephemeral=True)
else:
await context.send(embed=embed, view=view)
return melonx

View File

@@ -74,10 +74,19 @@ class SidestoreSelect(discord.ui.Select):
embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true") embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true")
await interaction.response.edit_message(embed=embed, view=None) await interaction.response.edit_message(embed=embed, view=None)
except discord.Forbidden: except discord.Forbidden:
self.bot.logger.warning(f"Bot missing permissions in server {interaction.guild.name} (ID: {interaction.guild.id}) - cannot execute {command_name} command") guild_info = f"server {interaction.guild.name} (ID: {interaction.guild.id})" if interaction.guild else "DM or private channel"
self.bot.logger.warning(f"Bot missing permissions in {guild_info} - cannot execute {command_name} command")
if interaction.guild is None:
embed = discord.Embed(
title="Error",
description="This command cannot be executed in DMs.",
color=0xFF0000
)
else:
embed = discord.Embed( embed = discord.Embed(
title="Permission Error", title="Permission Error",
description="The bot doesn't have the required permissions in this server to execute this command. Use the slash command `/{command_name}` instead.", description="The bot needs the `send messages` permission to execute this command.",
color=0xFF0000 color=0xFF0000
) )
embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true") embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true")
@@ -112,6 +121,34 @@ def sidestore_command():
name="help", description="SideStore troubleshooting and help" name="help", description="SideStore troubleshooting and help"
) )
async def sidestore(self, context): async def sidestore(self, context):
if isinstance(context.channel, discord.DMChannel):
embed = discord.Embed(
title="Error",
description="This command can only be used in servers.",
color=0xE02B2B,
)
embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true")
if context.interaction:
await context.interaction.response.send_message(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 send messages permissions in this channel.",
color=0xE02B2B,
)
embed.set_author(name="SideStore", icon_url="https://github.com/SideStore/assets/blob/main/icons/classic/Default.png?raw=true")
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
await context.send(embed=embed, ephemeral=True)
return
embed = discord.Embed( embed = discord.Embed(
title="SideStore Commands", title="SideStore Commands",
description="Choose a command from the dropdown below to get help with specific issues:", description="Choose a command from the dropdown below to get help with specific issues:",