Random quotes via /random, make test

This commit is contained in:
Pavel 2019-06-09 20:27:15 +03:00
parent f85a5ddd3a
commit 2ea533cad5
4 changed files with 14 additions and 1 deletions

View File

@ -3,4 +3,5 @@ language: go
go:
- "1.12"
script:
- "make"
- "make test"
- "make build"

View File

@ -15,6 +15,10 @@ clean:
@echo Cleaning...
@rm -rf $(dir ${BIN})
test:
@echo Testing...
@$(GO) test $(SRC)
run:
@$(BIN)

View File

@ -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)

View File

@ -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()
}