add related skill buttons

This commit is contained in:
2026-01-16 23:01:05 -05:00
parent 65726eb539
commit f5e26e5036
4 changed files with 45 additions and 11 deletions

30
main.go
View File

@@ -48,7 +48,7 @@ func main() {
r.Route("/skill", func(r handler.Router) {
r.SlashCommand("/", skillHandler)
r.Autocomplete("/", skillAutocomplete)
// TODO(zeph): button handler
r.ButtonComponent("/{id}", skillButton)
})
slog.Info("connect", slog.String("disgo", disgo.Version))
@@ -94,15 +94,14 @@ var commands = []discord.ApplicationCommandCreate{
func skillHandler(data discord.SlashCommandInteractionData, e *handler.CommandEvent) error {
q := data.String("query")
id, err := strconv.ParseInt(q, 10, 32)
var s horse.Skill
if err == nil {
// note inverted condition; this is when we have an id
s = global.AllSkills[horse.SkillID(id)]
id = int64(global.AllSkills[horse.SkillID(id)].ID)
}
if s.ID == 0 {
if id == 0 {
// Either we weren't given a number or the number doesn't match any skill ID.
id, ok := global.SkillNameToID[q]
if !ok {
v := global.SkillNameToID[q]
if v == 0 {
// No such skill.
m := discord.MessageCreate{
Content: "No such skill.",
@@ -110,11 +109,11 @@ func skillHandler(data discord.SlashCommandInteractionData, e *handler.CommandEv
}
return e.CreateMessage(m)
}
s = global.AllSkills[id]
id = int64(v)
}
// TODO(zeph): search conditions and effects, give a list
m := discord.MessageCreate{
Components: []discord.LayoutComponent{RenderSkill(s)},
Components: []discord.LayoutComponent{RenderSkill(horse.SkillID(id), global.AllSkills, global.SkillGroups)},
Flags: discord.MessageFlagIsComponentsV2,
}
return e.CreateMessage(m)
@@ -133,3 +132,18 @@ func skillAutocomplete(e *handler.AutocompleteEvent) error {
}
return e.AutocompleteResult(r)
}
func skillButton(data discord.ButtonInteractionData, e *handler.ComponentEvent) error {
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.MessageUpdate{
Components: &[]discord.LayoutComponent{RenderSkill(horse.SkillID(id), global.AllSkills, global.SkillGroups)},
}
return e.UpdateMessage(m)
}