From 27c782b7bc71fdce04117ba3674959553b9f53e2 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Wed, 29 Dec 2021 08:25:42 -0500 Subject: [PATCH] IDK, experiment is over anyway --- bot/handlers.go | 2 -- plugins/beers/beers.go | 1 - plugins/counter/counter.go | 30 +++++++++++++++--------------- plugins/fact/factoid.go | 20 ++++++++++---------- util/migrate/counter.go | 2 +- util/migrate/fact.go | 2 +- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/bot/handlers.go b/bot/handlers.go index c152384..4797862 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -67,9 +67,7 @@ func ParseValues(r *regexp.Regexp, body string) RegexValues { func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.Message, args ...interface{}) bool { t := reflect.TypeOf(plugin).String() for _, spec := range b.callbacks[t][evt] { - log.Debug().Msgf("Trying callback %v with regex %v for msg %v", t, spec.Regex.String(), message.Body) if spec.Regex.MatchString(message.Body) { - log.Debug().Msgf("Running callback") req := Request{ Conn: conn, Kind: evt, diff --git a/plugins/beers/beers.go b/plugins/beers/beers.go index 1487c2d..027ee5b 100644 --- a/plugins/beers/beers.go +++ b/plugins/beers/beers.go @@ -217,7 +217,6 @@ func (p *BeersPlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, } func getUserBeers(store *bh.Store, user, id, itemName string) *counter.Item { - // TODO: really ought to have an ID here booze, _ := counter.GetUserItem(store, user, id, itemName) return booze } diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index 8c760be..f447588 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -36,7 +36,7 @@ type Item struct { UserID string } -type Alias struct { +type CounterAlias struct { store *bh.Store created bool @@ -60,17 +60,17 @@ func GetAllItems(store *bh.Store) ([]Item, error) { } // GetItems returns all counters for a subject -func GetItems(store *bh.Store, nick, id string) ([]Item, error) { - var items []Item +func GetItems(store *bh.Store, nick, id string) ([]*Item, error) { + var items []*Item var err error - q := &bh.Query{} if id != "" { - q = bh.Where("UserID").Eq(id) + if err = store.Find(&items, bh.Where("UserID").Eq(id)); err != nil { + return nil, err + } } else { - q = bh.Where("Nick").Eq(nick) - } - if err = store.Find(&items, q); err != nil { - return nil, err + if err = store.Find(&items, bh.Where("Nick").Eq(nick)); err != nil { + return nil, err + } } // Don't forget to embed the db into all of that shiz for i := range items { @@ -110,17 +110,17 @@ func Leader(store *bh.Store, itemName string) ([]Item, error) { } func RmAlias(store *bh.Store, aliasName string) error { - a := &Alias{} + a := &CounterAlias{} if err := store.FindOne(a, bh.Where("Item").Eq(aliasName)); err != nil { return err } - return store.Delete(a.ID, Alias{}) + return store.Delete(a.ID, CounterAlias{}) } -func MkAlias(store *bh.Store, aliasName, pointsTo string) (*Alias, error) { +func MkAlias(store *bh.Store, aliasName, pointsTo string) (*CounterAlias, error) { aliasName = strings.ToLower(aliasName) pointsTo = strings.ToLower(pointsTo) - alias := &Alias{ + alias := &CounterAlias{ store: store, Item: aliasName, PointsTo: pointsTo, @@ -134,7 +134,7 @@ func MkAlias(store *bh.Store, aliasName, pointsTo string) (*Alias, error) { func GetItem(store *bh.Store, itemName string) ([]Item, error) { itemName = trimUnicode(itemName) var items []Item - var a Alias + var a CounterAlias if err := store.FindOne(&a, bh.Where("Item").Eq(itemName)); err == nil { itemName = a.PointsTo } else { @@ -162,7 +162,7 @@ func GetUserItem(store *bh.Store, nick, id, itemName string) (*Item, error) { item.Nick = nick item.Item = itemName item.UserID = id - var a Alias + var a CounterAlias err := store.FindOne(&a, bh.Where("Item").Eq(itemName)) if err == nil { log.Debug().Msgf("itemName now is %s", a.PointsTo) diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go index ca40953..5fe40e0 100644 --- a/plugins/fact/factoid.go +++ b/plugins/fact/factoid.go @@ -36,20 +36,20 @@ type Factoid struct { Count int } -type Alias struct { +type FactAlias struct { Fact string Next string } -func (a Alias) Key() string { +func (a FactAlias) Key() string { return a.Fact + a.Next } -func (a *Alias) resolve(store *bh.Store) (*Factoid, error) { - // perform db query to fill the To field +func (a *FactAlias) resolve(store *bh.Store) (*Factoid, error) { + // perform db query to fill the To field. // todo: remove this query //q := `select fact, next from factoid_alias where fact=?` - var next Alias + var next FactAlias err := store.FindOne(&next, bh.Where("Fact").Eq(a.Next)) if err != nil { // we hit the end of the chain, get a factoid named Next @@ -66,7 +66,7 @@ func (a *Alias) resolve(store *bh.Store) (*Factoid, error) { func findAlias(store *bh.Store, fact string) (bool, *Factoid) { // todo: remove this query //q := `select * from factoid_alias where fact=?` - var a Alias + var a FactAlias err := store.FindOne(&a, bh.Where("Fact").Eq(fact)) if err != nil { return false, nil @@ -75,9 +75,9 @@ func findAlias(store *bh.Store, fact string) (bool, *Factoid) { return err == nil, f } -func (a *Alias) save(store *bh.Store) error { +func (a *FactAlias) save(store *bh.Store) error { //q := `select * from factoid_alias where fact=?` - var offender Alias + var offender FactAlias err := store.FindOne(&offender, bh.Where("Fact").Eq(a.Next)) if err == nil { return fmt.Errorf("DANGER: an opposite alias already exists") @@ -95,8 +95,8 @@ func (a *Alias) save(store *bh.Store) error { return nil } -func aliasFromStrings(from, to string) *Alias { - return &Alias{from, to} +func aliasFromStrings(from, to string) *FactAlias { + return &FactAlias{from, to} } func (f *Factoid) Save(store *bh.Store) error { diff --git a/util/migrate/counter.go b/util/migrate/counter.go index 4967378..27287b8 100644 --- a/util/migrate/counter.go +++ b/util/migrate/counter.go @@ -30,7 +30,7 @@ func migrateCounter(db *sqlx.DB, store *bh.Store) error { } } - aliases := []counter2.Alias{} + aliases := []counter2.CounterAlias{} log.Printf("Migrating %T", aliases) if err := db.Select(&aliases, `select * from counter_alias`); err != nil { return err diff --git a/util/migrate/fact.go b/util/migrate/fact.go index 6285fb9..988eeee 100644 --- a/util/migrate/fact.go +++ b/util/migrate/fact.go @@ -36,7 +36,7 @@ func migrateFacts(db *sqlx.DB, store *bh.Store) error { log.Printf("Migrated %d facts", len(allFacts)) q = `select * from factoid_alias` - allAliases := []fact2.Alias{} + allAliases := []fact2.FactAlias{} if err := db.Select(&allAliases, q); err != nil { return err