Skip to content

Commit

Permalink
refining ticket display
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Philion committed Aug 13, 2024
1 parent fa38a1a commit c10a834
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cog_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class TicketsCog(commands.Cog):
"""encapsulate Discord ticket functions"""
def __init__(self, bot:NetBot):
self.bot:NetBot = bot
self.redmine:Client = bot.redmine
self.redmine: Client = bot.redmine

# see https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/slash_cog_groups.py
ticket = SlashCommandGroup("ticket", "ticket commands")
Expand Down Expand Up @@ -262,11 +262,11 @@ async def query(self, ctx: discord.ApplicationContext, term: str):


@ticket.command(description="Get ticket details")
@option("term", description="ticket ID")
@option("ticket_id", description="ticket ID")
async def details(self, ctx: discord.ApplicationContext, ticket_id:int):
"""Update status on a ticket, using: unassign, resolve, progress"""
#log.debug(f"found user mapping for {ctx.user.name}: {user}")
ticket = self.redmine.get_ticket(ticket_id)
ticket = self.redmine.get_ticket(ticket_id, include="children")
if ticket:
await self.bot.formatter.print_ticket(ticket, ctx)
else:
Expand Down
28 changes: 13 additions & 15 deletions formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

log = logging.getLogger(__name__)


MAX_MESSAGE_LEN = 2000


Expand Down Expand Up @@ -48,6 +47,10 @@ def get_emoji(key:str) -> str:
'EPIC': discord.Color.dark_gray(),
}

EPIC_TAG = "[EPIC] "
def strip_epic_tag(subject:str) -> str:
return subject[len(EPIC_TAG):] if subject.startswith(EPIC_TAG) else subject


class DiscordFormatter():
"""
Expand Down Expand Up @@ -263,8 +266,9 @@ def get_user_id(self, ctx: discord.ApplicationContext, ticket:Ticket) -> str:

def ticket_embed(self, ctx: discord.ApplicationContext, ticket:Ticket) -> discord.Embed:
"""Build an embed panel with full ticket details"""
subject = f"{get_emoji(ticket.priority.name)} {strip_epic_tag(ticket.subject)} (#{ticket.id})"
embed = discord.Embed(
title=ticket.subject,
title=subject,
description=ticket.description,
colour=self.ticket_color(ticket)
)
Expand All @@ -278,17 +282,12 @@ def ticket_embed(self, ctx: discord.ApplicationContext, ticket:Ticket) -> discor
if ticket.assigned_to:
embed.add_field(name="Owner", value=self.get_user_id(ctx, ticket))

if ticket.priority.name == "EPIC":
# list the sub-tickets
epic = ctx.bot.redmine.get_ticket(ticket.id, include="children")
if epic.children:
buff = ""
for child in epic.children:
buff += "- " + self.format_subticket(child) + "\n"
embed.add_field(name="Tickets", value=buff, inline=False)

#subtickets = []
#embed.add_field(name="Tickets", value=self.format_tickets("", subtickets))
# list the sub-tickets
if ticket.children:
buff = ""
for child in ticket.children:
buff += "- " + self.format_subticket(child) + "\n"
embed.add_field(name="Tickets", value=buff, inline=False)

# thread & redmine links
thread = ctx.bot.find_ticket_thread(ticket.id)
Expand All @@ -305,8 +304,7 @@ def epics_embed(self, ctx: discord.ApplicationContext, epics: dict[str,list[Tick

for tracker_name, tickets in epics.items():
for epic in tickets:
subject = epic.subject[6:] if epic.subject.startswith("[EPIC]") else epic.subject
subject = f"{ get_emoji('EPIC') } {subject} (#{epic.id})"
subject = f"{ get_emoji(epic.priority.name) } {strip_epic_tag(epic.subject)} (#{epic.id})"
embed.add_field(name=subject, value=epic.description, inline=False)
if epic.assigned_to:
embed.add_field(name="Owner", value=self.get_user_id(ctx, epic))
Expand Down

0 comments on commit c10a834

Please sign in to comment.