diff --git a/cog_tickets.py b/cog_tickets.py index 54d1a6c..aeb1f77 100644 --- a/cog_tickets.py +++ b/cog_tickets.py @@ -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") @@ -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: diff --git a/formatting.py b/formatting.py index 2000288..61109c1 100644 --- a/formatting.py +++ b/formatting.py @@ -11,7 +11,6 @@ log = logging.getLogger(__name__) - MAX_MESSAGE_LEN = 2000 @@ -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(): """ @@ -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) ) @@ -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) @@ -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))