mirror of https://github.com/velour/catbase.git
twitter: fix persistence
This commit is contained in:
parent
c42ae647f3
commit
0112b23aa5
|
@ -10,8 +10,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
sqlite3 "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/mattn/go-sqlite3"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,6 +37,19 @@ func (c *Config) GetFloat64(key string, fallback float64) float64 {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInt64 returns the config value for a string key
|
||||||
|
// It will first look in the env vars for the key
|
||||||
|
// It will check the DB for the key if an env DNE
|
||||||
|
// Finally, it will return a zero value if the key does not exist
|
||||||
|
// It will attempt to convert the value to an int if it exists
|
||||||
|
func (c *Config) GetInt64(key string, fallback int64) int64 {
|
||||||
|
i, err := strconv.ParseInt(c.GetString(key, strconv.FormatInt(fallback, 10)), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
// GetInt returns the config value for a string key
|
// GetInt returns the config value for a string key
|
||||||
// It will first look in the env vars for the key
|
// It will first look in the env vars for the key
|
||||||
// It will check the DB for the key if an env DNE
|
// It will check the DB for the key if an env DNE
|
||||||
|
|
5
main.go
5
main.go
|
@ -9,6 +9,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/velour/catbase/plugins/twitter"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
@ -44,7 +46,6 @@ import (
|
||||||
"github.com/velour/catbase/plugins/tell"
|
"github.com/velour/catbase/plugins/tell"
|
||||||
"github.com/velour/catbase/plugins/tldr"
|
"github.com/velour/catbase/plugins/tldr"
|
||||||
"github.com/velour/catbase/plugins/twitch"
|
"github.com/velour/catbase/plugins/twitch"
|
||||||
// "github.com/velour/catbase/plugins/twitter"
|
|
||||||
"github.com/velour/catbase/plugins/your"
|
"github.com/velour/catbase/plugins/your"
|
||||||
"github.com/velour/catbase/plugins/zork"
|
"github.com/velour/catbase/plugins/zork"
|
||||||
)
|
)
|
||||||
|
@ -129,7 +130,7 @@ func main() {
|
||||||
b.AddPlugin(tldr.New(b))
|
b.AddPlugin(tldr.New(b))
|
||||||
b.AddPlugin(stock.New(b))
|
b.AddPlugin(stock.New(b))
|
||||||
b.AddPlugin(newsbid.New(b))
|
b.AddPlugin(newsbid.New(b))
|
||||||
// b.AddPlugin(twitter.New(b))
|
b.AddPlugin(twitter.New(b))
|
||||||
b.AddPlugin(cli.New(b))
|
b.AddPlugin(cli.New(b))
|
||||||
// catches anything left, will always return true
|
// catches anything left, will always return true
|
||||||
b.AddPlugin(fact.New(b))
|
b.AddPlugin(fact.New(b))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package twitter
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -78,7 +79,7 @@ func (t *Twitter) check(c bot.Connector) {
|
||||||
log.Debug().Str("ch", ch).Msg("Sending tweet")
|
log.Debug().Str("ch", ch).Msg("Sending tweet")
|
||||||
t.b.Send(c, bot.Message, ch, link)
|
t.b.Send(c, bot.Message, ch, link)
|
||||||
}
|
}
|
||||||
t.c.Set(userKey, string(tweet.Id))
|
t.c.Set(userKey, strconv.FormatInt(tweet.Id, 10))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue