Skip to content

Commit

Permalink
Adding command. No tests yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Philion committed Oct 29, 2024
1 parent 559be3a commit 7dcfac5
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions netbot/cog_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,35 +170,32 @@ async def callback(self, interaction: discord.Interaction):
await interaction.response.send_message(embeds=[embed])


# REMOVE unused
# class EditView(discord.ui.View):
# """View to allow ticket editing"""
# # to build, need:
# # - list of trackers
# # - list or priorities
# # - ticket subject
# # - from email
# # build intake view
# # 1. Assign: (popup with potential assignments)
# # 2. Priority: (popup with priorities)
# # 3. (Reject) Subject
# # 4. (Block) email-addr
# def __init__(self, bot_: discord.Bot) -> None:
# self.bot = bot_
# super().__init__()

# # Adds the dropdown to our View object
# self.add_item(PrioritySelect(self.bot))
# self.add_item(TrackerSelect(self.bot))

# self.add_item(discord.ui.Button(label="Done", row=4))
# self.add_item(discord.ui.Button(label="Edit Subject & Description", row=4))

# async def select_callback(self, select, interaction): # the function called when the user is done selecting options
# await interaction.response.send_message(f"EditView.select_callback() selected: {select.values[0]}")

# async def callback(self, interaction: discord.Interaction):
await interaction.response.send_message(f"EditView.callback() {interaction.data}")
class EditDescriptionModal(discord.ui.Modal):
"""modal dialog to edit the ticket subject and description"""
def __init__(self, redmine: Client, ticket: Ticket, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.redmine = redmine
self.ticket = ticket
self.add_item(discord.ui.InputText(label="Description",
value=ticket.description,
style=InputTextStyle.paragraph))


async def callback(self, interaction: discord.Interaction):
description = self.children[0].value
log.debug(f"callback: {description}")

user = self.redmine.user_mgr.find_discord_user(interaction.user.name)

fields = {
"description": description,
}
ticket = self.redmine.ticket_mgr.update(self.ticket.id, fields, user.login)

embed = discord.Embed(title=f"Updated ticket {ticket.id} description")
embed.add_field(name="Description", value=ticket.description)

await interaction.response.send_message(embeds=[embed])


# distinct from above. takes app-context
Expand Down Expand Up @@ -693,6 +690,18 @@ async def due(self, ctx: discord.ApplicationContext, date_str:str):
await ctx.respond("Command only valid in ticket thread. No ticket info found in this thread.")


@ticket.command(name="description", description="Edit the description of a ticket")
async def edit_description(self, ctx: discord.ApplicationContext):
# pop the the edit description embed
ticket_id = ctx.bot.parse_thread_title(ctx.channel.name)
ticket = self.redmine.ticket_mgr.get(ticket_id)
if ticket:
modal = EditDescriptionModal(self.redmine, ticket, title=ticket.subject)
await ctx.send_modal(modal)
else:
await ctx.respond(f"Cannot find ticket for {ctx.channel}")


@ticket.command(name="help", description="Display hepl about ticket management")
async def help(self, ctx: discord.ApplicationContext):
await ctx.respond(embed=self.bot.formatter.help_embed(ctx))

0 comments on commit 7dcfac5

Please sign in to comment.