From 7464a7c84cbc6ad8b1f1c96f6875d982ebc4349b Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 5 Aug 2021 09:35:43 -0400 Subject: [PATCH] quotegame: draft of game --- plugins/quotegame/quotegame.go | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 plugins/quotegame/quotegame.go diff --git a/plugins/quotegame/quotegame.go b/plugins/quotegame/quotegame.go new file mode 100644 index 0000000..4834bd0 --- /dev/null +++ b/plugins/quotegame/quotegame.go @@ -0,0 +1,50 @@ +package quotegame + +import ( + "math/rand" + "time" + + "github.com/jmoiron/sqlx" + "github.com/velour/catbase/bot" + "github.com/velour/catbase/config" +) + +type QuoteGame struct { + b bot.Bot + c *config.Config + db *sqlx.DB + + currentGame *time.Timer +} + +func New(b bot.Bot) *QuoteGame { + return &QuoteGame{ + b: b, + c: b.Config(), + db: b.DB(), + currentGame: nil, + } +} + +func (p *QuoteGame) getAllQuotes() ([]string, error) { + threshold := p.c.GetInt("quotegame.threshold", 10) + q := ` + select tidbit from fact where fact in ( + select fact, verb, tidbit from fact where fact like '%quotes' group by fact having count(fact) > ? + ) + ` + quotes := []string{} + err := p.db.Select("es, q, threshold) + if err != nil { + return nil, err + } + return quotes, nil +} + +func (p *QuoteGame) getRandomquote() (string, error) { + quotes, err := p.getAllQuotes() + if err != nil { + return "", err + } + return quotes[rand.Intn(len(quotes))], nil +} \ No newline at end of file