horsebot: use a command option to decide whether ephemeral
This commit is contained in:
@@ -85,7 +85,6 @@ func main() {
|
|||||||
r.SlashCommand("/", skillSrv.slash)
|
r.SlashCommand("/", skillSrv.slash)
|
||||||
r.Autocomplete("/", skillSrv.autocomplete)
|
r.Autocomplete("/", skillSrv.autocomplete)
|
||||||
r.ButtonComponent("/swap/{id}", skillSrv.button)
|
r.ButtonComponent("/swap/{id}", skillSrv.button)
|
||||||
r.ButtonComponent("/share/{id}", skillSrv.share)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
opts := []bot.ConfigOpt{bot.WithDefaultGateway(), bot.WithEventListeners(r)}
|
opts := []bot.ConfigOpt{bot.WithDefaultGateway(), bot.WithEventListeners(r)}
|
||||||
@@ -144,6 +143,10 @@ var commands = []discord.ApplicationCommandCreate{
|
|||||||
Required: true,
|
Required: true,
|
||||||
Autocomplete: true,
|
Autocomplete: true,
|
||||||
},
|
},
|
||||||
|
discord.ApplicationCommandOptionBool{
|
||||||
|
Name: "share",
|
||||||
|
Description: "Share the skill info",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,11 @@ func (s *skillServer) slash(data discord.SlashCommandInteractionData, e *handler
|
|||||||
id = int64(v)
|
id = int64(v)
|
||||||
}
|
}
|
||||||
m := discord.MessageCreate{
|
m := discord.MessageCreate{
|
||||||
Components: []discord.LayoutComponent{s.render(horse.SkillID(id), false)},
|
Components: []discord.LayoutComponent{s.render(horse.SkillID(id))},
|
||||||
Flags: discord.MessageFlagIsComponentsV2 | discord.MessageFlagEphemeral,
|
Flags: discord.MessageFlagIsComponentsV2,
|
||||||
|
}
|
||||||
|
if !data.Bool("share") {
|
||||||
|
m.Flags |= discord.MessageFlagEphemeral
|
||||||
}
|
}
|
||||||
return e.CreateMessage(m)
|
return e.CreateMessage(m)
|
||||||
}
|
}
|
||||||
@@ -87,31 +90,15 @@ func (s *skillServer) button(data discord.ButtonInteractionData, e *handler.Comp
|
|||||||
return e.CreateMessage(m)
|
return e.CreateMessage(m)
|
||||||
}
|
}
|
||||||
m := discord.MessageUpdate{
|
m := discord.MessageUpdate{
|
||||||
Components: &[]discord.LayoutComponent{s.render(horse.SkillID(id), false)},
|
Components: &[]discord.LayoutComponent{s.render(horse.SkillID(id))},
|
||||||
}
|
}
|
||||||
return e.UpdateMessage(m)
|
return e.UpdateMessage(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *skillServer) share(data discord.ButtonInteractionData, e *handler.ComponentEvent) error {
|
func (s *skillServer) render(id horse.SkillID) discord.ContainerComponent {
|
||||||
id, err := strconv.ParseInt(e.Vars["id"], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
m := discord.MessageCreate{
|
|
||||||
Content: "That button produced an invalid skill ID. That's not supposed to happen.",
|
|
||||||
Flags: discord.MessageFlagEphemeral,
|
|
||||||
}
|
|
||||||
return e.CreateMessage(m)
|
|
||||||
}
|
|
||||||
m := discord.MessageCreate{
|
|
||||||
Components: []discord.LayoutComponent{s.render(horse.SkillID(id), true)},
|
|
||||||
Flags: discord.MessageFlagIsComponentsV2,
|
|
||||||
}
|
|
||||||
return e.CreateMessage(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *skillServer) render(id horse.SkillID, share bool) discord.ContainerComponent {
|
|
||||||
skill, ok := s.skills[id]
|
skill, ok := s.skills[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
slog.Error("invalid skill id", slog.Int("id", int(id)), slog.Bool("share", share))
|
slog.Error("invalid skill id", slog.Int("id", int(id)))
|
||||||
return discord.NewContainer(discord.NewTextDisplayf("invalid skill ID %v made it to render", id))
|
return discord.NewContainer(discord.NewTextDisplayf("invalid skill ID %v made it to render", id))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +185,7 @@ func (s *skillServer) render(id horse.SkillID, share bool) discord.ContainerComp
|
|||||||
rel = append(rel, s.skills[id])
|
rel = append(rel, s.skills[id])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(rel) > 1 || !share {
|
if len(rel) > 1 {
|
||||||
buttons := make([]discord.InteractiveComponent, 0, 4)
|
buttons := make([]discord.InteractiveComponent, 0, 4)
|
||||||
for _, rs := range rel {
|
for _, rs := range rel {
|
||||||
b := discord.NewSecondaryButton(rs.Name, fmt.Sprintf("/skill/swap/%d", rs.ID))
|
b := discord.NewSecondaryButton(rs.Name, fmt.Sprintf("/skill/swap/%d", rs.ID))
|
||||||
@@ -207,9 +194,6 @@ func (s *skillServer) render(id horse.SkillID, share bool) discord.ContainerComp
|
|||||||
}
|
}
|
||||||
buttons = append(buttons, b)
|
buttons = append(buttons, b)
|
||||||
}
|
}
|
||||||
if !share {
|
|
||||||
buttons = append(buttons, discord.NewPrimaryButton("Share", fmt.Sprintf("/skill/share/%d", skill.ID)))
|
|
||||||
}
|
|
||||||
r.Components = append(r.Components, discord.NewActionRow(buttons...))
|
r.Components = append(r.Components, discord.NewActionRow(buttons...))
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
|
|||||||
Reference in New Issue
Block a user