mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 22:23:13 +00:00
Refactor deletion of custom reactions
This commit is contained in:
parent
5076cebf62
commit
4af860a05e
3 changed files with 18 additions and 37 deletions
|
@ -1,4 +1,9 @@
|
||||||
{
|
{
|
||||||
|
"triggers_delete_not_found_author": "Custom Reaction Not Found",
|
||||||
|
"triggers_not_found": "no custom reaction found with the provided ID.",
|
||||||
|
"triggers_not_deleted": "something went wrong while trying to delete this trigger.",
|
||||||
|
"triggers_delete_author": "Custom Reaction Deleted",
|
||||||
|
"triggers_delete_description": "custom reaction has been successfully deleted.",
|
||||||
"triggers_list_trigger_text": "**Trigger Text:** `{0}`",
|
"triggers_list_trigger_text": "**Trigger Text:** `{0}`",
|
||||||
"triggers_list_reaction_type": "**Reaction Type:** {0}",
|
"triggers_list_reaction_type": "**Reaction Type:** {0}",
|
||||||
"triggers_list_emoji_id": "**Emoji ID:** `{0}`",
|
"triggers_list_emoji_id": "**Emoji ID:** `{0}`",
|
||||||
|
|
|
@ -75,22 +75,6 @@ def create_failure_embed(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_deletion_embed(trigger_text: str, is_emoji: bool) -> discord.Embed:
|
|
||||||
trigger_text = formatter.shorten(trigger_text, 50)
|
|
||||||
|
|
||||||
description = f"**Trigger Text:** `{trigger_text}`\n"
|
|
||||||
description += "Custom reaction has been successfully deleted."
|
|
||||||
|
|
||||||
return create_embed("Custom Reaction Deleted", description, 0xFF8C00, check_icon)
|
|
||||||
|
|
||||||
|
|
||||||
def create_not_found_embed(reaction_id: int) -> discord.Embed:
|
|
||||||
description = f"**Reaction ID:** `{reaction_id}`\n"
|
|
||||||
description += "No custom reaction found with the provided ID."
|
|
||||||
|
|
||||||
return create_embed("Custom Reaction Not Found", description, 0xFF4500, cross_icon)
|
|
||||||
|
|
||||||
|
|
||||||
def create_no_triggers_embed() -> discord.Embed:
|
def create_no_triggers_embed() -> discord.Embed:
|
||||||
description = (
|
description = (
|
||||||
"There are no custom reactions set up yet.\n\n"
|
"There are no custom reactions set up yet.\n\n"
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
from discord.ext import bridge
|
from discord.ext import bridge
|
||||||
|
|
||||||
from lib.embeds.triggers import (
|
|
||||||
create_deletion_embed,
|
|
||||||
create_failure_embed,
|
|
||||||
create_not_found_embed,
|
|
||||||
)
|
|
||||||
from services.reactions_service import CustomReactionsService
|
from services.reactions_service import CustomReactionsService
|
||||||
|
from lib.embed_builder import EmbedBuilder
|
||||||
|
from lib.constants import CONST
|
||||||
|
from lib.exceptions.LumiExceptions import LumiException
|
||||||
|
|
||||||
|
|
||||||
async def delete_reaction(ctx: bridge.Context, reaction_id: int) -> None:
|
async def delete_reaction(ctx: bridge.Context, reaction_id: int) -> None:
|
||||||
|
@ -14,23 +11,18 @@ async def delete_reaction(ctx: bridge.Context, reaction_id: int) -> None:
|
||||||
|
|
||||||
reaction_service = CustomReactionsService()
|
reaction_service = CustomReactionsService()
|
||||||
guild_id: int = ctx.guild.id
|
guild_id: int = ctx.guild.id
|
||||||
|
|
||||||
# Check if the reaction exists and belongs to the guild
|
|
||||||
reaction = await reaction_service.find_id(reaction_id)
|
reaction = await reaction_service.find_id(reaction_id)
|
||||||
|
|
||||||
if reaction is None or reaction["guild_id"] != guild_id or reaction["is_global"]:
|
if reaction is None or reaction["guild_id"] != guild_id or reaction["is_global"]:
|
||||||
embed = create_not_found_embed(reaction_id)
|
raise LumiException(CONST.STRINGS["triggers_not_found"])
|
||||||
await ctx.respond(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
trigger_text = reaction["trigger_text"]
|
await reaction_service.delete_custom_reaction(reaction_id)
|
||||||
is_emoji = reaction["is_emoji"]
|
|
||||||
|
|
||||||
# Attempt to delete the reaction
|
embed = EmbedBuilder.create_success_embed(
|
||||||
success: bool = await reaction_service.delete_custom_reaction(reaction_id)
|
ctx,
|
||||||
|
author_text=CONST.STRINGS["triggers_delete_author"],
|
||||||
|
description=CONST.STRINGS["triggers_delete_description"],
|
||||||
|
footer_text=CONST.STRINGS["triggers_reaction_service_footer"],
|
||||||
|
)
|
||||||
|
|
||||||
if success:
|
|
||||||
embed = create_deletion_embed(trigger_text, is_emoji)
|
|
||||||
await ctx.respond(embed=embed)
|
|
||||||
else:
|
|
||||||
embed = create_failure_embed(trigger_text, is_emoji)
|
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
|
|
Loading…
Reference in a new issue