From 2ea533cad53d6aa98e6a651a84699b2166e73b75 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Sun, 9 Jun 2019 20:27:15 +0300 Subject: [PATCH] Random quotes via /random, make test --- .travis.yml | 3 ++- Makefile | 4 ++++ src/bashim.go | 4 ++++ src/bot.go | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e0780e4..d22b70c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,5 @@ language: go go: - "1.12" script: - - "make" \ No newline at end of file + - "make test" + - "make build" \ No newline at end of file diff --git a/Makefile b/Makefile index f0b554d..7180324 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,10 @@ clean: @echo Cleaning... @rm -rf $(dir ${BIN}) +test: + @echo Testing... + @$(GO) test $(SRC) + run: @$(BIN) diff --git a/src/bashim.go b/src/bashim.go index 58cfd3a..61f8dd0 100644 --- a/src/bashim.go +++ b/src/bashim.go @@ -31,6 +31,10 @@ func GetLatestAbyssQuotes() ([]BashQuote, error) { return extractQuotes("/abyss/", 25) } +func GetRandomQuotes() ([]BashQuote, error) { + return extractQuotes("/random", 25) +} + func GetQuote(id int) (BashQuote, error) { quotes, err := extractQuotes(fmt.Sprintf("/quote/%d", id), 1) diff --git a/src/bot.go b/src/bot.go index cb997c6..beb7c76 100644 --- a/src/bot.go +++ b/src/bot.go @@ -115,6 +115,8 @@ func processUpdate(update tgbotapi.Update, bot *tgbotapi.BotAPI) { NewMessageWithQuotes(bot, update, &msgs, "Получаю свежие цитаты", update.Message.Command()) case "abyss": NewMessageWithQuotes(bot, update, &msgs, "Получаю цитаты из Бездны", update.Message.Command()) + case "random": + NewMessageWithQuotes(bot, update, &msgs, "Получаю случайные цитаты", update.Message.Command()) default: msgs[len(msgs)-1].Text = "Как насчёт последних цитат? Используйте /latest" } @@ -151,6 +153,8 @@ func NewMessageWithQuotes( items, err = GetLatestQuotes() case "abyss": items, err = GetLatestAbyssQuotes() + case "random": + items, err = GetRandomQuotes() default: items, err = GetLatestQuotes() }