Skip to content

Commit

Permalink
cc: fix tmpl exec on ephemeral context messages (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
jo3-l authored Jul 22, 2024
1 parent 61058ff commit 7c3e293
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions customcommands/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func handleDelayedRunCC(evt *schEventsModels.ScheduledEvent, data interface{}) (
if err != nil {
return false, errors.WrapIf(err, "find_command")
}

if cmd.R.Group != nil && cmd.R.Group.Disabled {
return false, errors.New("custom command group is disabled")
}
Expand Down Expand Up @@ -685,6 +685,10 @@ func handleInteractionCreate(evt *eventsystem.EventData) {
return
}

// Ephemeral messages always have guild_id = 0 even if created in a guild channel; see
// https://github.com/discord/discord-api-docs/issues/4557. But exec/execAdmin rely
// on the guild ID of the message to fill guild data, so patch it here.
interaction.Message.GuildID = evt.GS.ID
interaction.Member.GuildID = evt.GS.ID

switch interaction.Type {
Expand Down Expand Up @@ -1122,7 +1126,7 @@ func ExecuteCustomCommand(cmd *models.CustomCommand, tmplCtx *templates.Context)
// deal with the results
if err != nil {
logger.WithField("guild", tmplCtx.GS.ID).WithError(err).Error("Error executing custom command")

errChannel := tmplCtx.CurrentFrame.CS.ID
if cmd.RedirectErrorsChannel != 0 {
errChannel = cmd.RedirectErrorsChannel
Expand Down Expand Up @@ -1556,4 +1560,4 @@ var cmdFixCommands = &commands.YAGCommand{

return fmt.Sprintf("Doneso! fixed %d commands!", len(ccs)), nil
}),
}
}

0 comments on commit 7c3e293

Please sign in to comment.