Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: version 3.26 #89

Merged
merged 10 commits into from
Jul 30, 2024
177 changes: 173 additions & 4 deletions suggestions/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

class SuggestionsBot(commands.AutoShardedInteractionBot):
def __init__(self, *args, **kwargs):
self.version: str = "Public Release 3.25"
self.version: str = "Public Release 3.26"
self.main_guild_id: int = 601219766258106399
self.legacy_beta_role_id: int = 995588041991274547
self.automated_beta_role_id: int = 998173237282361425
Expand Down Expand Up @@ -300,6 +300,7 @@ async def on_slash_command_error(
"author_id": error.user_id,
"guild_id": error.guild_id,
"traceback": commons.exception_as_string(exception),
"error_code": ErrorCode.UNHANDLED_ERROR.value,
},
)
return await interaction.send(
Expand All @@ -320,17 +321,33 @@ async def on_slash_command_error(
await self.db.error_tracking.update(error, error)

if attempt_code == ErrorCode.MISSING_FETCH_PERMISSIONS_IN_SUGGESTIONS_CHANNEL:
logger.debug(
"MISSING_FETCH_PERMISSIONS_IN_SUGGESTIONS_CHANNEL",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": attempt_code.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Configuration Error",
"I do not have permission to use your guilds configured suggestions channel.",
error_code=attempt_code,
error_code=attempt_code.value,
error=error,
),
ephemeral=True,
)

elif attempt_code == ErrorCode.MISSING_FETCH_PERMISSIONS_IN_LOGS_CHANNEL:
logger.debug(
"MISSING_FETCH_PERMISSIONS_IN_LOGS_CHANNEL",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": attempt_code.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Configuration Error",
Expand All @@ -342,6 +359,14 @@ async def on_slash_command_error(
)

elif attempt_code == ErrorCode.MISSING_SEND_PERMISSIONS_IN_SUGGESTION_CHANNEL:
logger.debug(
"MISSING_SEND_PERMISSIONS_IN_SUGGESTION_CHANNEL",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": attempt_code.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Configuration Error",
Expand All @@ -353,6 +378,13 @@ async def on_slash_command_error(
)

if isinstance(exception, BetaOnly):
logger.critical(
"BetaOnly",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
},
)
embed: disnake.Embed = disnake.Embed(
title="Beta restrictions",
description="This command is restricted to beta guilds only, "
Expand All @@ -362,6 +394,14 @@ async def on_slash_command_error(
return await interaction.send(embed=embed, ephemeral=True)

elif isinstance(exception, MissingSuggestionsChannel):
logger.debug(
"MissingSuggestionsChannel",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.MISSING_SUGGESTIONS_CHANNEL.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Missing Suggestions Channel",
Expand All @@ -375,6 +415,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, MissingLogsChannel):
logger.debug(
"MissingLogsChannel",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.MISSING_LOG_CHANNEL.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Missing Logs Channel",
Expand All @@ -388,6 +436,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, MissingQueueLogsChannel):
logger.debug(
"MissingQueueLogsChannel",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.MISSING_QUEUE_LOG_CHANNEL.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Missing Queue Logs Channel",
Expand All @@ -401,6 +457,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, MissingPermissionsToAccessQueueChannel):
logger.debug(
"MissingPermissionsToAccessQueueChannel",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.MISSING_PERMISSIONS_IN_QUEUE_CHANNEL.value,
},
)
return await interaction.send(
embed=self.error_embed(
title="Missing permissions within queue logs channel",
Expand All @@ -419,6 +483,7 @@ async def on_slash_command_error(
"guild_id": interaction.guild_id,
"suggestion_id": exception.suggestion_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.SUGGESTION_NOT_FOUND.value,
},
)
return await interaction.send(
Expand All @@ -433,6 +498,15 @@ async def on_slash_command_error(

elif isinstance(exception, commands.MissingPermissions):
perms = ",".join(i for i in exception.missing_permissions)
logger.debug(
"commands.MissingPermissions: %s",
perms,
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.MISSING_PERMISSIONS.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Missing Permissions",
Expand All @@ -445,6 +519,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, SuggestionNotFound):
logger.debug(
"SuggestionNotFound",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.SUGGESTION_NOT_FOUND.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Command failed",
Expand All @@ -456,6 +538,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, SuggestionTooLong):
logger.debug(
"SuggestionTooLong",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.SUGGESTION_CONTENT_TOO_LONG.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Command failed",
Expand All @@ -471,6 +561,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, InvalidGuildConfigOption):
logger.debug(
"InvalidGuildConfigOption",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.INVALID_GUILD_CONFIG_CHOICE.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Command failed",
Expand All @@ -482,6 +580,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, CallableOnCooldown):
logger.debug(
"CallableOnCooldown",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.COMMAND_ON_COOLDOWN.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Command on Cooldown",
Expand All @@ -493,6 +599,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, BlocklistedUser):
logger.debug(
"BlocklistedUser",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.BLOCKLISTED_USER.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Blocked Action",
Expand All @@ -504,6 +618,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, InvalidFileType):
logger.debug(
"InvalidFileType",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.INVALID_FILE_TYPE.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Invalid file type",
Expand All @@ -516,6 +638,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, ConfiguredChannelNoLongerExists):
logger.debug(
"ConfiguredChannelNoLongerExists",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.CONFIGURED_CHANNEL_NO_LONGER_EXISTS.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Configuration Error",
Expand All @@ -530,6 +660,14 @@ async def on_slash_command_error(

elif isinstance(exception, LocalizationKeyError):
gid = interaction.guild_id if interaction.guild_id else None
logger.debug(
"LocalizationKeyError",
extra_metadata={
"guild_id": gid,
"author_id": interaction.author.id,
"error_code": ErrorCode.MISSING_TRANSLATION.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Something went wrong",
Expand All @@ -541,6 +679,14 @@ async def on_slash_command_error(
)

elif isinstance(exception, QueueImbalance):
logger.debug(
"QueueImbalance",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.QUEUE_IMBALANCE.value,
},
)
return await interaction.send(
embed=self.error_embed(
"Queue Imbalance",
Expand All @@ -559,6 +705,8 @@ async def on_slash_command_error(
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"traceback": commons.exception_as_string(exception),
"error_code": ErrorCode.GENERIC_NOT_FOUND.value,
},
)
gid = interaction.guild_id if interaction.guild_id else None
Expand All @@ -567,7 +715,7 @@ async def on_slash_command_error(
"Command failed",
"I've failed to find something, please retry whatever you were doing.\n"
f"If this error persists please contact support.\n\nGuild ID: `{gid}`",
error_code=ErrorCode.GENERIC_NOT_FOUND,
error_code=ErrorCode.GENERIC_NOT_FOUND.value,
error=error,
),
ephemeral=True,
Expand All @@ -582,6 +730,7 @@ async def on_slash_command_error(
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.GENERIC_FORBIDDEN.value,
},
)
await interaction.send(
Expand All @@ -597,6 +746,14 @@ async def on_slash_command_error(
raise exception

elif isinstance(exception, commands.NotOwner):
logger.debug(
"commands.NotOwner",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.OWNER_ONLY.value,
},
)
await interaction.send(
embed=self.error_embed(
"Command failed",
Expand All @@ -614,14 +771,26 @@ async def on_slash_command_error(
"disnake.HTTPException: Interaction has already been acknowledged"
)
logger.debug(
"disnake.HTTPException: Interaction has already been acknowledged"
"disnake.HTTPException: Interaction has already been acknowledged",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
},
)
return

ih: InteractionHandler = await InteractionHandler.fetch_handler(
interaction.id, self
)
if ih is not None and not ih.has_sent_something:
logger.critical(
"Interaction was never ack'd",
extra_metadata={
"guild_id": interaction.guild_id,
"author_id": interaction.author.id,
"error_code": ErrorCode.UNHANDLED_ERROR.value,
},
)
gid = interaction.guild_id if interaction.guild_id else None
# Fix "Bot is thinking" hanging on edge cases...
await interaction.send(
Expand Down
4 changes: 2 additions & 2 deletions suggestions/core/suggestion_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ async def modify_note_on_suggestions(
# We should now update the suggestions message
await suggestion.edit_suggestion_message(ih)

await ih.send(ih.bot.get_localized_string("NOTE_INNER_RESPONSE", ih))

# We should tell the user a change has occurred
suggestion_author_id: int = suggestion.suggestion_author_id
user_config: UserConfig = await UserConfig.from_id(
Expand Down Expand Up @@ -92,5 +94,3 @@ async def modify_note_on_suggestions(
embed.set_author(name=guild.name, icon_url=icon_url)
user: disnake.User = await ih.bot.fetch_user(suggestion_author_id)
await user.send(embed=embed)

await ih.send(ih.bot.get_localized_string("NOTE_INNER_RESPONSE", ih))
Loading
Loading