Skip to content

Commit

Permalink
Include better logging embed and fix timeout issues
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Dec 19, 2023
1 parent 9cd139a commit 8d2e925
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
14 changes: 6 additions & 8 deletions bot/cogs/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from discord.ext import commands
from libs.tickets.structs import ReservedTags, TicketThread
from libs.tickets.utils import get_cached_thread, get_partial_ticket
from libs.utils.embeds import LoggingEmbed

from .config import GuildWebhookDispatcher

Expand Down Expand Up @@ -289,18 +290,15 @@ async def on_ticket_create(
ticket: discord.channel.ThreadWithMessage,
init_message: str,
):
selected_mod = self.determine_active_mod(guild)
dispatcher = GuildWebhookDispatcher(self.bot, guild.id)
webhook = await dispatcher.get_webhook()

select_mod_mention = f"{selected_mod.mention}, " if selected_mod else ""

if webhook is not None:
msg = (
f"{select_mod_mention}{user.display_name} has created a ticket at {ticket.thread.mention}. The initial message has been provided below:\n\n"
f"{init_message}"
)
await webhook.send(content=msg)
embed = LoggingEmbed(title="\U0001f3ab New Ticket")
embed.description = init_message
embed.add_field(name="Owner", value=user.mention)
embed.add_field(name="Link", value=ticket.thread.mention)
await webhook.send(embed=embed)


async def setup(bot: Rodhaj) -> None:
Expand Down
15 changes: 15 additions & 0 deletions bot/libs/tickets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,18 @@ async def get_cached_thread(
if thread is None:
return None
return ThreadWithGuild(thread, thread.guild)


def safe_content(content: str, amount: int = 4000) -> str:
"""Safely sends the content by reducing the length
to avoid errors
Args:
content (str): Content to be sent
Returns:
str: A safe version of the content
"""
if len(content) > amount:
return content[: amount - 3] + "..."
return content
8 changes: 4 additions & 4 deletions bot/libs/tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from libs.tickets.structs import TicketThread
from libs.utils import ErrorEmbed, RoboView

from .utils import register_user
from .utils import register_user, safe_content

if TYPE_CHECKING:
from libs.utils.context import RoboContext
Expand Down Expand Up @@ -72,7 +72,7 @@ async def confirm(
self.guild,
self.ctx.author,
created_ticket.ticket,
self.content,
safe_content(self.content),
)
embed = discord.Embed(
title="\U0001f3ab Ticket created", color=discord.Color.from_rgb(124, 252, 0)
Expand All @@ -81,7 +81,7 @@ async def confirm(

if self.message:
await self.message.edit(
content=None, embed=embed, view=None, delete_after=15.0
content=None, embed=embed, view=None, delete_after=5.0
)

@discord.ui.button(
Expand All @@ -106,5 +106,5 @@ async def on_timeout(self) -> None:
"Timed out waiting for a response. Not creating a ticket. "
"In order to create a ticket, please resend your message and properly confirm"
)
await self.message.edit(embed=embed, view=None, delete_after=15.0)
await self.message.edit(embed=embed, view=None)
return
1 change: 1 addition & 0 deletions bot/libs/utils/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, **kwargs):
class LoggingEmbed(discord.Embed):
def __init__(self, **kwargs):
kwargs.setdefault("color", discord.Color.from_rgb(212, 252, 255))
kwargs.setdefault("timestamp", discord.utils.utcnow())
super().__init__(**kwargs)


Expand Down

0 comments on commit 8d2e925

Please sign in to comment.