Skip to content

Commit

Permalink
add object map to autocomplete context [#18]
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Jul 21, 2023
1 parent b621ecf commit 0944511
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,37 @@ type AutocompleteCommand interface {

// AutocompleteContext provides easy acces to the underlying event data.
type AutocompleteContext struct {
ObjectMap

session *discordgo.Session
ken *Ken
event *discordgo.InteractionCreate
}

var _ safepool.ResetState = (*AutocompleteContext)(nil)

func newAutocompleteContext() *AutocompleteContext {
return &AutocompleteContext{
ObjectMap: new(simpleObjectMap),
}
}

func (t *AutocompleteContext) ResetState() {
t.ken = nil
t.session = nil
t.event = nil
t.Purge()
}

// Get either returns an instance from the internal object map -
// if existent. Otherwise, the object is looked up in the specified
// dependency provider, if available. When no object was found in
// either of both maps, nil is returned.
func (c *AutocompleteContext) Get(key string) (v interface{}) {
if v = c.ObjectMap.Get(key); v == nil && c.ken.opt.DependencyProvider != nil {
v = c.ken.opt.DependencyProvider.Get(key)
}
return
}

// Event returns the underlying InteractionCreate event.
Expand Down

0 comments on commit 0944511

Please sign in to comment.