diff --git a/config/config.go b/config/config.go index ee767d2..ab68c06 100644 --- a/config/config.go +++ b/config/config.go @@ -10,8 +10,9 @@ import ( "strconv" "strings" + sqlite3 "github.com/mattn/go-sqlite3" + "github.com/jmoiron/sqlx" - "github.com/mattn/go-sqlite3" "github.com/rs/zerolog/log" ) @@ -36,6 +37,19 @@ func (c *Config) GetFloat64(key string, fallback float64) float64 { 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 // It will first look in the env vars for the key // It will check the DB for the key if an env DNE diff --git a/main.go b/main.go index 83fa84a..eade49e 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,8 @@ import ( "os" "time" + "github.com/velour/catbase/plugins/twitter" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -44,7 +46,6 @@ import ( "github.com/velour/catbase/plugins/tell" "github.com/velour/catbase/plugins/tldr" "github.com/velour/catbase/plugins/twitch" - // "github.com/velour/catbase/plugins/twitter" "github.com/velour/catbase/plugins/your" "github.com/velour/catbase/plugins/zork" ) @@ -129,7 +130,7 @@ func main() { b.AddPlugin(tldr.New(b)) b.AddPlugin(stock.New(b)) b.AddPlugin(newsbid.New(b)) - // b.AddPlugin(twitter.New(b)) + b.AddPlugin(twitter.New(b)) b.AddPlugin(cli.New(b)) // catches anything left, will always return true b.AddPlugin(fact.New(b)) diff --git a/plugins/twitter/twitter.go b/plugins/twitter/twitter.go index 1a958a9..6e229b8 100644 --- a/plugins/twitter/twitter.go +++ b/plugins/twitter/twitter.go @@ -3,6 +3,7 @@ package twitter import ( "fmt" "net/url" + "strconv" "time" "github.com/rs/zerolog/log" @@ -78,7 +79,7 @@ func (t *Twitter) check(c bot.Connector) { log.Debug().Str("ch", ch).Msg("Sending tweet") t.b.Send(c, bot.Message, ch, link) } - t.c.Set(userKey, string(tweet.Id)) + t.c.Set(userKey, strconv.FormatInt(tweet.Id, 10)) } } }