mirror of https://github.com/velour/catbase.git
IDK, experiment is over anyway
This commit is contained in:
parent
4e16c8f464
commit
27c782b7bc
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue