Compare commits

...

2 Commits

3 changed files with 5 additions and 13 deletions

View File

@@ -20,13 +20,9 @@ type Set[V any] struct {
// The behavior is undefined if the key already has a value.
func (s *Set[V]) Add(key string, val V) {
k := util.ToChars([]byte(key))
i, ok := slices.BinarySearchFunc(s.keys, k, func(a, b util.Chars) int {
i, _ := slices.BinarySearchFunc(s.keys, k, func(a, b util.Chars) int {
return bytes.Compare(a.Bytes(), b.Bytes())
})
if ok {
s.vals[i] = val
return
}
s.keys = slices.Insert(s.keys, i, k)
s.vals = slices.Insert(s.vals, i, val)
}

View File

@@ -163,11 +163,7 @@ func skillHandler(data discord.SlashCommandInteractionData, e *handler.CommandEv
func skillAutocomplete(e *handler.AutocompleteEvent) error {
q := e.Data.String("query")
opts := skillGlobalAuto().Find(nil, q)
r := make([]discord.AutocompleteChoice, min(len(opts), 25))
for i, k := range opts[:min(len(opts), len(r))] {
r[i] = discord.AutocompleteChoiceString{Name: k, Value: k}
}
return e.AutocompleteResult(r)
return e.AutocompleteResult(opts[:min(len(opts), 25)])
}
func skillButton(data discord.ButtonInteractionData, e *handler.ComponentEvent) error {

View File

@@ -118,11 +118,11 @@ func isDebuff(s horse.Skill) bool {
return false
}
var skillGlobalAuto = sync.OnceValue(func() *autocomplete.Set[string] {
var set autocomplete.Set[string]
var skillGlobalAuto = sync.OnceValue(func() *autocomplete.Set[discord.AutocompleteChoice] {
var set autocomplete.Set[discord.AutocompleteChoice]
for _, id := range global.OrderedSkills {
s := global.AllSkills[id]
set.Add(s.Name, s.Name)
set.Add(s.Name, discord.AutocompleteChoiceString{Name: s.Name, Value: s.Name})
}
return &set
})