-
Notifications
You must be signed in to change notification settings - Fork 940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tickets: Make ticket closing prompt more granular #1808
base: dev
Are you sure you want to change the base?
Changes from 5 commits
04687c9
2535de2
04452e9
f6938d7
333d879
f81416f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,8 +193,6 @@ func openTicket(ctx context.Context, gs *dstate.GuildSet, ms *dstate.MemberState | |
var closingTickets = make(map[int64]bool) | ||
var closingTicketsLock sync.Mutex | ||
|
||
const closingTicketMsg = "Closing ticket, creating logs, downloading attachments and so on.\nThis may take a while if the ticket is big." | ||
|
||
func closeTicket(gs *dstate.GuildSet, currentTicket *Ticket, ticketCS *dstate.ChannelState, conf *models.TicketConfig, member *discordgo.User, reason string, ctx context.Context) (string, error) { | ||
// protect again'st calling close multiple times at the sime time | ||
closingTicketsLock.Lock() | ||
|
@@ -210,8 +208,28 @@ func closeTicket(gs *dstate.GuildSet, currentTicket *Ticket, ticketCS *dstate.Ch | |
closingTicketsLock.Unlock() | ||
}() | ||
|
||
closingMsg := "Closing ticket." | ||
|
||
// We only need to build up a more detailed closing msg. | ||
// if we're creating logs. | ||
if conf.TicketsUseTXTTranscripts || conf.DownloadAttachments { | ||
var closingMsgBuilder strings.Builder | ||
closingMsgBuilder.WriteString(closingMsg) | ||
|
||
if conf.TicketsUseTXTTranscripts { | ||
closingMsgBuilder.WriteString("\nCreating logs.") | ||
} | ||
|
||
if conf.DownloadAttachments { | ||
closingMsgBuilder.WriteString("\nDownloading attachments.") | ||
} | ||
Comment on lines
+219
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax of the generated message is a bit awkward:
I wonder if we can arrange for the message to be more similar to the original. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt the "and so on" read weirdly, as those are the only two actions it's doing, and the comma version reads weirdly without it. I could have tried to do a version conditionally inserting "and", but this seemed like the least complex approach... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. For completeness, an alternative that is not too complicated is a switch enumerating all the cases, which is not too difficult here: transcripts, attachments := conf.TicketsUseTXTTranscripts, conf.DownloadAttachments
var closingMsg string
switch {
case transcripts && attachments:
closingMsg = "Closing ticket, creating logs, and downloading attachments. [...]"
case transcripts:
...
...
} but it is arguable whether this is a real improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the standpoint of minimising allocations, it's almost certainly an improvement. I was thinking of making a change of growing the allocation before building the string, but choosing a single option is almost certainly better, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is definitely more performant, but this code is not on the hot path and we do not make much effort to minimize allocations in general so that concern may be misplaced. The main questions, I think, are quality of the output message, code readability, and extensibility, and it's a bit less clear whether the above suggestion is a meaningful improvement on all three fronts to be worthwhile--I don't have a strong opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively: The initial line could be added as three statements; Having looked at my solution, using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about a slice of actions joined by commas and switched to title case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't particularly see how that helps. It would create a single source for changing any separators, yes, but would largely result in checking the same conditions anyway... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just joins it all into one sentence instead of three separate ones. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initial quibble, was about the fact I changed the response to be separated onto different lines, and the message reading somewhat strangely as a result. I kind of agree with that in hindsight, and I think the three statements could be on the same line. So basically, just swapping |
||
|
||
closingMsgBuilder.WriteString("\nThis may take a while, if the ticket is long.") | ||
Wolveric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
closingMsg = closingMsgBuilder.String() | ||
} | ||
|
||
// send a heads up that this can take a while | ||
common.BotSession.ChannelMessageSend(currentTicket.Ticket.ChannelID, closingTicketMsg) | ||
common.BotSession.ChannelMessageSend(currentTicket.Ticket.ChannelID, closingMsg) | ||
|
||
currentTicket.Ticket.ClosedAt.Time = time.Now() | ||
currentTicket.Ticket.ClosedAt.Valid = true | ||
|
@@ -298,13 +316,6 @@ func handleButton(evt *eventsystem.EventData, ic *discordgo.InteractionCreate, m | |
} | ||
} | ||
|
||
common.BotSession.CreateInteractionResponse(ic.ID, ic.Token, &discordgo.InteractionResponse{ | ||
Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
Data: &discordgo.InteractionResponseData{ | ||
Content: closingTicketMsg, | ||
Flags: discordgo.MessageFlagsEphemeral, | ||
}, | ||
}) | ||
response.Data.Content, err = closeTicket(evt.GS, currentTicket, currentChannel, conf, member.User, "", evt.Context()) | ||
case "close-reason": | ||
response = &discordgo.InteractionResponse{ | ||
|
@@ -360,13 +371,6 @@ func handleModal(evt *eventsystem.EventData, ic *discordgo.InteractionCreate, me | |
} | ||
} | ||
|
||
common.BotSession.CreateInteractionResponse(ic.ID, ic.Token, &discordgo.InteractionResponse{ | ||
Type: discordgo.InteractionResponseChannelMessageWithSource, | ||
Data: &discordgo.InteractionResponseData{ | ||
Content: closingTicketMsg, | ||
Flags: discordgo.MessageFlagsEphemeral, | ||
}, | ||
}) | ||
response.Data.Content, err = closeTicket(evt.GS, currentTicket, currentChannel, conf, member.User, value, evt.Context()) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the full stop is misplaced as is